|  | @ -1,6 +1,5 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.hospital.prescription.service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.dict.dao.DictHospitalDeptDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.dict.DictHospitalDeptDO;
 | 
	
	
		
			
				|  | @ -13,36 +12,42 @@ import com.yihu.jw.entity.hospital.consult.WlyyHospitalWaitingRoomDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDiagnosisDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionExpressageDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.consult.dao.DoctorClinicRoomConsultDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.consult.dao.HospitalWaitingRoomDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PrescriptionDiagnosisDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PrescriptionExpressageDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PrescriptionInfoDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
 | 
	
		
			
				|  |  | import com.yihu.jw.org.dao.BaseOrgDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionDiagnosisVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionExpressageVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionInfoVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.MixEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.base.BaseRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import net.sf.json.JSONArray;
 | 
	
		
			
				|  |  | import net.sf.json.JSONObject;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.map.HashedMap;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.beans.PropertyDescriptor;
 | 
	
		
			
				|  |  | import java.lang.reflect.Method;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by Trick on 2019/5/17.
 | 
	
	
		
			
				|  | @ -75,8 +80,69 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |     private DictHospitalDeptDao dictHospitalDeptDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseOrgDao baseOrgDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private EntranceService entranceService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientMappingDao patientMappingDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${demo.flag}")
 | 
	
		
			
				|  |  |     private boolean demoFlag;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取居民就诊记录接口
 | 
	
		
			
				|  |  |      * @param patNo
 | 
	
		
			
				|  |  |      * @param startTime
 | 
	
		
			
				|  |  |      * @param endTime
 | 
	
		
			
				|  |  |      * @param demoFlag
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONArray findOutpatientList(String patNo, String startTime, String endTime, boolean demoFlag)throws Exception{
 | 
	
		
			
				|  |  |         return entranceService.BS30025(patNo,startTime,endTime,demoFlag);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 原处方记录列表
 | 
	
		
			
				|  |  |      * @param registerSn
 | 
	
		
			
				|  |  |      * @param patNo
 | 
	
		
			
				|  |  |      * @param admNo
 | 
	
		
			
				|  |  |      * @param demoFlag
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<WlyyPrescriptionVO> findOriginPrescriptionList(String registerSn,String patNo,String admNo,boolean demoFlag)throws Exception{
 | 
	
		
			
				|  |  |         return entranceService.BS16017(registerSn,patNo,admNo,null,demoFlag);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取单条处方记录
 | 
	
		
			
				|  |  |      * @param registerSn
 | 
	
		
			
				|  |  |      * @param patNo
 | 
	
		
			
				|  |  |      * @param admNo
 | 
	
		
			
				|  |  |      * @param realOrder
 | 
	
		
			
				|  |  |      * @param demoFlag
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public WlyyPrescriptionVO findOriginPrescription(String registerSn, String patNo, String admNo, String realOrder, boolean demoFlag)throws Exception{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionVO> rs = entranceService.BS16017(registerSn,patNo,admNo,realOrder,demoFlag);
 | 
	
		
			
				|  |  |         if(rs!=null&&rs.size()>0){
 | 
	
		
			
				|  |  |             return rs.get(0);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查询历史
 | 
	
		
			
				|  |  |      * @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 " +
 | 
	
	
		
			
				|  | @ -85,7 +151,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |                 " wlyy_prescription p ";
 | 
	
		
			
				|  |  |         totalSql += " WHERE 1=1 ";
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             totalSql+=" AND p.patient ='"+patient+"'";
 | 
	
		
			
				|  |  |             totalSql+=" AND p.patient_code ='"+patient+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(status)){
 | 
	
		
			
				|  |  |             totalSql+=" AND p.status IN ("+status+")";
 | 
	
	
		
			
				|  | @ -150,7 +216,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |                 " wlyy_prescription p " +
 | 
	
		
			
				|  |  |                 " WHERE 1=1 ";
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             sql+=" AND p.patient ='"+patient+"'";
 | 
	
		
			
				|  |  |             sql+=" AND p.patient_code ='"+patient+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(status)){
 | 
	
		
			
				|  |  |             sql+=" AND p.status IN ("+status+")";
 | 
	
	
		
			
				|  | @ -164,10 +230,12 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |         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));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -229,7 +297,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |      * @param json
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Boolean appointmentRevisit(JSONObject json){
 | 
	
		
			
				|  |  |     public Boolean appointmentRevisit(JSONObject json)throws Exception{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //1.创建支付
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -243,22 +311,19 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |      * @param json
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String paymentCallback(JSONObject json){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String paymentCallback(JSONObject json)throws Exception{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //创建续方
 | 
	
		
			
				|  |  |         createPrescription(json);
 | 
	
		
			
				|  |  |         //创建诊室
 | 
	
		
			
				|  |  |         createRoom(json);
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Boolean createPrescription(JSONObject json){
 | 
	
		
			
				|  |  |     public Boolean createPrescription(JSONObject json) throws Exception{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String patient = json.getString("patient");
 | 
	
		
			
				|  |  |         String doctor = json.getString("doctor");
 | 
	
		
			
				|  |  |         String dept = json.getString("dept");
 | 
	
		
			
				|  |  |         String hospital = json.getString("hospital");
 | 
	
		
			
				|  |  |         String reservationTime = json.getString("reservationTime");
 | 
	
		
			
				|  |  |         Integer consultType = json.getInteger("consultType");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String originRealOrder = json.getString("originRealOrder");
 | 
	
		
			
				|  |  |         String originAdmNo = json.getString("originAdmNo");
 | 
	
	
		
			
				|  | @ -268,8 +333,14 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |         BasePatientDO basePatientDO = basePatientDao.findById(patient);
 | 
	
		
			
				|  |  |         PatientMedicareCardDO cardDO = basePatientMedicareCardDao.findByTypeAndPatientCodeAndDel(PatientMedicareCardDO.Type.MedicareCard.getType(),patient,"1");
 | 
	
		
			
				|  |  |         BaseDoctorDO baseDoctorDO = baseDoctorDao.findOne(doctor);
 | 
	
		
			
				|  |  |         String patNo  = patientMappingDao.findByIdcardAndSource(basePatientDO.getIdcard(),"1").getMappingCode();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         WlyyPrescriptionVO originPrescriptionVO = findOriginPrescription(serialNo,patNo,originAdmNo,originRealOrder,demoFlag);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         WlyyPrescriptionDO prescription = new WlyyPrescriptionDO();
 | 
	
		
			
				|  |  |         prescription.setOriginAdmNo(originAdmNo);
 | 
	
		
			
				|  |  |         prescription.setOriginRealOrder(originRealOrder);
 | 
	
		
			
				|  |  |         prescription.setOriginSerialNo(serialNo);
 | 
	
		
			
				|  |  |         prescription.setStatus(0);
 | 
	
		
			
				|  |  |         prescription.setPatientCode(patient);
 | 
	
		
			
				|  |  |         prescription.setPatientName(basePatientDO.getName());
 | 
	
	
		
			
				|  | @ -277,9 +348,18 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |         prescription.setDoctor(doctor);
 | 
	
		
			
				|  |  |         prescription.setDoctorName(baseDoctorDO.getName());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionInfoVO> originInfoVOs = originPrescriptionVO.getInfoVOs();
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionInfoDO> infoDOs = new ArrayList<>();
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionDiagnosisVO> diagnosisVOs = originPrescriptionVO.getDiagnosisVOs();
 | 
	
		
			
				|  |  |         List<WlyyPrescriptionDiagnosisDO> diagnosisDOs = new ArrayList<>();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         prescriptionInfoDao.save(convertToModels(originInfoVOs,infoDOs,WlyyPrescriptionInfoDO.class));
 | 
	
		
			
				|  |  |         prescriptionDiagnosisDao.save(convertToModels(diagnosisVOs,diagnosisDOs,WlyyPrescriptionDiagnosisDO.class));
 | 
	
		
			
				|  |  |         prescriptionDao.save(prescription);
 | 
	
		
			
				|  |  |         return true;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Boolean createRoom(JSONObject json){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String patient = json.getString("patient");
 | 
	
	
		
			
				|  | @ -287,7 +367,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
 | 
	
		
			
				|  |  |         String dept = json.getString("dept");
 | 
	
		
			
				|  |  |         String hospital = json.getString("hospital");
 | 
	
		
			
				|  |  |         String reservationTime = json.getString("reservationTime");
 | 
	
		
			
				|  |  |         Integer consultType = json.getInteger("consultType");
 | 
	
		
			
				|  |  |         Integer consultType = json.getInt("consultType");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BasePatientDO basePatientDO = basePatientDao.findById(patient);
 | 
	
		
			
				|  |  |         BaseDoctorDO baseDoctorDO = baseDoctorDao.findOne(doctor);
 |