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

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

/**
 * @ClassName : THR0126
 * @Description : 主治医师首次查房未在48小时内完成
 * @Author : 胡敬
 * @Date: 2020-03-19 15:50
 */
@Component
public class THR0126 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getThreeLevelWardDocs().size() == 0) {
            return;
        }
        if (inputInfo.getLeaveHospitalDoc() != null && inputInfo.getLeaveHospitalDoc().getStructureMap() != null
                && inputInfo.getThreeLevelWardDocs().size() > 0) {
            Map<String, String> getLeaveHospitalStructureMap = inputInfo.getLeaveHospitalDoc().getStructureMap();
            String admisTime = getLeaveHospitalStructureMap.get(Content.admisTime);
            String dischargeTime = getLeaveHospitalStructureMap.get(Content.dischargeTime);
            if (CatalogueUtil.isEmpty(admisTime) || CatalogueUtil.isEmpty(dischargeTime)) {
                status.set("0");
                return;
            }
            //如果住院天数小于2天则不判断该条规则
            if (!CatalogueUtil.compareTime(StringUtil.parseDateTime(admisTime), StringUtil.parseDateTime(dischargeTime), (long) (48 * 60))) {
                status.set("0");
                return;
            }
            ThreeLevelWardDoc threeLevelWardDoc = inputInfo.getThreeLevelWardDocs().get(0);
            List<AttendingDoctorWardDoc> attendingDoctorWardDocs = threeLevelWardDoc.getAttendingDoctorWardDocs();
            if (attendingDoctorWardDocs.size() == 0) {
                status.set("0");
                return;
            }
            AttendingDoctorWardDoc firstAttending = attendingDoctorWardDocs.get(0);
            String wardDateStr = firstAttending.getStructureMap().get("查房日期");
            if (!CatalogueUtil.compareTime(StringUtil.parseDateTime(admisTime), StringUtil.parseDateTime(wardDateStr), (long) (48 * 60))) {
                status.set("0");
            }
        }
    }
}