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 : THR0601
 * @Description : 整份病历无主治医师查房记录
 * @Author : 胡敬
 * @Date: 2020-03-25 10:21
 */
@Component
public class THR0601 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getLeaveHospitalDoc() == null || inputInfo.getThreeLevelWardDocs().size() == 0) {
            return;
        }
        Map<String, String> leaveHospitalStructureMap = inputInfo.getLeaveHospitalDoc().getStructureMap();
        String lengthOfStay = leaveHospitalStructureMap.get("住院天数");
        if (StringUtil.isNotBlank(lengthOfStay) && CatalogueUtil.numbersOnly(lengthOfStay)) {
            //如果住院天数小于2天则不判断该条规则
            if (Integer.parseInt(lengthOfStay) <= 2) {
                return;
            }
        }

        List<ThreeLevelWardDoc> allDoctorWradDocs = inputInfo.getThreeLevelWardDocs().get(0).getAllDoctorWradDocs();//查房记录
        String title, record;
        boolean findIndications = false;
        for (ThreeLevelWardDoc threeLevelWardDoc : allDoctorWradDocs) {
            Map<String, String> rescueStructureMap = threeLevelWardDoc.getStructureMap();
            title = CatalogueUtil.subTitle(rescueStructureMap.get("查房标题"));
            record = CatalogueUtil.subTitle(rescueStructureMap.get("病情记录"));
            if (StringUtil.isNotBlank(title) && title.contains(Content.attend)) {
                findIndications = true;
                break;
            }
            if (StringUtil.isNotBlank(title) && StringUtil.isNotBlank(record)
                    && title.contains("共同照护讨论记录") && record.contains(Content.attend)) {
                findIndications = true;
                break;
            }

        }
        if (!findIndications) {
            status.set("-1");
        }
    }
}