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.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 : THR03017
 * @Description : 主治查房记录无审核
 * @Author : 胡敬
 * @Date: 2020-03-25 10:21
 */
@Component
public class THR03017 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;
            }
        }

        boolean findIndications = true;
        ThreeLevelWardDoc threeLevelWardDoc = inputInfo.getThreeLevelWardDocs().get(0);
        List<AttendingDoctorWardDoc> attendingDoctorWardDocs = threeLevelWardDoc.getAttendingDoctorWardDocs();
        String jlDateStr, shDateStr, professor;
        for (AttendingDoctorWardDoc attendingDoctorWardDoc : attendingDoctorWardDocs) {
            jlDateStr = attendingDoctorWardDoc.getStructureMap().get("记录时间");
            shDateStr = attendingDoctorWardDoc.getStructureMap().get("审核日期");
            if (!CatalogueUtil.isOccup(attendingDoctorWardDoc.getStructureMap().get("审核人"))
                    || CatalogueUtil.compareTime(StringUtil.parseDateTime(jlDateStr), StringUtil.parseDateTime(shDateStr), 48 * 60L)) {
                findIndications = false;
                break;
            }
        }
        if (!findIndications) {
            status.set("-1");
        }
    }

}