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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.doc.DeathRecordDoc;
import com.lantone.qc.pub.model.doc.LeaveHospitalDoc;
import com.lantone.qc.pub.model.entity.Diag;
import com.lantone.qc.pub.model.label.DiagLabel;
import com.lantone.qc.pub.util.ListUtil;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: 出院记录入院诊断与首程的初步诊断不一致
 * @author: 胡敬
 * @time: 2020/3/27 15:15
 */
@Component
public class LEA0509 extends QCCatalogue {
    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        LeaveHospitalDoc leaveHospitalDoc = inputInfo.getLeaveHospitalDoc();
        if (leaveHospitalDoc == null) {
            return;
        }
        DeathRecordDoc deathRecordDoc = inputInfo.getDeathRecordDoc();
        if(deathRecordDoc == null || deathRecordDoc.getText() == null) {
            if (inputInfo.getFirstCourseRecordDoc() != null) {
                DiagLabel beHospitalizedLabel = leaveHospitalDoc.getBeHospitalizedLabel();
                DiagLabel initialDiagLabel = inputInfo.getFirstCourseRecordDoc().getInitialDiagLabel();
                if (beHospitalizedLabel != null && initialDiagLabel != null) {
                    //出院记录入院诊断
                    List<Diag> beHospitalizedDiags = beHospitalizedLabel.getDiags();
                    //首程初步诊断
                    List<Diag> initialDiags = initialDiagLabel.getDiags();
                    if (!ListUtil.equals(beHospitalizedDiags, initialDiags)) {
                        status.set("-1");
                    }
                }
            }
        }
    }
}