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

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

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author rgb
 * 出院小结无F以上医师签名
 * @date 2020/4/7
 * @time 21:42
 */
@Component
public class LEA03029 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("医师签名");
        String shPerson = structureMap.get("审核人");
        String regex = "\\s+";
        List<String> docNames = new ArrayList<>();
        if (StringUtil.isNotBlank(doctorName)) {
            docNames.addAll(Arrays.asList(doctorName.split(regex)));
        }
        if (StringUtil.isNotBlank(shPerson)) {
            docNames.addAll(Arrays.asList(shPerson.split(regex)));
        }
        String professor = null;
        for (String docName : docNames) {
            professor = CatalogueUtil.getProfessor(docName);
            if (StringUtil.isNotBlank(professor) && professor.contains("主任")) {
                status.set("0");
                break;
            }
        }
    }

}