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

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.FirstCourseRecordDoc;
import com.lantone.qc.pub.model.doc.ward.AttendingDoctorWardDoc;
import com.lantone.qc.pub.model.doc.ward.DirectorDoctorWardDoc;
import com.lantone.qc.pub.model.entity.Diag;
import com.lantone.qc.pub.model.label.DiagLabel;
import com.lantone.qc.pub.model.label.ThreeLevelWardLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName : THR0702
 * @Description : 首次主任医师查房中鉴别诊断跟首程一致
 * @Author : 胡敬
 * @Date: 2020-04-20 16:38
 */
@Component
public class THR0702 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getThreeLevelWardDocs().size() == 0 || inputInfo.getFirstCourseRecordDoc() == null) {
            status.set("0");
        }
        List<DirectorDoctorWardDoc> directorDocs = inputInfo.getThreeLevelWardDocs().get(0).getDirectorDoctorWardDocs();
        FirstCourseRecordDoc firstCourseRecordDoc = inputInfo.getFirstCourseRecordDoc();
        String firstCourseDiffDiag = getDiffDiag(firstCourseRecordDoc);
        if (StringUtil.isBlank(firstCourseDiffDiag)) {
            return;
        }
        if (directorDocs.size() == 0) {
            status.set("0");
            return;
        }
        DirectorDoctorWardDoc firstDirectorDoc = directorDocs.get(0);
        ThreeLevelWardLabel firstAttendLabel = firstDirectorDoc.getThreeLevelWardLabel();
        if (firstAttendLabel == null) {
            status.set("0");
            return;
        }
        if (firstAttendLabel.getDiffDiag().size() != 0) {
            for (Diag diffDiag : firstAttendLabel.getDiffDiag()) {
                String diffDiagName = diffDiag.getHospitalDiagName();
                if (StringUtil.isBlank(diffDiagName)) {
                    continue;
                }
                if (firstCourseDiffDiag.equals(diffDiagName)) {
                    status.set("0");
                    return;
                }
            }

        }
        if (StringUtil.isNotBlank(firstAttendLabel.getDiffDiagText())) {
            if (firstAttendLabel.getDiffDiagText().equals(firstCourseDiffDiag)) {
                status.set("0");
            }
        }
    }

    /**
     * 获取首程鉴别诊断
     *
     * @param firstCourseRecordDoc
     * @return
     */
    private String getDiffDiag(FirstCourseRecordDoc firstCourseRecordDoc) {
        String diffDiag = "";
        DiagLabel differentialDiagLabel = firstCourseRecordDoc.getDifferentialDiagLabel();
        if (StringUtil.isNotBlank(firstCourseRecordDoc.getStructureMap().get("鉴别诊断"))) {
            diffDiag = firstCourseRecordDoc.getStructureMap().get("鉴别诊断");
        } else if (differentialDiagLabel != null && StringUtil.isNotBlank(differentialDiagLabel.getText())) {
            diffDiag = differentialDiagLabel.getText();
        }
        return diffDiag;
    }
}