package org.diagbot.graphWeb.work;

import org.diagbot.common.push.bean.FeatureRate;
import org.diagbot.common.push.bean.ResponseData;
import org.diagbot.common.push.bean.SearchData;
import org.diagbot.pub.api.Response;
import org.diagbot.pub.utils.PropertiesUtil;
import org.diagbot.pub.utils.http.HttpApi;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class LisPacsCalculate {
    public ResponseData getLisPacs(HttpServletRequest request, SearchData searchData) throws Exception {

        ResponseData responseData = new ResponseData();
        PropertiesUtil propertiesUtil = new PropertiesUtil("url.properties");
        //调用图谱API
        HttpApi<Response> api = new HttpApi<>();
        Response lisPacsResponse = api.doPost(propertiesUtil.getProperty("lisPacs.http.url"), searchData,
                Response.class);

        Map data = (Map<String, Map>)lisPacsResponse.getData();
        responseData.setLabs((List)data.get("labs"));
        responseData.setPacs((List)data.get("pacs"));
        List<FeatureRate> vitalFeature = new ArrayList<>();
        List<LinkedHashMap> vitals =(List) data.get("vitals");
        if(vitals != null){
            for (LinkedHashMap v:vitals) {
                String featureName = v.get("featureName").toString();
                FeatureRate featureRate = new FeatureRate();
                featureRate.setFeatureName(featureName);
                vitalFeature.add(featureRate);
            }
        }
        responseData.setVitals(vitalFeature);
        return responseData;
    }
}
