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.consultation.ConsultationApplicationDoc;
import com.lantone.qc.pub.model.doc.consultation.ConsultationDoc;
import com.lantone.qc.pub.model.doc.consultation.ConsultationResultsDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : CON0526
 * @Description : 急诊室急会诊未在10分钟内完成
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class CON0526 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) throws ParseException {
        status.set("0");
        List<ConsultationDoc> consultationDocs = inputInfo.getConsultationDocs();
        if (consultationDocs.size() > 0) {
            for (ConsultationDoc consulation : consultationDocs) {
                ConsultationApplicationDoc consultationApplicationDoc = consulation.getConsultationApplicationDoc();
                ConsultationResultsDoc consultationResultsDoc = consulation.getConsultationResultsDoc();
                Map<String, String> applicationMap = consultationApplicationDoc.getStructureMap();
                Map<String, String> resultMap = consultationResultsDoc.getStructureMap();
                if (applicationMap != null && resultMap != null) {
                    String applicationDate = applicationMap.get("申请日期");
                    String resultDate = resultMap.get("会诊到达时间");
                    if (applicationDate != null && resultDate != null) {
                        Date date_in = StringUtil.parseDateTime(applicationDate);
                        Date date_out = StringUtil.parseDateTime(resultDate);
                        if (date_in == null || date_out == null) {
                            return;
                        }
                        long times = date_out.getTime() - date_in.getTime();
                        long day = times / (24 * 60 * 60 * 1000);
                        long hour = (times / (60 * 60 * 1000) - day * 24);
                        long min = ((times / (60 * 1000)) - day * 24 * 60 - hour * 60);
                        long min1 = ((times / (60 * 1000)) - day * 24 * 60 - hour * 60);
                        if (min1 > 10) {
                            status.set("-1");
                        }

                    }
                }
            }
        }

    }
}