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

import com.lantone.qc.dbanaly.util.KernelConstants;
import com.lantone.qc.dbanaly.util.SpecialStorageUtil;
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.LeaveHospitalDoc;
import com.lantone.qc.pub.util.SpringContextUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

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

/**
 * @author kwz
 * 出院记录无执业医师签名
 * @date 2020/4/7
 * @time 21:42
 */
@Component
public class LEA0508 extends QCCatalogue {
    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) throws ParseException {
        LeaveHospitalDoc leaveHospitalDoc = inputInfo.getLeaveHospitalDoc();
        if (leaveHospitalDoc == null) {
            status.set("0");
            return;
        }
        Map<String, String> structureMap = leaveHospitalDoc.getStructureMap();
        String doctorName = structureMap.get("医师签名");
        if (StringUtils.isEmpty(doctorName)) {
            status.set("0");
            return;
        }

        SpecialStorageUtil specialStorageUtil = SpringContextUtil.getBean("specialStorageUtil");
        Map<String, Object> surgeon = specialStorageUtil.getJsonStringValue(KernelConstants.HOSPITAL_DOCTOR_MAP);
        if (surgeon == null || surgeon.size() == 0) {
            status.set("0");
            return;
        }
        for (String doctorNameSplit : doctorName.split("\\s+")) {
            Map<String, String> doctor = (Map) surgeon.get(doctorNameSplit);
            if (doctor == null || doctor.size() == 0) {
                continue;
            }
            String occup = doctor.get("occup");
            if (StringUtils.isNotEmpty(occup) && "1".equals(occup)) {
                status.set("0");
                return;
            }
        }
    }
}
