|
@ -0,0 +1,198 @@
|
|
|
package com.yihu.jw.patient.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
|
|
|
import com.yihu.jw.entity.base.patient.PatientPreDiagnosisInfoDO;
|
|
|
import com.yihu.jw.entity.hospital.family.WlyyPatientFamilyMemberDO;
|
|
|
import com.yihu.jw.hospital.family.dao.WlyyPatientFamilyMemberDao;
|
|
|
import com.yihu.jw.mysql.query.BaseJpaService;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
|
|
|
import com.yihu.jw.patient.dao.PatientPreDiagnosisInfoDao;
|
|
|
import com.yihu.jw.restmodel.web.PageEnvelop;
|
|
|
import com.yihu.jw.util.encrypt.MD5;
|
|
|
import com.yihu.jw.util.entity.ServiceException;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* Created by yeshijie on 2024/12/20.
|
|
|
*/
|
|
|
@Service
|
|
|
public class PatientPreDiagnosisInfoService extends BaseJpaService<PatientPreDiagnosisInfoDO, PatientPreDiagnosisInfoDao> {
|
|
|
|
|
|
@Autowired
|
|
|
private PatientPreDiagnosisInfoDao patientPreDiagnosisInfoDao;
|
|
|
@Autowired
|
|
|
private BasePatientDao patientDao;
|
|
|
@Autowired
|
|
|
private BasePatientMedicareCardDao basePatientMedicareCardDao;
|
|
|
@Autowired
|
|
|
private WlyyPatientFamilyMemberDao familyMemberDao;
|
|
|
|
|
|
//诊前信息分页
|
|
|
public PageEnvelop findByPage(String name,String mobile,String idcard,String chargeType,String fromSource,String systolicPressureStart
|
|
|
,String diastolicPressureStart,String systolicPressureEnd,String diastolicPressureEnd,String startTime,String endTime,int page,int size){
|
|
|
String sql = "select * ";
|
|
|
String countSql = "selcet count(*) ";
|
|
|
String filter = " from base_patient_pre_diagnosis_info where 1=1 ";
|
|
|
String orderBy = " order by id desc limit "+(page-1)*size+","+size;
|
|
|
if(StringUtils.isNotBlank(name)){
|
|
|
filter += " and (name like '%"+name+"%' or card_no like '%"+name+"%')";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(mobile)){
|
|
|
filter += " and mobile like '%"+mobile+"%' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(idcard)){
|
|
|
filter += " and idcard like '%"+idcard+"%' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(chargeType)){
|
|
|
filter += " and charge_type = '"+chargeType+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(fromSource)){
|
|
|
filter += " and from_source = '"+fromSource+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(systolicPressureStart)){
|
|
|
filter += " and systolic_pressure >= '"+systolicPressureStart+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(systolicPressureEnd)){
|
|
|
filter += " and systolic_pressure <= '"+systolicPressureEnd+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(diastolicPressureStart)){
|
|
|
filter += " and diastolic_pressure >= '"+diastolicPressureStart+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(diastolicPressureEnd)){
|
|
|
filter += " and diastolic_pressure <= '"+diastolicPressureEnd+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(startTime)){
|
|
|
filter += " and create_time >= '"+startTime+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(endTime)){
|
|
|
filter += " and create_time <= '"+endTime+"' ";
|
|
|
}
|
|
|
|
|
|
List<PatientPreDiagnosisInfoDO> list = jdbcTemplate.query(sql+filter+orderBy,new BeanPropertyRowMapper<>(PatientPreDiagnosisInfoDO.class));
|
|
|
long count = jdbcTemplate.queryForObject(countSql+filter,Long.class);
|
|
|
return PageEnvelop.getSuccessListWithPage("查询成功",list,page,size,count);
|
|
|
}
|
|
|
|
|
|
//保存患者档案
|
|
|
public PatientPreDiagnosisInfoDO savePreDiagnosisInfo(PatientPreDiagnosisInfoDO infoDO) throws Exception{
|
|
|
String idcard = infoDO.getIdcard();
|
|
|
if(StringUtils.isNotBlank(infoDO.getIdcard())){
|
|
|
throw new ServiceException("请输入证件类型");
|
|
|
}
|
|
|
String cardType = infoDO.getIdcardType();
|
|
|
String mobile = infoDO.getMobile();
|
|
|
BasePatientDO patient = patientDao.findByIdcard(infoDO.getIdcard());
|
|
|
if(patient==null){
|
|
|
patient = new BasePatientDO();
|
|
|
String salt = UUID.randomUUID().toString().substring(0, 5);
|
|
|
//三院注册不需要密码 默认密码aza354q.
|
|
|
String pw = "aza354q.";
|
|
|
patient.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
|
|
|
patient.setSalt(salt);
|
|
|
patient.setCardType(cardType);
|
|
|
try {
|
|
|
if ("身份证".equals(cardType)) {
|
|
|
String year = idcard.substring(6, 10);
|
|
|
String month = idcard.substring(10, 12);
|
|
|
String day = idcard.substring(12, 14);
|
|
|
String birthday = year + "-" + month + "-" + day;
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
patient.setBirthday(dateFormat.parse(birthday));
|
|
|
}
|
|
|
} catch (ParseException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
patient.setMobile(mobile);
|
|
|
patient.setDel("1");
|
|
|
patient.setEnabled(1);
|
|
|
patient.setLocked(0);
|
|
|
patient.setSsc(infoDO.getCardNo());
|
|
|
patient.setCreateTime(new Date());
|
|
|
patient.setUpdateTime(new Date());
|
|
|
patient.setName(infoDO.getName());
|
|
|
if (StringUtils.isNoneBlank(idcard)) {
|
|
|
patient.setIdcard(idcard);
|
|
|
}
|
|
|
BasePatientDO temp = patientDao.save(patient);
|
|
|
|
|
|
PatientMedicareCardDO medicareCardDO = new PatientMedicareCardDO();
|
|
|
medicareCardDO.setDel("1");
|
|
|
medicareCardDO.setParentType("A");
|
|
|
medicareCardDO.setType("A_01");
|
|
|
medicareCardDO.setPatientCode(temp.getId());
|
|
|
|
|
|
basePatientMedicareCardDao.save(medicareCardDO);
|
|
|
WlyyPatientFamilyMemberDO wlyyPatientFamilyMemberDO = new WlyyPatientFamilyMemberDO();
|
|
|
wlyyPatientFamilyMemberDO.setIsDel(1);
|
|
|
wlyyPatientFamilyMemberDO.setPatient(patient.getId());
|
|
|
wlyyPatientFamilyMemberDO.setFamilyMember(patient.getId());
|
|
|
wlyyPatientFamilyMemberDO.setFamilyRelation("7");
|
|
|
wlyyPatientFamilyMemberDO.setFamilyRelationName("本人");
|
|
|
if (StringUtils.isNoneBlank(idcard)) {
|
|
|
wlyyPatientFamilyMemberDO.setCardNo(idcard);
|
|
|
}
|
|
|
familyMemberDao.save(wlyyPatientFamilyMemberDO);
|
|
|
}
|
|
|
infoDO.setPatient(patient.getId());
|
|
|
infoDO.setCreateTime(new Date());
|
|
|
infoDO = patientPreDiagnosisInfoDao.save(infoDO);
|
|
|
return infoDO;
|
|
|
}
|
|
|
|
|
|
//获取患者档案
|
|
|
public PatientPreDiagnosisInfoDO findInfoDetail(Long id){
|
|
|
return patientPreDiagnosisInfoDao.getOne(id);
|
|
|
}
|
|
|
|
|
|
//读卡
|
|
|
public JSONObject cardReading(String cardNo){
|
|
|
PatientPreDiagnosisInfoDO preDiagnosisInfoDO = patientPreDiagnosisInfoDao.getOne(1L);
|
|
|
JSONObject json = (JSONObject) JSON.toJSON(preDiagnosisInfoDO);
|
|
|
json.remove("id");
|
|
|
json.put("cardNo",cardNo);
|
|
|
json.remove("createTime");
|
|
|
json.remove("patient");
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
//关联平台测量数据
|
|
|
public PageEnvelop findHealthIndexPage(String deviceSn,String dept,String startTime,String endTime,int page,int size){
|
|
|
String sql = "SELECT i.id,i.value1,i.value2,i.value3,date_format(i.record_date,'%Y-%m-%d %H:%i:%S' ) recordDate " +
|
|
|
",i.name,i.dept,i.dept_name deptName,d.device_name deviceName ";
|
|
|
String countSql = "selcet count(i.id) ";
|
|
|
String filter = " from wlyy_patient_health_index i,wlyy_devices d " +
|
|
|
" WHERE i.device_sn=d.device_code and i.type=2 and i.del=1 ";
|
|
|
String orderBy = " order by id desc limit "+(page-1)*size+","+size;
|
|
|
if(StringUtils.isNotBlank(deviceSn)){
|
|
|
filter += " and i.device_sn >= '"+deviceSn+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(dept)){
|
|
|
filter += " and i.dept = '"+dept+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(startTime)){
|
|
|
filter += " and i.record_date >= '"+startTime+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(endTime)){
|
|
|
filter += " and i.record_date <= '"+endTime+"' ";
|
|
|
}
|
|
|
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql+filter+orderBy);
|
|
|
long count = jdbcTemplate.queryForObject(countSql+filter,Long.class);
|
|
|
return PageEnvelop.getSuccessListWithPage("查询成功",list,page,size,count);
|
|
|
}
|
|
|
|
|
|
}
|