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

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.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @ClassName : DEAR0338
 * @Description : 死亡记录无副主任医师审核签名
 * @Author : 胡敬
 * @Date: 2020-03-06 17:28
 */
@Component
public class DEAR03034 extends QCCatalogue {
    @Autowired
    private SpecialStorageUtil specialStorageUtil;

    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getDeathRecordDoc() == null) {
            status.set("0");
            return;
        }
        Map<String, String> deathRecordStructure = inputInfo.getDeathRecordDoc().getStructureMap();
        String recordDoctor = deathRecordStructure.get("审核人");
        if (StringUtil.isNotBlank(recordDoctor)) {
            if (findDirectorDoctor(recordDoctor)) {
                status.set("0");
            }
        }
    }

    private boolean findDirectorDoctor(String recordDoctor) {
        Map<String, Map<String, Object>> hospitalDoctorMap = specialStorageUtil.getJsonStringValue(KernelConstants.HOSPITAL_DOCTOR_MAP);
        if (hospitalDoctorMap == null) {
            return false;
        }
        if (hospitalDoctorMap.containsKey(recordDoctor)) {
            Object professor = hospitalDoctorMap.get(recordDoctor).get("professor");
            if (professor != null) {
                return professor.toString().contains("主任");
            }
        }
        return false;
    }
}