package org.diagbot.graphWeb.work;

import org.diagbot.common.work.SearchData;
import org.diagbot.graph.javabean.GdbResponse;
import org.diagbot.graph.jdbc.DriverManager;
import org.diagbot.graph.jdbc.Neo4jAPI;
import org.diagbot.pub.api.Response;
import org.neo4j.driver.v1.Driver;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class HighRiskCalculate {
   private Driver driver=null;
   private Neo4jAPI n4api=null;
    public Response<GdbResponse> calculateHighRisk(HttpServletRequest request, SearchData searchData) throws Exception {
        GdbResponse responseData = new GdbResponse();
        Response<GdbResponse> objectResponse = new Response<>();
        Map<String,String> RSet = null;
        if (driver == null) {
            driver = DriverManager.newDrive();
        }
        if (driver != null && driver.session() != null) {
            n4api = new Neo4jAPI(driver);
            if(searchData.getDiag().trim()!=null){
                String diag = searchData.getDiag();
                RSet = n4api.getHighRisk(diag);
            }
           responseData.setResult(RSet);
        }
        objectResponse.setData(responseData);
        return objectResponse;
    }
}
