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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
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.entity.Diag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName : FIRP0173
 * @Description :门（急）诊诊断与现病史里的内容不一致
 * @Author : 胡敬
 * @Date: 2020-03-18 16:30
 */
@Component
public class FIRP0173 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getFirstPageRecordDoc() == null){
            status.set("0");
            return;
        }
        if (inputInfo.getFirstPageRecordDoc().getStructureMap() != null
                && inputInfo.getBeHospitalizedDoc() != null
                && inputInfo.getBeHospitalizedDoc().getPresentLabel() != null) {
            Map<String, Object> firstpageStructureMap = inputInfo.getFirstPageRecordDoc().getStructureExtMap();
            //病案首页门急诊诊断
            String outpatientEmergencyDiag = (String) firstpageStructureMap.get(Content.outpatientEmergencyDiag);
            if (StringUtils.isEmpty(outpatientEmergencyDiag)) {
                status.set("0");
            }
            //现病史所有诊断
            List<Diag> presentDiags = inputInfo.getBeHospitalizedDoc().getPresentLabel().getDiags();
            for (Diag diag : presentDiags) {
                if(diag.getHospitalDiagName().equals(outpatientEmergencyDiag)){
                    status.set("0");
                    return;
                }
            }
            List<Diag> presentPossibleDiag = presentDiags.stream().filter(diag -> diag.getPossible() != null).collect(Collectors.toList());
            if (presentPossibleDiag.size() > 0) {
                if (presentPossibleDiag.get(0).getHospitalDiagName().equals(outpatientEmergencyDiag)) {
                    status.set("0");
                }
            }
        }
    }
}