|  | @ -24,6 +24,7 @@ import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.message.SystemMessageDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.order.BusinessOrderDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.file_upload.FileUploadService;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.consult.dao.HospitalWaitingRoomDao;
 | 
	
	
		
			
				|  | @ -38,6 +39,7 @@ import com.yihu.jw.hospital.mapping.service.PatientMappingService;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.message.service.SystemMessageService;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
 | 
	
		
			
				|  |  | import com.yihu.jw.order.BusinessOrderService;
 | 
	
		
			
				|  |  | import com.yihu.jw.org.dao.BaseOrgDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BaseDoctorPatientFollowDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
	
		
			
				|  | @ -163,412 +165,14 @@ public class YkyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
 | 
	
		
			
				|  |  |     private WlyyHospitalWorkRuleDao wlyyHospitalWorkRuleDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorInfoService baseDoctorService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BusinessOrderService  businessOrderService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${demo.flag}")
 | 
	
		
			
				|  |  |     private boolean demoFlag;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取居民就诊记录接口
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @param startTime
 | 
	
		
			
				|  |  |      * @param endTime
 | 
	
		
			
				|  |  |      * @param demoFlag
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public  List<WlyyOutpatientVO> findOutpatientList(String patient, String startTime, String endTime, boolean demoFlag)throws Exception{
 | 
	
		
			
				|  |  |         logger.info("findOutpatientList patient:"+patient);
 | 
	
		
			
				|  |  |         String patNo =patientMappingService.findHisPatNoByPatient(patient);
 | 
	
		
			
				|  |  |         if(StringUtils.isBlank(patNo)){
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         logger.info("findOutpatientList patNo "+patNo);
 | 
	
		
			
				|  |  |         return entranceService.BS30025(patNo,null,startTime,endTime,demoFlag);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查询单条门诊记录
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @param conNo
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public WlyyOutpatientVO findOutpatientInfo(String patient,String conNo)throws Exception{
 | 
	
		
			
				|  |  |         logger.info("findOutpatientList patient:"+patient);
 | 
	
		
			
				|  |  |         String patNo =patientMappingService.findHisPatNoByPatient(patient);
 | 
	
		
			
				|  |  |         if(StringUtils.isBlank(patNo)){
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         logger.info("findOutpatientList patNo:"+patNo);
 | 
	
		
			
				|  |  |         List<WlyyOutpatientVO> list = entranceService.BS30025(patNo,conNo,null,null,demoFlag);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(list!=null&&list.size()>0){
 | 
	
		
			
				|  |  |             WlyyOutpatientVO outpatientVO = list.get(0);
 | 
	
		
			
				|  |  |             BasePatientDO patientDO = basePatientDao.findById(patient);
 | 
	
		
			
				|  |  |             outpatientVO.setSex(patientDO.getSex()+"");
 | 
	
		
			
				|  |  |             outpatientVO.setBirthday(patientDO.getBirthday());
 | 
	
		
			
				|  |  |             return outpatientVO;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<WlyyPrescriptionVO> findOriginPrescriptionList(String registerSn,String patient,String realOrder,String admNo,boolean demoFlag)throws Exception{
 | 
	
		
			
				|  |  |         String patNo =patientMappingService.findHisPatNoByPatient(patient);
 | 
	
		
			
				|  |  |         if(StringUtils.isBlank(patNo)){
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //BS16017(String REGISTER_SN,String realOrder,String PAT_NO,String ADM_NO,boolean demoFlag) throws Exception {
 | 
	
		
			
				|  |  |         logger.info("findOriginPrescriptionList: registerSn:"+registerSn+" patient"+patient+" patNo:"+patNo+" realOrder:"+realOrder+" admNo:"+admNo);
 | 
	
		
			
				|  |  |         return entranceService.BS16017(registerSn,realOrder,patNo,admNo,demoFlag);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取单条处方记录
 | 
	
		
			
				|  |  |      * @param registerSn
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @param admNo
 | 
	
		
			
				|  |  |      * @param realOrder
 | 
	
		
			
				|  |  |      * @param demoFlag
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public WlyyPrescriptionVO findOriginPrescription(String registerSn, String patient, String admNo, String realOrder, boolean demoFlag)throws Exception{
 | 
	
		
			
				|  |  |         String patNo =patientMappingService.findHisPatNoByPatient(patient);
 | 
	
		
			
				|  |  |         if(StringUtils.isBlank(patNo)){
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionVO> rs = entranceService.BS16017(registerSn,realOrder,patNo,admNo,demoFlag);
 | 
	
		
			
				|  |  |         if(rs!=null&&rs.size()>0){
 | 
	
		
			
				|  |  |             return rs.get(0);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取复诊记录列表
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @param status
 | 
	
		
			
				|  |  |      * @param page
 | 
	
		
			
				|  |  |      * @param size
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public MixEnvelop findReOutpatientList(String patient,Integer status,String startTime,String endTime,Integer page,Integer size){
 | 
	
		
			
				|  |  |         String totalSql = "SELECT " +
 | 
	
		
			
				|  |  |                 " COUNT(1) AS total " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " wlyy_outpatient o " +
 | 
	
		
			
				|  |  |                 " WHERE " +
 | 
	
		
			
				|  |  |                 " o.patient = ? AND o.outpatient_type != '2' ";
 | 
	
		
			
				|  |  |         List<Object> totalParams = new ArrayList<>();
 | 
	
		
			
				|  |  |         totalParams.add(patient);
 | 
	
		
			
				|  |  |         if(status!=null){
 | 
	
		
			
				|  |  |             totalSql +=  " AND o.status = ? ";
 | 
	
		
			
				|  |  |             totalParams.add(status);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(startTime)){
 | 
	
		
			
				|  |  |             totalSql += " AND create_time >= ? ";
 | 
	
		
			
				|  |  |             totalParams.add(startTime+" 00:00:00");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(endTime)){
 | 
	
		
			
				|  |  |             totalSql += " AND create_time <= ? ";
 | 
	
		
			
				|  |  |             totalParams.add(endTime+" 23:59:59");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql,totalParams.toArray());
 | 
	
		
			
				|  |  |         Long count = 0L;
 | 
	
		
			
				|  |  |         if (rstotal != null && rstotal.size() > 0) {
 | 
	
		
			
				|  |  |             count = (Long) rstotal.get(0).get("total");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String sql ="SELECT " +
 | 
	
		
			
				|  |  |                 " o.id, " +
 | 
	
		
			
				|  |  |                 " o.adm_no AS admNo, " +
 | 
	
		
			
				|  |  |                 " o.origin_adm_no AS originAdmNo, " +
 | 
	
		
			
				|  |  |                 " o.register_no AS registerNo, " +
 | 
	
		
			
				|  |  |                 " o.origin_register_no AS originRegisterNo, " +
 | 
	
		
			
				|  |  |                 " o.origin_con_no AS originConNo," +
 | 
	
		
			
				|  |  |                 " o.con_no AS conNo," +
 | 
	
		
			
				|  |  |                 " o.hospital," +
 | 
	
		
			
				|  |  |                 " o.hospital_name AS hospitalName," +
 | 
	
		
			
				|  |  |                 " o.win_no AS winNo," +
 | 
	
		
			
				|  |  |                 " o.type," +
 | 
	
		
			
				|  |  |                 " o.dept AS dept, " +
 | 
	
		
			
				|  |  |                 " o.dept_name AS deptName, " +
 | 
	
		
			
				|  |  |                 " o.patient AS patient, " +
 | 
	
		
			
				|  |  |                 " o.patient_name AS patientName, " +
 | 
	
		
			
				|  |  |                 " o.doctor AS doctor, " +
 | 
	
		
			
				|  |  |                 " o.doctor_name AS doctorName, " +
 | 
	
		
			
				|  |  |                 " o.idcard AS idcard, " +
 | 
	
		
			
				|  |  |                 " o.card_no AS cardNo," +
 | 
	
		
			
				|  |  |                 " o.mjz AS mjz, " +
 | 
	
		
			
				|  |  |                 " o.icd10 AS icd10, " +
 | 
	
		
			
				|  |  |                 " o.icd10_name AS icd10Name, " +
 | 
	
		
			
				|  |  |                 " o.adm_date AS admDate, " +
 | 
	
		
			
				|  |  |                 " o.con_date AS conDate, " +
 | 
	
		
			
				|  |  |                 " o.description AS description, " +
 | 
	
		
			
				|  |  |                 " o.disease_img AS diseaseImg, " +
 | 
	
		
			
				|  |  |                 " o.create_time AS createTime, " +
 | 
	
		
			
				|  |  |                 " o.`status` AS `status`," +
 | 
	
		
			
				|  |  |                 " o.register_date AS registerDate," +
 | 
	
		
			
				|  |  |                 " o.evaluate_status AS evaluateStatus   " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " wlyy_outpatient o " +
 | 
	
		
			
				|  |  |                 " WHERE " +
 | 
	
		
			
				|  |  |                 " o.patient = ? ";
 | 
	
		
			
				|  |  |         List<Object> params = new ArrayList<>();
 | 
	
		
			
				|  |  |         params.add(patient);
 | 
	
		
			
				|  |  |         if(status!=null){
 | 
	
		
			
				|  |  |             sql +=  " AND o.status = ? ";
 | 
	
		
			
				|  |  |             params.add(status);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(startTime)){
 | 
	
		
			
				|  |  |             sql += " AND o.create_time >= ? ";
 | 
	
		
			
				|  |  |             params.add(startTime+" 00:00:00");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(endTime)){
 | 
	
		
			
				|  |  |             sql += " AND o.create_time <= ? ";
 | 
	
		
			
				|  |  |             params.add(endTime+" 23:59:59");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql += " AND o.outpatient_type != '2' ORDER BY o.create_time DESC LIMIT " + (page - 1) * size + "," + size + " ";
 | 
	
		
			
				|  |  |         List<WlyyOutpatientVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyyOutpatientVO.class),params.toArray());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取单条复诊记录信息
 | 
	
		
			
				|  |  |      * @param outpatientId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public com.alibaba.fastjson.JSONObject findReOutpatientInfo(String outpatientId,String prescriptionId){
 | 
	
		
			
				|  |  |         com.alibaba.fastjson.JSONObject rs = new com.alibaba.fastjson.JSONObject();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //复诊信息
 | 
	
		
			
				|  |  |         WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outpatientId);
 | 
	
		
			
				|  |  |         rs.put("outpatient",convertToModel(outpatientDO,WlyyOutpatientVO.class));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //居民详情
 | 
	
		
			
				|  |  |         BasePatientDO basePatientDO = basePatientDao.findById(outpatientDO.getPatient());
 | 
	
		
			
				|  |  |         rs.put("patientName",basePatientDO.getName());
 | 
	
		
			
				|  |  |         rs.put("photo",basePatientDO.getPhoto());
 | 
	
		
			
				|  |  |         rs.put("patientId",basePatientDO.getId());
 | 
	
		
			
				|  |  |         rs.put("idCard",basePatientDO.getIdcard());
 | 
	
		
			
				|  |  |         rs.put("sex", basePatientDO.getSex());
 | 
	
		
			
				|  |  |         PatientMedicareCardDO cardDO = basePatientMedicareCardDao.findByTypeAndPatientCodeAndDel(PatientMedicareCardDO.Type.MedicareCard.getType(),outpatientDO.getPatient(),"1");
 | 
	
		
			
				|  |  |         rs.put("ssc",cardDO);
 | 
	
		
			
				|  |  |         rs.put("age",IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard()));
 | 
	
		
			
				|  |  |         rs.put("address",basePatientDO.getAddress());
 | 
	
		
			
				|  |  |         rs.put("mobile",basePatientDO.getMobile());
 | 
	
		
			
				|  |  |         rs.put("birthday",DateUtil.dateToStr(basePatientDO.getBirthday(),"yyyy-MM-dd"));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //获取处方信息
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionDO> prescriptionDOs = null;
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(prescriptionId)){
 | 
	
		
			
				|  |  |             prescriptionDOs = prescriptionDao.findById(prescriptionId);
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             prescriptionDOs = prescriptionDao.findByOutpatientId(outpatientId);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionVO> prescriptionVOs = new ArrayList<>();
 | 
	
		
			
				|  |  |         if(prescriptionDOs!=null&&prescriptionDOs.size()>0){
 | 
	
		
			
				|  |  |             convertToModels(prescriptionDOs,prescriptionVOs,WlyyPrescriptionVO.class);
 | 
	
		
			
				|  |  |             for(WlyyPrescriptionVO vo:prescriptionVOs){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //疾病信息
 | 
	
		
			
				|  |  |                 vo.setDiagnosisVOs(findDiagnosisById(vo.getId()));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //药品信息
 | 
	
		
			
				|  |  |                 List<WlyyPrescriptionInfoVO> infoVOs = new ArrayList<>();
 | 
	
		
			
				|  |  |                 vo.setInfoVOs(convertToModels(prescriptionInfoDao.findByPrescriptionId(vo.getId()),infoVOs,WlyyPrescriptionInfoVO.class));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //检查检验信息
 | 
	
		
			
				|  |  |                 List<WlyyInspectionVO> inspectionVOs = new ArrayList<>();
 | 
	
		
			
				|  |  |                 vo.setInspectionVOs(convertToModels(wlyyInspectionDao.findByPrescriptionId(vo.getId()),inspectionVOs,WlyyInspectionVO.class));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         rs.put("prescriptions",prescriptionVOs);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //物流信息
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionExpressageDO> expressageDOs = prescriptionExpressageDao.findByOutpatientId(outpatientId);
 | 
	
		
			
				|  |  |         if(expressageDOs!=null&&expressageDOs.size()>0){
 | 
	
		
			
				|  |  |             rs.put("expressage",convertToModel(expressageDOs.get(0), WlyyPrescriptionExpressageVO.class));
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             rs.put("expressage",null);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //物流配送新
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionExpressageLogDO>  expressageLogDOs = prescriptionExpressageLogDao.queryByOutpatientIdOrderByCreateTimeDesc(outpatientId);
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionExpressageLogVO> expressageLogVOs = new ArrayList<>();
 | 
	
		
			
				|  |  |         if(expressageLogDOs!=null&&expressageLogDOs.size()>0){
 | 
	
		
			
				|  |  |             rs.put("expressageLogs",convertToModels(expressageLogDOs,expressageLogVOs, WlyyPrescriptionExpressageLogVO.class));
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             rs.put("expressageLogs",null);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //预约记录
 | 
	
		
			
				|  |  |         List<WlyyPatientRegisterTimeDO> timeDOs = patientRegisterTimeDao.findByOutpatientId(outpatientId);
 | 
	
		
			
				|  |  |         if(timeDOs!=null&&timeDOs.size()>0){
 | 
	
		
			
				|  |  |             rs.put("register",timeDOs.get(0));
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             rs.put("register",null);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return rs;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查询历史
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @param status
 | 
	
		
			
				|  |  |      * @param startTime
 | 
	
		
			
				|  |  |      * @param endTime
 | 
	
		
			
				|  |  |      * @param page
 | 
	
		
			
				|  |  |      * @param size
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public MixEnvelop findPrescriptionList(String patient, String status,String startTime, String endTime, Integer page, Integer size){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String totalSql ="SELECT " +
 | 
	
		
			
				|  |  |                 " count(1) AS total " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " wlyy_prescription p ";
 | 
	
		
			
				|  |  |         totalSql += " WHERE 1=1 ";
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             totalSql+=" AND p.patient_code ='"+patient+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(status)){
 | 
	
		
			
				|  |  |             totalSql+=" AND p.status IN ("+status+")";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(startTime)){
 | 
	
		
			
				|  |  |             totalSql += " AND create_time >='"+startTime+" 00:00:00'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(endTime)){
 | 
	
		
			
				|  |  |             totalSql += " AND create_time <='"+endTime+" 23:59:59'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Long count = 0L;
 | 
	
		
			
				|  |  |         if (rstotal != null && rstotal.size() > 0) {
 | 
	
		
			
				|  |  |             count = (Long) rstotal.get(0).get("total");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql ="SELECT " +
 | 
	
		
			
				|  |  |                 " p.id, " +
 | 
	
		
			
				|  |  |                 " p.real_order AS realOrder," +
 | 
	
		
			
				|  |  |                 " p.origin_real_order AS originRealOrder," +
 | 
	
		
			
				|  |  |                 " p.adm_no AS admNo," +
 | 
	
		
			
				|  |  |                 " p.origin_adm_no AS originAdmNo," +
 | 
	
		
			
				|  |  |                 " p.serial_no AS serialNo," +
 | 
	
		
			
				|  |  |                 " p.type AS type, " +
 | 
	
		
			
				|  |  |                 " p.patient_code AS patientCode, " +
 | 
	
		
			
				|  |  |                 " p.patient_name AS patientName, " +
 | 
	
		
			
				|  |  |                 " p.ssc AS ssc, " +
 | 
	
		
			
				|  |  |                 " p.doctor AS doctor, " +
 | 
	
		
			
				|  |  |                 " p.doctor_name AS doctorName, " +
 | 
	
		
			
				|  |  |                 " p.`status` AS `status`, " +
 | 
	
		
			
				|  |  |                 " p.mk_fail_reason AS mkFailReason, " +
 | 
	
		
			
				|  |  |                 " p.mk_time AS mk_time, " +
 | 
	
		
			
				|  |  |                 " p.prescribe_reason AS prescribeReason, " +
 | 
	
		
			
				|  |  |                 " p.prescribe_time AS prescribeTime, " +
 | 
	
		
			
				|  |  |                 " p.pay_time AS payTime, " +
 | 
	
		
			
				|  |  |                 " p.dosage_time AS dosageTime, " +
 | 
	
		
			
				|  |  |                 " p.finish_time AS finishTime, " +
 | 
	
		
			
				|  |  |                 " p.create_time AS createTime, " +
 | 
	
		
			
				|  |  |                 " p.dept AS dept, " +
 | 
	
		
			
				|  |  |                 " p.dept_name AS deptName, " +
 | 
	
		
			
				|  |  |                 " p.hospital AS hospital, " +
 | 
	
		
			
				|  |  |                 " p.hospital_name AS hospitalName, " +
 | 
	
		
			
				|  |  |                 " p.consult AS consult, " +
 | 
	
		
			
				|  |  |                 " p.dispensary_type AS dispensaryType, " +
 | 
	
		
			
				|  |  |                 " p.reason AS reason, " +
 | 
	
		
			
				|  |  |                 " p.remark AS remark, " +
 | 
	
		
			
				|  |  |                 " p.cancel_reason AS cancelReason, " +
 | 
	
		
			
				|  |  |                 " p.ca_cert_data AS caCertData, " +
 | 
	
		
			
				|  |  |                 " p.ca_message AS caMessage, " +
 | 
	
		
			
				|  |  |                 " p.digital_sign_no AS digitalSignNo, " +
 | 
	
		
			
				|  |  |                 " p.original_data_abstract AS originalDataAbstract, " +
 | 
	
		
			
				|  |  |                 " p.str_original_data AS strOriginalData, " +
 | 
	
		
			
				|  |  |                 " p.his_dept_code AS hisDeptCode, " +
 | 
	
		
			
				|  |  |                 " p.his_doctor_code AS hisDoctorCode, " +
 | 
	
		
			
				|  |  |                 " p.his_gister_type_code AS hisGisterTypeCode, " +
 | 
	
		
			
				|  |  |                 " p.his_rate_type_code AS hisRateTypeCode, " +
 | 
	
		
			
				|  |  |                 " p.his_hospital AS hisHospital, " +
 | 
	
		
			
				|  |  |                 " p.his_register_fee AS hisRegisterFee, " +
 | 
	
		
			
				|  |  |                 " p.pay_status AS payStatus " +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " wlyy_prescription p " +
 | 
	
		
			
				|  |  |                 " WHERE 1=1 ";
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             sql+=" AND p.patient_code ='"+patient+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(status)){
 | 
	
		
			
				|  |  |             sql+=" AND p.status IN ("+status+")";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(startTime)){
 | 
	
		
			
				|  |  |             sql += " AND create_time >='"+startTime+" 00:00:00'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(endTime)){
 | 
	
		
			
				|  |  |             sql += " AND create_time <='"+endTime+" 23:59:59'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql += " LIMIT " + (page - 1) * size + "," + size + "";
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyyPrescriptionVO.class));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //设置病种,药品
 | 
	
		
			
				|  |  |         if(list!=null&&list.size()>0){
 | 
	
		
			
				|  |  |             for(WlyyPrescriptionVO vo:list){
 | 
	
		
			
				|  |  |                 vo.setDiagnosisVOs(findDiagnosisById(vo.getId()));
 | 
	
		
			
				|  |  |                 List<WlyyPrescriptionInfoVO> infoVOs = new ArrayList<>();
 | 
	
		
			
				|  |  |                 vo.setInfoVOs(convertToModels(prescriptionInfoDao.findByPrescriptionId(vo.getId()),infoVOs,WlyyPrescriptionInfoVO.class));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<WlyyPrescriptionDiagnosisVO> findDiagnosisById(String id){
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionDiagnosisDO> list = prescriptionDiagnosisDao.findByPrescriptionId(id);
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionDiagnosisVO> rs = new ArrayList<>();
 | 
	
		
			
				|  |  |         if(list!=null&&list.size()>0){
 | 
	
		
			
				|  |  |             return convertToModels(list,rs,WlyyPrescriptionDiagnosisVO.class);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return rs;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Map<String,Object> findPrescriptionInfo(String prescriptionId){
 | 
	
		
			
				|  |  |         //续方信息
 | 
	
		
			
				|  |  |         Map<String,Object> rs = new HashedMap();
 | 
	
		
			
				|  |  |         WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findOne(prescriptionId);
 | 
	
		
			
				|  |  |         rs.put("prescription",convertToModel(wlyyPrescriptionDO,WlyyPrescriptionVO.class));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //居民详情
 | 
	
		
			
				|  |  |         BasePatientDO basePatientDO = basePatientDao.findById(wlyyPrescriptionDO.getPatientCode());
 | 
	
		
			
				|  |  |         rs.put("patientName",basePatientDO.getName());
 | 
	
		
			
				|  |  |         rs.put("patientId",basePatientDO.getId());
 | 
	
		
			
				|  |  |         rs.put("idCard",basePatientDO.getIdcard());
 | 
	
		
			
				|  |  |         rs.put("sex", basePatientDO.getSex());
 | 
	
		
			
				|  |  |         PatientMedicareCardDO cardDO = basePatientMedicareCardDao.findByTypeAndPatientCodeAndDel(PatientMedicareCardDO.Type.MedicareCard.getType(),wlyyPrescriptionDO.getPatientCode(),"1");
 | 
	
		
			
				|  |  |         rs.put("ssc",cardDO);
 | 
	
		
			
				|  |  |         rs.put("age",IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard()));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //诊断信息
 | 
	
		
			
				|  |  |         rs.put("diagnosis",findDiagnosisById(wlyyPrescriptionDO.getId()));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //药品信息
 | 
	
		
			
				|  |  |         rs.put("infos",prescriptionInfoDao.findByPrescriptionId(wlyyPrescriptionDO.getId()));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return rs;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Boolean checkPrescription(String patient){
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionDO> list = prescriptionDao.findByPatientCode(patient);
 | 
	
		
			
				|  |  |         if(list!=null&&list.size()>0){
 | 
	
		
			
				|  |  |             return false;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return true;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
	
		
			
				|  | @ -592,6 +196,22 @@ public class YkyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
 | 
	
		
			
				|  |  |         outpatientDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         outpatientDO.setPayStatus(0);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BusinessOrderDO businessOrderDO = new BusinessOrderDO();
 | 
	
		
			
				|  |  |         businessOrderDO.setRelationCode(outpatientDO.getId());
 | 
	
		
			
				|  |  |         businessOrderDO.setRelationName("复诊-诊查费");
 | 
	
		
			
				|  |  |         businessOrderDO.setDescription("复诊-诊查费");
 | 
	
		
			
				|  |  |         businessOrderDO.setPatient(outpatientDO.getPatient());
 | 
	
		
			
				|  |  |         businessOrderDO.setPatientName(outpatientDO.getPatientName());
 | 
	
		
			
				|  |  |         businessOrderDO.setDoctor(outpatientDO.getDoctor());
 | 
	
		
			
				|  |  |         if (outpatientDO.getType().equalsIgnoreCase("1")){
 | 
	
		
			
				|  |  |             businessOrderDO.setOrderType(1);
 | 
	
		
			
				|  |  |             businessOrderDO.setOrderCategory("2");
 | 
	
		
			
				|  |  |         }else if (outpatientDO.getType().equalsIgnoreCase("2")){
 | 
	
		
			
				|  |  |             businessOrderDO.setOrderType(3);
 | 
	
		
			
				|  |  |             businessOrderDO.setOrderCategory("3");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         businessOrderService.saveOrder(businessOrderDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(outpatientDO.getRegisterDate()==null){
 | 
	
		
			
				|  |  |             outpatientDO.setRegisterDate(new Date());
 | 
	
		
			
				|  |  |         }
 | 
	
	
		
			
				|  | @ -679,70 +299,6 @@ public class YkyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *@param admNo 门诊唯一号
 | 
	
		
			
				|  |  |      * @param realOrder 处方号
 | 
	
		
			
				|  |  |      *  @param status 处方状态 1审方失败,2审核完成,3结算完成
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Map<String,Object> updatePrescriptionByHisStatu(String admNo,String realOrder,String status)throws Exception {
 | 
	
		
			
				|  |  |         Map<String,Object> rs = new HashedMap();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "";
 | 
	
		
			
				|  |  |         //status 处方流程状态 ,13  开方失败/调整中,20 诊断完成/开方成功/待支付,已完成:100 已完成
 | 
	
		
			
				|  |  |         //pay_status`:处方结算状态,0为未结算,1为结算成功,默认为0',
 | 
	
		
			
				|  |  |         String outPatientSql="";
 | 
	
		
			
				|  |  |         if ("1".equals(status)) {
 | 
	
		
			
				|  |  |             sql = "UPDATE base.wlyy_prescription p SET p.`status`='13' WHERE p.adm_no='" + admNo + "' AND p.real_order='" + realOrder + "' ";
 | 
	
		
			
				|  |  |             WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findByRealOrder(realOrder);
 | 
	
		
			
				|  |  |             jdbcTemplate.execute(sql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         } else if ("2".equals(status)) {
 | 
	
		
			
				|  |  |             //开方成功时候,先用处方号获取本地处方状态是否为开方失败,如果是则需要更新本地的处方
 | 
	
		
			
				|  |  |             sql = "UPDATE base.wlyy_prescription p SET p.`status`='20' WHERE p.adm_no='" + admNo + "' AND p.real_order='" + realOrder + "' ";
 | 
	
		
			
				|  |  |             //变更门诊状态
 | 
	
		
			
				|  |  |             outPatientSql="UPDATE base.wlyy_outpatient p SET p.`status`='2' WHERE p.adm_no='" + admNo + "'";
 | 
	
		
			
				|  |  |             jdbcTemplate.execute(outPatientSql);
 | 
	
		
			
				|  |  |             jdbcTemplate.execute(sql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         } else if ("3".equals(status)) {
 | 
	
		
			
				|  |  |             //自取处方结束
 | 
	
		
			
				|  |  |             WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findByRealOrder(realOrder);
 | 
	
		
			
				|  |  |             WlyyOutpatientDO outpatientDO = outpatientDao.findById(wlyyPrescriptionDO.getOutpatientId());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (null != wlyyPrescriptionDO && 1 == wlyyPrescriptionDO.getDispensaryType()) {
 | 
	
		
			
				|  |  |                 //取药类型:1 自取 2快递配送
 | 
	
		
			
				|  |  |                 wlyyPrescriptionDO.setPayStatus(1);
 | 
	
		
			
				|  |  |                 wlyyPrescriptionDO.setStatus(100);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 prescriptionLogService.addPrescriptionLog(wlyyPrescriptionDO.getId(),100,2,outpatientDO.getDoctor(),outpatientDO.getDoctorName(),"",new Date());
 | 
	
		
			
				|  |  |                 prescriptionDao.save(wlyyPrescriptionDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 //取药类型:1 自取 2快递配送
 | 
	
		
			
				|  |  |                 wlyyPrescriptionDO.setPayStatus(1);
 | 
	
		
			
				|  |  |                 wlyyPrescriptionDO.setStatus(32);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 try{
 | 
	
		
			
				|  |  |                     WlyyPrescriptionVO vo = findOriginPrescription(outpatientDO.getRegisterNo(),outpatientDO.getPatient(),admNo,realOrder,demoFlag);
 | 
	
		
			
				|  |  |                     wlyyPrescriptionDO.setDispUser(vo.getDispUser());
 | 
	
		
			
				|  |  |                     wlyyPrescriptionDO.setDispUserName(vo.getDispUserName());
 | 
	
		
			
				|  |  |                     wlyyPrescriptionDO.setDispDate(new Date());
 | 
	
		
			
				|  |  |                     prescriptionLogService.addPrescriptionLog(wlyyPrescriptionDO.getId(),32,2,vo.getDispUser(),vo.getDispUserName(),"",new Date());
 | 
	
		
			
				|  |  |                 }catch (Exception e){
 | 
	
		
			
				|  |  |                     logger.error("获取处方信息异常"+e.toString());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 prescriptionDao.save(wlyyPrescriptionDO);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //发送取药系统消息
 | 
	
		
			
				|  |  |             SystemMessageDO systemMessageDO = sendPatientGetDrugMes(outpatientDO,wlyyPrescriptionDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             rs.put("mes",systemMessageDO);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         rs.put("flag",true);
 | 
	
		
			
				|  |  |         return rs;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public SystemMessageDO sendPatientGetDrugMes(WlyyOutpatientDO outpatient,WlyyPrescriptionDO prescriptionDO){
 | 
	
		
			
				|  |  |         SystemMessageDO systemMessageDO = new SystemMessageDO();
 |