package com.lantone.qc.kernel.catalogue.firstpagerecord;

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.CatalogueUtil;
import com.lantone.qc.pub.Content;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.doc.BeHospitalizedDoc;
import com.lantone.qc.pub.model.entity.AllergyMedicine;
import com.lantone.qc.pub.model.label.PastLabel;
import com.lantone.qc.pub.util.ListUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : FIRP0185
 * @Description :药物过敏与既往史不一致
 * @Author : 胡敬
 * @Date: 2020-03-18 14:07
 */
@Component
public class FIRP0185 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getFirstPageRecordDoc() != null && inputInfo.getBeHospitalizedDoc() != null) {
            Map<String, String> firstpageStructureMap = inputInfo.getFirstPageRecordDoc().getStructureMap();
            String drugAllergy = firstpageStructureMap.get(Content.drugAllergy);
            BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
            if (beHospitalizedDoc.getPastLabel() == null) {
                return;
            }
            PastLabel pastLabel = beHospitalizedDoc.getPastLabel();
            List<AllergyMedicine> allergyMedicines = pastLabel.getAllergyMedicines();
            if (allergyMedicines.size() == 0 || CatalogueUtil.isEmpty(drugAllergy)) {
                return;
            }
            String[] drugAllergyArr = drugAllergy.split(",|，|、| ");
            List<String> drugAllergyPastList = new ArrayList<String>(drugAllergyArr.length);
            Collections.addAll(drugAllergyPastList, drugAllergyArr);
            List<String> drugAllergyFirstPageList = new ArrayList<>();
            for (AllergyMedicine allergyMedicine : allergyMedicines) {
                if (allergyMedicine.getNegative() == null) {
                    drugAllergyFirstPageList.add(allergyMedicine.getName());
                }
            }
            if (!ListUtil.equals(drugAllergyPastList, drugAllergyFirstPageList)) {
                status.set("-1");
            }
        }
    }
}