|  | @ -7,11 +7,9 @@ import com.yihu.mm.service.MedicineAnswerLogService;
 | 
	
		
			
				|  |  | import com.yihu.mm.service.PatientExamService;
 | 
	
		
			
				|  |  | import com.yihu.mm.service.PatientService;
 | 
	
		
			
				|  |  | import com.yihu.mm.service.PhysicalExaminationService;
 | 
	
		
			
				|  |  | import com.yihu.mm.util.HttpClientUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.Patient;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiParam;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.json.JSONObject;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
	
		
			
				|  | @ -21,7 +19,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RestController;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  | import javax.servlet.http.HttpSession;
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -51,35 +48,8 @@ public class PhysicalExaminationController extends BaseController {
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/findExames",produces="application/json;charset=UTF-8")
 | 
	
		
			
				|  |  |     @ResponseBody
 | 
	
		
			
				|  |  |     public String findExames(@ApiParam(name = "tp_type", value = "'问卷类型',(备选值:1,2,4)1:初筛问卷,2:助理问卷,4:现场问卷", required = true)@RequestParam(required = false, name = "tp_type") String tp_type,
 | 
	
		
			
				|  |  |                              HttpServletRequest req
 | 
	
		
			
				|  |  |                              ) {
 | 
	
		
			
				|  |  |         HttpSession session = req.getSession();
 | 
	
		
			
				|  |  |             String key = (String) session.getAttribute("key");
 | 
	
		
			
				|  |  |             if(StringUtils.isBlank(key)){
 | 
	
		
			
				|  |  |                 //通过接口查询key
 | 
	
		
			
				|  |  |                 String result = HttpClientUtil.postBody(yuerenApi + "/phonekey", new JSONObject());
 | 
	
		
			
				|  |  |                 JSONObject jsonObject = new JSONObject(result);
 | 
	
		
			
				|  |  |                 String status = jsonObject.get("status").toString();
 | 
	
		
			
				|  |  |                 if ("200".equals(status)) {
 | 
	
		
			
				|  |  |                     JSONObject recordset = jsonObject.getJSONObject("recordset");
 | 
	
		
			
				|  |  |                     key = recordset.getString("key");
 | 
	
		
			
				|  |  |                 }else{
 | 
	
		
			
				|  |  |                     return result;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 session.setMaxInactiveInterval(60*60*4);
 | 
	
		
			
				|  |  |                 session.setAttribute("key",key);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |                              HttpServletRequest req) {
 | 
	
		
			
				|  |  |         String exames = physicalExaminationService.findExames(tp_type, examCode);
 | 
	
		
			
				|  |  |         //if(StringUtils.isNotBlank(examCode)){
 | 
	
		
			
				|  |  |         //    JSONObject examJson = new JSONObject(exames);
 | 
	
		
			
				|  |  |         //    String exam_status = examJson.get("status").toString();
 | 
	
		
			
				|  |  |         //    if ("200".equals(exam_status)) {
 | 
	
		
			
				|  |  |         //        JSONObject recordset = examJson.getJSONObject("recordset");
 | 
	
		
			
				|  |  |         //        key = recordset.getString("key");
 | 
	
		
			
				|  |  |         //    }else{
 | 
	
		
			
				|  |  |         //        return result;
 | 
	
		
			
				|  |  |         //    }
 | 
	
		
			
				|  |  |         //}
 | 
	
		
			
				|  |  |         return exames;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -87,99 +57,92 @@ public class PhysicalExaminationController extends BaseController {
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/insertslip",produces="application/json;charset=UTF-8")
 | 
	
		
			
				|  |  |     @ResponseBody
 | 
	
		
			
				|  |  |     public String insertslip(@ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode, HttpServletRequest req){
 | 
	
		
			
				|  |  |         String key = (String) req.getSession().getAttribute("key");
 | 
	
		
			
				|  |  |         Patient patient = patientService.findByCode(patientCode);
 | 
	
		
			
				|  |  |         return physicalExaminationService.insertslip(patient);
 | 
	
		
			
				|  |  |         int isSignJM = patientService.isSignJM(patientCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(isSignJM==3){
 | 
	
		
			
				|  |  |             String insertslip = physicalExaminationService.insertslip(patient);
 | 
	
		
			
				|  |  |             JSONObject jsonQuestion = new JSONObject(insertslip);
 | 
	
		
			
				|  |  |             JSONObject recordset = jsonQuestion.getJSONObject("recordset");
 | 
	
		
			
				|  |  |             String ct_id = recordset.get("ct_id").toString();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             PatientExam patientExam = new PatientExam();
 | 
	
		
			
				|  |  |             patientExam.setCtId(ct_id);
 | 
	
		
			
				|  |  |             patientExam.setPatient(patientCode);
 | 
	
		
			
				|  |  |             patientExam.setIsComplete(0);
 | 
	
		
			
				|  |  |             patientExam.setTpId(examCode);
 | 
	
		
			
				|  |  |             patientExam.setCreateTime(new Date());
 | 
	
		
			
				|  |  |             patientExamService.save(patientExam);
 | 
	
		
			
				|  |  |             return insertslip;
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             return write(200,"未签约或者签约不在集美","isSignJM",isSignJM);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @ApiOperation(value = "获取试题")
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/findQuestion",produces="application/json;charset=UTF-8")
 | 
	
		
			
				|  |  |     @ResponseBody
 | 
	
		
			
				|  |  |     public String findQuestion(@ApiParam(name = "tp_id", value = "试卷id", required = true)@RequestParam(required = true, name = "tp_id") String tp_id,
 | 
	
		
			
				|  |  |     public String findQuestion(
 | 
	
		
			
				|  |  |                                @ApiParam(name = "pb_id", value = "问卷编号,第一题为0", required = true)@RequestParam(required = true, name = "pb_id") String pb_id,
 | 
	
		
			
				|  |  |                                @ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode,
 | 
	
		
			
				|  |  |                                HttpServletRequest req) throws IOException {
 | 
	
		
			
				|  |  |         String ct_id="";
 | 
	
		
			
				|  |  |         PatientExam patientExam = patientExamService.findByPatientAndTpId(patientCode, tp_id);
 | 
	
		
			
				|  |  |         if(patientExam==null){
 | 
	
		
			
				|  |  |             Patient patient = patientService.findByCode(patientCode);
 | 
	
		
			
				|  |  |             String result = physicalExaminationService.insertslip(patient);
 | 
	
		
			
				|  |  |             JSONObject jsonObject = new JSONObject(result);
 | 
	
		
			
				|  |  |             String status = jsonObject.get("status").toString();
 | 
	
		
			
				|  |  |             if ("200".equals(status)) {
 | 
	
		
			
				|  |  |                 JSONObject recordset = jsonObject.getJSONObject("recordset");
 | 
	
		
			
				|  |  |                 ct_id = recordset.get("ct_id").toString();
 | 
	
		
			
				|  |  |                 patientExam = new PatientExam();
 | 
	
		
			
				|  |  |                 patientExam.setCtId(ct_id);
 | 
	
		
			
				|  |  |                 patientExam.setPatient(patientCode);
 | 
	
		
			
				|  |  |                 patientExam.setIsComplete(0);
 | 
	
		
			
				|  |  |                 patientExam.setTpId(tp_id);
 | 
	
		
			
				|  |  |                 patientExamService.save(patientExam);
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 return result;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             ct_id = patientExam.getCtId();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String question = physicalExaminationService.findQuestion(tp_id, pb_id, ct_id);
 | 
	
		
			
				|  |  |                                @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id) throws IOException {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String question = physicalExaminationService.findQuestion(examCode, pb_id, ct_id);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject jsonQuestion = new JSONObject(question);
 | 
	
		
			
				|  |  |         jsonQuestion.put("answer","");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject recordset = jsonQuestion.getJSONObject("recordset");
 | 
	
		
			
				|  |  |         String _pb_id = recordset.get("pb_id").toString();//越人api问题,  我们数据库保存的居民答案的pb_id是这边返回下一题的pb_id
 | 
	
		
			
				|  |  |         //查找居民是否已经答过该试题
 | 
	
		
			
				|  |  |         MedicineAnswerLog answer = medicineAnswerLogService.findAnswer(patientCode, tp_id, pb_id);
 | 
	
		
			
				|  |  |         if(answer!=null){
 | 
	
		
			
				|  |  |             jsonQuestion.put("answer",answer);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         MedicineAnswerLog answer = medicineAnswerLogService.findAnswer(patientCode, examCode, _pb_id,ct_id);
 | 
	
		
			
				|  |  |         jsonQuestion.put("answer",answer);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //Map<String, Object> resp = customerService.findServerInfo(patient);
 | 
	
		
			
				|  |  |         //resp.put("patient",patient);
 | 
	
		
			
				|  |  |         //return write(1,"查询成功","data",resp);
 | 
	
		
			
				|  |  |         return question;
 | 
	
		
			
				|  |  |         return jsonQuestion.toString();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @ApiOperation(value = "提交试卷答案")
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/handleExam",produces="application/json;charset=UTF-8")
 | 
	
		
			
				|  |  |     @ResponseBody
 | 
	
		
			
				|  |  |     public String handleExam(@ApiParam(name = "tp_id", value = "试卷id", required = true)@RequestParam(required = true, name = "tp_id") String tp_id,
 | 
	
		
			
				|  |  |     public String handleExam(@ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id,
 | 
	
		
			
				|  |  |                                @ApiParam(name = "pb_id", value = "问卷编号,第一题为0", required = true)@RequestParam(required = true, name = "pb_id") String pb_id,
 | 
	
		
			
				|  |  |                                 @ApiParam(name = "i_multiselect", value = "试题类型(0单选 ,1多选)", required = true)@RequestParam(required = true, name = "i_multiselect") String i_multiselect,
 | 
	
		
			
				|  |  |                                @ApiParam(name = "dc_answer", value = "问题答案", required = true)@RequestParam(required = true, name = "dc_answer") String dc_answer,
 | 
	
		
			
				|  |  |                              @ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode,
 | 
	
		
			
				|  |  |                              @ApiParam(name = "isLast", value = "是否是最后一题(0否 ,1是)", required = true)@RequestParam(required = true, name = "isLast") String isLast,
 | 
	
		
			
				|  |  |                             HttpServletRequest req){
 | 
	
		
			
				|  |  |         PatientExam patientExam = patientExamService.findByPatientAndTpId(patientCode, tp_id);
 | 
	
		
			
				|  |  |                              @ApiParam(name = "isLast", value = "是否是最后一题(0否 ,1是)", required = true)@RequestParam(required = false, name = "isLast") String isLast){
 | 
	
		
			
				|  |  |         PatientExam patientExam = patientExamService.findByPatientAndTpId(patientCode, examCode,ct_id);
 | 
	
		
			
				|  |  |         String tpName = patientExam.getTpName();
 | 
	
		
			
				|  |  |         String ct_id = patientExam.getCtId();
 | 
	
		
			
				|  |  |         String result = physicalExaminationService.handleExam(tp_id, pb_id, dc_answer, ct_id);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //将答案保存到自己数据库
 | 
	
		
			
				|  |  |         MedicineAnswerLog medicineAnswerLog = new MedicineAnswerLog();
 | 
	
		
			
				|  |  |         medicineAnswerLog.setPatientCode(patientCode);
 | 
	
		
			
				|  |  |         medicineAnswerLog.setTpId(tp_id);
 | 
	
		
			
				|  |  |         medicineAnswerLog.setTpName(tpName);
 | 
	
		
			
				|  |  |         medicineAnswerLog.setPbType(String.valueOf(i_multiselect));
 | 
	
		
			
				|  |  |         medicineAnswerLog.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         medicineAnswerLog.setProblems(dc_answer);
 | 
	
		
			
				|  |  |         medicineAnswerLogService.save(medicineAnswerLog);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //最后一题
 | 
	
		
			
				|  |  |         if("1".equals(isLast)){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String result = physicalExaminationService.handleExam(examCode, pb_id, dc_answer, ct_id);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //将答案保存/更新到自己数据库
 | 
	
		
			
				|  |  |         MedicineAnswerLog answer = medicineAnswerLogService.findAnswer(patientCode, examCode, pb_id, ct_id);
 | 
	
		
			
				|  |  |         if(answer==null){//新增
 | 
	
		
			
				|  |  |             answer = new MedicineAnswerLog();
 | 
	
		
			
				|  |  |             answer.setCreateTime(new Date());
 | 
	
		
			
				|  |  |             answer.setPatientCode(patientCode);
 | 
	
		
			
				|  |  |             answer.setPbId(pb_id);
 | 
	
		
			
				|  |  |             answer.setTpId(examCode);
 | 
	
		
			
				|  |  |             answer.setTpName(tpName);
 | 
	
		
			
				|  |  |             answer.setCtId(ct_id);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         answer.setPbType(String.valueOf(i_multiselect));
 | 
	
		
			
				|  |  |         answer.setProblems(dc_answer);
 | 
	
		
			
				|  |  |         medicineAnswerLogService.save(answer);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @ApiOperation(value = "四诊资料采集")
 | 
	
		
			
				|  |  |     @RequestMapping(value = "/dillphoneimgdata",produces="application/json;charset=UTF-8")
 | 
	
		
			
				|  |  |     @ResponseBody
 | 
	
		
			
				|  |  |     public String dillphoneimgdata(@ApiParam(name = "tp_id", value = "试卷id", required = true)@RequestParam(required = true, name = "tp_id") String tp_id,
 | 
	
		
			
				|  |  |                              @ApiParam(name = "pb_id", value = "问卷编号,第一题为0", required = true)@RequestParam(required = true, name = "pb_id") String pb_id,
 | 
	
		
			
				|  |  |                              @ApiParam(name = "dc_answer", value = "问题答案", required = true)@RequestParam(required = true, name = "dc_answer") String dc_answer,
 | 
	
		
			
				|  |  |     public String dillphoneimgdata(@ApiParam(name = "at_id", value = "文件id", required = true)@RequestParam(required = true, name = "at_id") String at_id,
 | 
	
		
			
				|  |  |                              @ApiParam(name = "answer", value = "问题答案,文件名称", required = true)@RequestParam(required = true, name = "answer") String answer,
 | 
	
		
			
				|  |  |                               @ApiParam(name = "type", value = "1.脸型  2.舌像  3.声音", required = true)@RequestParam(required = true, name = "type") String type,
 | 
	
		
			
				|  |  |                              @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |         String result = physicalExaminationService.dillphoneimgdata(at_id, answer, type, ct_id);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @ApiOperation(value = "查找报告单")
 |