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

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.ThreeLevelWardDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ClassName : THR0144
 * @Description : 患者出院前无主治医师/副主任医师/主任医师/科主任同意出院的病程记录
 * @Author : 胡敬
 * @Date: 2020-03-19 17:20
 */
@Component
public class THR0144 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getThreeLevelWardDocs().size() == 0) {
            status.set("0");
            return;
        }
        List<ThreeLevelWardDoc> allDoctorWradDocs = inputInfo.getThreeLevelWardDocs().get(0).getAllDoctorWradDocs();
        if (allDoctorWradDocs.size() == 0) {
            status.set("0");
            return;
        }
        ThreeLevelWardDoc lastWardDoc = allDoctorWradDocs.get(allDoctorWradDocs.size() - 1);
        Map<String, String> structureMap = lastWardDoc.getStructureMap();
        String conditionRecord = structureMap.get("病情记录");
        String treatmentPlan = structureMap.get("治疗计划和措施");
        String title = structureMap.get("查房标题");
        conditionRecord = StringUtil.isBlank(conditionRecord)?"":conditionRecord;
        treatmentPlan = StringUtil.isBlank(treatmentPlan)?"":treatmentPlan;
        if ((conditionRecord.contains("出院") || treatmentPlan.contains("出院"))
                && StringUtil.isNotBlank(title)
                && (CatalogueUtil.subTitle(title).contains(Content.attend) || CatalogueUtil.subTitle(title).contains(Content.director))) {
            status.set("0");
        }
    }
}