|  | @ -3,8 +3,11 @@ package com.yihu.wlyy.service.third.jw;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.doctor.profile.Doctor;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.prescription.Prescription;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.prescription.PrescriptionDiagnosis;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.prescription.PrescriptionDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.system.Icd10DictServcie;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.HttpClientUtil;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.apache.http.NameValuePair;
 | 
	
	
		
			
				|  | @ -17,9 +20,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.HashMap;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * 基位长处方接口
 | 
	
	
		
			
				|  | @ -40,6 +41,10 @@ public class JwPrescriptionService {
 | 
	
		
			
				|  |  |     private PrescriptionDao prescriptionDao;
 | 
	
		
			
				|  |  |     @Value("${spring.profiles}")
 | 
	
		
			
				|  |  |     private String profiles;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private Icd10DictServcie icd10DictServcie;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ZyDictService zyDictService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取字典列表
 | 
	
	
		
			
				|  | @ -75,7 +80,7 @@ public class JwPrescriptionService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取历史处方记录列表
 | 
	
		
			
				|  |  |      * 获取历史处方记录
 | 
	
		
			
				|  |  |      * @param cardNo 社保卡号
 | 
	
		
			
				|  |  |      * @param recipeNo 医嘱号
 | 
	
		
			
				|  |  |      * @param applyTimeFrom 开始时间
 | 
	
	
		
			
				|  | @ -91,75 +96,123 @@ public class JwPrescriptionService {
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("applyTimeFrom", applyTimeFrom));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("applyTimeEnd", applyTimeEnd));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String response = "";
 | 
	
		
			
				|  |  |         if("prod".equals(profiles)){
 | 
	
		
			
				|  |  |             response = httpClientUtil.post(url, params, "UTF-8");
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             String sql = "SELECT h.response from wlyy_http_log h WHERE h.id = 806287";
 | 
	
		
			
				|  |  |             List<Map<String ,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |             response = list.get(0).get("response").toString();
 | 
	
		
			
				|  |  |             JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |             jsonObject.put("status",200);
 | 
	
		
			
				|  |  |             jsonObject.put("data",response);
 | 
	
		
			
				|  |  |             response = jsonObject.toString();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String response = httpClientUtil.post(url, params, "UTF-8");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取处方列表
 | 
	
		
			
				|  |  |      * @param cardNo
 | 
	
		
			
				|  |  |      * @param recipeNo
 | 
	
		
			
				|  |  |      * @param patientCode
 | 
	
		
			
				|  |  |      * @param applyTimeFrom
 | 
	
		
			
				|  |  |      * @param applyTimeEnd
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getRecipeList(String cardNo,String recipeNo,String applyTimeFrom,String applyTimeEnd){
 | 
	
		
			
				|  |  |         JSONObject recipeJson = new JSONObject();
 | 
	
		
			
				|  |  |         try{
 | 
	
		
			
				|  |  |             Map<String,String> map = new HashMap<>();
 | 
	
		
			
				|  |  |             JSONArray jsonArray = new JSONArray();
 | 
	
		
			
				|  |  |             for (int i=0;i<3;i++){
 | 
	
		
			
				|  |  |                 if(!map.containsKey(recipeNo)){
 | 
	
		
			
				|  |  |                     map.put(recipeNo,recipeNo);
 | 
	
		
			
				|  |  |                     String response = getLastRecipe(cardNo,recipeNo,applyTimeFrom,applyTimeEnd);
 | 
	
		
			
				|  |  |                     JSONObject json = JSONObject.parseObject(response);
 | 
	
		
			
				|  |  |                     if(json.getInteger("status")==200){
 | 
	
		
			
				|  |  |                         //智业接口每次返回一条数据,需要遍历请求
 | 
	
		
			
				|  |  |                         JSONObject data = json.getJSONObject("data");
 | 
	
		
			
				|  |  |                         String code = data.getString("CODE");
 | 
	
		
			
				|  |  |                         if("1".equals(code)){
 | 
	
		
			
				|  |  |                             JSONArray returnData = data.getJSONArray("returnData");
 | 
	
		
			
				|  |  |                             if(returnData.size()>0){
 | 
	
		
			
				|  |  |                                 JSONObject recipe = returnData.getJSONArray(0).getJSONObject(0);//获取最后一条处方
 | 
	
		
			
				|  |  |                                 jsonArray.add(recipe);
 | 
	
		
			
				|  |  |                                 recipeNo = recipe.getString("RECIPE_NO");
 | 
	
		
			
				|  |  |                                 if(recipeJson.isEmpty()){
 | 
	
		
			
				|  |  |                                     recipeJson = json;
 | 
	
		
			
				|  |  |                                 }else {
 | 
	
		
			
				|  |  |                                     recipeJson.getJSONObject("data").getJSONArray("returnData").getJSONArray(0).add(recipe);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |     public JSONObject getRecipeMasterList(String patientCode,String applyTimeFrom,String applyTimeEnd) throws Exception{
 | 
	
		
			
				|  |  |         JSONObject re = new JSONObject();
 | 
	
		
			
				|  |  |         String url = jwUrl + "/third/prescription/getRecipeMasterList";
 | 
	
		
			
				|  |  |         List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("patientCode", patientCode));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("applyTimeFrom", applyTimeFrom));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("applyTimeEnd", applyTimeEnd));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONArray jsonArray = new JSONArray();
 | 
	
		
			
				|  |  |         Integer totalCount = 0;
 | 
	
		
			
				|  |  |         String errorMsg = "";
 | 
	
		
			
				|  |  |         String response = httpClientUtil.post(url, params, "UTF-8");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //        String sql = "SELECT h.response from wlyy_zy_push_log h WHERE h.id = 436";
 | 
	
		
			
				|  |  | //        List<Map<String ,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  | //        String response = list.get(0).get("response").toString();
 | 
	
		
			
				|  |  | //        JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  | //        jsonObject.put("status",200);
 | 
	
		
			
				|  |  | //        jsonObject.put("data",response);
 | 
	
		
			
				|  |  | //        response = jsonObject.toString();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject json = JSONObject.parseObject(response);
 | 
	
		
			
				|  |  |         if(json.getInteger("status")==200){
 | 
	
		
			
				|  |  |             //智业接口,需要遍历请求 实现分页
 | 
	
		
			
				|  |  |             JSONObject data = json.getJSONObject("data");
 | 
	
		
			
				|  |  |             String code = data.getString("CODE");
 | 
	
		
			
				|  |  |             if("1".equals(code)){
 | 
	
		
			
				|  |  |                 JSONArray returnData = data.getJSONArray("returnData");
 | 
	
		
			
				|  |  |                 JSONArray byRefParaData = data.getJSONArray("byRefParaData");
 | 
	
		
			
				|  |  |                 totalCount = byRefParaData.getJSONObject(0).getInteger("totalCount");
 | 
	
		
			
				|  |  |                 errorMsg = byRefParaData.getJSONObject(0).getString("errorMsg");
 | 
	
		
			
				|  |  |                 if(returnData.size()>0){
 | 
	
		
			
				|  |  |                     for(int i=0;i<totalCount;i++){
 | 
	
		
			
				|  |  |                         JSONObject recipe = returnData.getJSONArray(0).getJSONObject(i);//获取最后一条处方
 | 
	
		
			
				|  |  |                         JSONObject pre = new JSONObject();
 | 
	
		
			
				|  |  |                         pre.put("code",recipe.getString("RECIPE_NO"));//医嘱号
 | 
	
		
			
				|  |  |                         pre.put("createTime",recipe.getString("APPLY_TIME"));//开单时间
 | 
	
		
			
				|  |  | //                        pre.put("applyOperator",recipe.getString("APPLY_OPERATOR"));//开单医生代码
 | 
	
		
			
				|  |  | //                        pre.put("applyOperatorName",recipe.getString("APPLY_OPERATOR_NAME"));//开单医生姓名
 | 
	
		
			
				|  |  | //                        pre.put("healthOrgCode",recipe.getString("HEALTH_ORG_CODE"));//开单机构编码
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         //开方医生和医院
 | 
	
		
			
				|  |  |                         Doctor doctor =  zyDictService.getDoctByJw(recipe.getString("APPLY_OPERATOR"),recipe.getString("HEALTH_ORG_CODE"));
 | 
	
		
			
				|  |  |                         // "APPLY_OPERATOR_NAME": 开单医生姓名","HEALTH_ORG_CODE": "开单机构编码",
 | 
	
		
			
				|  |  |                         if(doctor!=null){
 | 
	
		
			
				|  |  |                             pre.put("doctor",doctor.getCode());
 | 
	
		
			
				|  |  |                             pre.put("doctorName",doctor.getName());
 | 
	
		
			
				|  |  |                             pre.put("hospitalName",doctor.getHospitalName());
 | 
	
		
			
				|  |  |                             pre.put("hospital",doctor.getHospital());
 | 
	
		
			
				|  |  |                         }else{
 | 
	
		
			
				|  |  |                             pre.put("doctor",recipe.getString("APPLY_OPERATOR"));
 | 
	
		
			
				|  |  |                             pre.put("doctorName",recipe.getString("APPLY_OPERATOR_NAME"));
 | 
	
		
			
				|  |  |                             pre.put("hospitalName",recipe.getString("HEALTH_ORG_CODE"));
 | 
	
		
			
				|  |  |                             pre.put("hospital",recipe.getString("HEALTH_ORG_CODE"));
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //                        pre.put("diagnoseCode",recipe.getString("DIAGNOSE_CODE"));//诊断代码
 | 
	
		
			
				|  |  | //                        pre.put("diagnoseName",recipe.getString("DIAGNOSE_NAME"));//诊断名称
 | 
	
		
			
				|  |  | //                        pre.put("diagnoseSubCode",recipe.getString("DIAGNOSE_SUB_CODE"));//次诊断编码
 | 
	
		
			
				|  |  | //                        pre.put("diagnoseSubName",recipe.getString("DIAGNOSE_SUB_NAME"));//次诊断名称
 | 
	
		
			
				|  |  |                         PrescriptionDiagnosis diagnosis = new PrescriptionDiagnosis();
 | 
	
		
			
				|  |  |                         String diagnoseCode = recipe.getString("DIAGNOSE_CODE");
 | 
	
		
			
				|  |  |                         String diagnoseName = recipe.getString("DIAGNOSE_NAME");
 | 
	
		
			
				|  |  |                         diagnosis.setCode(diagnoseCode);//诊断代码
 | 
	
		
			
				|  |  |                         diagnosis.setName(diagnoseName);//诊断名称
 | 
	
		
			
				|  |  |                         String icd10 = icd10DictServcie.getHealthProblemsByIcd10Code(diagnoseCode);
 | 
	
		
			
				|  |  |                         if(!StringUtils.isEmpty(icd10)){
 | 
	
		
			
				|  |  |                             JSONObject icd = JSONObject.parseObject(icd10);
 | 
	
		
			
				|  |  |                             diagnosis.setHealthProblemName(icd.getString("value"));//诊断名称
 | 
	
		
			
				|  |  |                             diagnosis.setHealthProblem(icd.getString("key"));//诊断代码
 | 
	
		
			
				|  |  |                         }else{
 | 
	
		
			
				|  |  |                             diagnosis.setHealthProblemName(diagnoseName);//诊断名称
 | 
	
		
			
				|  |  |                             diagnosis.setHealthProblem(diagnoseCode);//诊断代码
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         JSONArray jsonArrayDt = new JSONArray();
 | 
	
		
			
				|  |  |                         jsonArrayDt.add(diagnosis);
 | 
	
		
			
				|  |  |                         if(recipe.getString("DIAGNOSE_SUB_CODE")!=null){
 | 
	
		
			
				|  |  |                             diagnosis = new PrescriptionDiagnosis();
 | 
	
		
			
				|  |  |                             diagnoseCode = recipe.getString("DIAGNOSE_CODE");
 | 
	
		
			
				|  |  |                             diagnoseName = recipe.getString("DIAGNOSE_NAME");
 | 
	
		
			
				|  |  |                             diagnosis.setCode(diagnoseCode);//诊断代码
 | 
	
		
			
				|  |  |                             diagnosis.setName(diagnoseName);//诊断名称
 | 
	
		
			
				|  |  |                             icd10 = icd10DictServcie.getHealthProblemsByIcd10Code(diagnoseCode);
 | 
	
		
			
				|  |  |                             if(!StringUtils.isEmpty(icd10)){
 | 
	
		
			
				|  |  |                                 JSONObject icd = JSONObject.parseObject(icd10);
 | 
	
		
			
				|  |  |                                 diagnosis.setHealthProblemName(icd.getString("value"));//诊断名称
 | 
	
		
			
				|  |  |                                 diagnosis.setHealthProblem(icd.getString("key"));//诊断代码
 | 
	
		
			
				|  |  |                             }else{
 | 
	
		
			
				|  |  |                                 diagnosis.setHealthProblemName(diagnoseName);//诊断名称
 | 
	
		
			
				|  |  |                                 diagnosis.setHealthProblem(diagnoseCode);//诊断代码
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                             jsonArrayDt.add(diagnosis);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         pre.put("prescriptionDt",jsonArrayDt);
 | 
	
		
			
				|  |  |                         jsonArray.add(pre);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(jsonArray.size()>1){
 | 
	
		
			
				|  |  |                 JSONObject re = new JSONObject();
 | 
	
		
			
				|  |  |                 re.put("status",200);
 | 
	
		
			
				|  |  |                 re.put("msg","调阅历史处方接口!");
 | 
	
		
			
				|  |  |                 JSONObject data = new JSONObject();
 | 
	
		
			
				|  |  |                 data.put("CODE","1");
 | 
	
		
			
				|  |  |                 JSONArray returnData = new JSONArray();
 | 
	
		
			
				|  |  |                 returnData.add(jsonArray);
 | 
	
		
			
				|  |  |                 data.put("returnData",returnData);
 | 
	
		
			
				|  |  |                 re.put("data",data);
 | 
	
		
			
				|  |  |                 return re.toString();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return recipeJson.toString();
 | 
	
		
			
				|  |  |         re.put("list",jsonArray);
 | 
	
		
			
				|  |  |         re.put("totalCount",totalCount);
 | 
	
		
			
				|  |  |         re.put("errorMsg",errorMsg);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return re;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 |