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

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.DoctorAdviceDoc;
import com.lantone.qc.pub.model.doc.consultation.ConsultationDoc;
import com.lantone.qc.pub.model.doc.consultation.ConsultationRecordDoc;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : CON0528
 * @Description : 无会诊记录单
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class CON0528 extends QCCatalogue {

    public void start(InputInfo inputInfo, OutputInfo outputInfo) throws ParseException {
        status.set("0");
        List<ConsultationDoc> consultationDocs = inputInfo.getConsultationDocs();
        List<DoctorAdviceDoc> doctorAdviceDocs = inputInfo.getDoctorAdviceDocs();
        if (doctorAdviceDocs.size() == 0) {
            return;
        }
        boolean findConsultation = false, findConsultationRemove = false;
        for (DoctorAdviceDoc doctorAdviceDoc : doctorAdviceDocs) {
            Map<String, String> doctStructureMap = doctorAdviceDoc.getStructureMap();
            if (doctStructureMap.get("医嘱项目名称") != null) {
                if (doctStructureMap.get("医嘱项目名称").contains("会诊")) {
                    findConsultation = true;
                }
                if (doctStructureMap.get("医嘱项目名称").contains("会诊")
                        && doctStructureMap.get("医嘱项目名称").contains("取消")) {
                    findConsultationRemove = true;
                }
            }
        }
        //医嘱有会诊但没有取消会诊
        if (findConsultation && !findConsultationRemove) {
            if (consultationDocs.size() > 0) {
                for (ConsultationDoc consulation : consultationDocs) {
                    ConsultationRecordDoc consultationRecordDoc = consulation.getConsultationRecordDoc();
                    if (consultationRecordDoc == null) {
                        status.set("-1");
                        return;
                    }
                }
            }
        } else {
            status.set("0");
        }
    }
}