|
@ -2,15 +2,18 @@ package com.yihu.wlyy.service.app.prenatalInspector;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.device.entity.DevicePatientHealthIndex;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.entity.patient.SignFamily;
|
|
|
import com.yihu.wlyy.entity.patient.prenatal.PrenatalInspectorPlan;
|
|
|
import com.yihu.wlyy.entity.patient.prenatal.PrenatalInspectorPlanLibrary;
|
|
|
import com.yihu.wlyy.entity.patient.prenatal.PrenatalInspectorPreCard;
|
|
|
import com.yihu.wlyy.health.repository.DevicePatientHealthIndexDao;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
import com.yihu.wlyy.repository.patient.*;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
|
|
|
import com.yihu.wlyy.service.app.sign.FamilyContractService;
|
|
|
import com.yihu.wlyy.service.third.jw.JwMaternalChildService;
|
|
|
import com.yihu.wlyy.service.third.jw.ZyDictService;
|
|
@ -18,14 +21,13 @@ import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by yeshijie on 2017/6/6.
|
|
@ -34,6 +36,8 @@ import java.util.Map;
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(PrenatalInspectorPreCardService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private PrenatalInspectorPreCardDao prenatalInspectorPreCardDao;
|
|
|
@Autowired
|
|
@ -56,6 +60,10 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
private DoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private ZyDictService zyDictService;
|
|
|
@Autowired
|
|
|
private PatientHealthIndexService healthIndexService;
|
|
|
@Autowired
|
|
|
private DevicePatientHealthIndexDao healthIndexDao;
|
|
|
|
|
|
// public
|
|
|
|
|
@ -95,12 +103,14 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
}
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
try{
|
|
|
boolean checkFlag = true;//是否查询预建卡接口。有建卡记录且建卡记录有结束妊娠才查询预建卡
|
|
|
String response = jwMaternalChildService.getEhrMaternalFirstExamRecord(patient.getIdcard(),hospital);
|
|
|
JSONObject json = JSONObject.parseObject(response);
|
|
|
JSONArray data = null;
|
|
|
if(json.getInteger("status")==200){
|
|
|
data = json.getJSONObject("data").getJSONArray("DATA");
|
|
|
}
|
|
|
Map<String,String> map = new HashMap<>();//存储产检号,用于去除预建卡信息中重复记录
|
|
|
if(data!=null&&data.size()>0){//有建卡信息
|
|
|
for (int i=0;i<data.size();i++) {
|
|
|
JSONObject planJson = new JSONObject();
|
|
@ -119,8 +129,9 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
planJson.put("mensesLast",MENSES_LAST);
|
|
|
planJson.put("expectedTime",EXPECTED_TIME);
|
|
|
Date date = new Date();
|
|
|
map.put("PREGNANCY_NO","PREGNANCY_NO");
|
|
|
if(StringUtils.isBlank(END_TIME)){
|
|
|
|
|
|
checkFlag = checkFlag?false:checkFlag;
|
|
|
//未结束妊娠,生成待产检计划
|
|
|
List<PrenatalInspectorPlan> plans = prenatalInspectorPlanDao.findByPatient(patientCode);
|
|
|
boolean flag = false;
|
|
@ -164,7 +175,7 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
//计算距离下次产检时间
|
|
|
Long nextExamDay = 0l;
|
|
|
for (PrenatalInspectorPlan plan:plans) {
|
|
|
Long temp = DateUtil.getDays(date,plan.getInspectionStartTime());
|
|
|
Long temp = DateUtil.getDays(plan.getInspectionTime(),date);
|
|
|
if(nextExamDay==0||nextExamDay>temp){
|
|
|
nextExamDay = temp;
|
|
|
}
|
|
@ -179,10 +190,10 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
JSONObject bedJson = JSONObject.parseObject(bedRecode);
|
|
|
JSONArray bedData = null;
|
|
|
if(bedJson.getInteger("status")==200){
|
|
|
bedData = json.getJSONObject("data").getJSONArray("DATA");
|
|
|
bedData = bedJson.getJSONObject("data").getJSONArray("DATA");
|
|
|
}
|
|
|
if(bedData!=null&&bedData.size()>0){
|
|
|
JSONObject exam = data.getJSONObject(data.size()-1);
|
|
|
JSONObject exam = bedData.getJSONObject(bedData.size()-1);
|
|
|
precontract_org_name = exam.getString("PRECONTRACT_ORG_NAME");
|
|
|
}
|
|
|
}catch (Exception e){
|
|
@ -192,18 +203,25 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
}
|
|
|
re.add(planJson);
|
|
|
}
|
|
|
}else{
|
|
|
//没有建卡信息,请求预建卡接口
|
|
|
response = jwMaternalChildService.getEhrMaternalPreFirstExamRecord(patient.getIdcard(),hospital);
|
|
|
JSONObject preJson = JSONObject.parseObject(response);
|
|
|
}
|
|
|
|
|
|
//请求预建卡接口
|
|
|
if(checkFlag){
|
|
|
String resp = jwMaternalChildService.getEhrMaternalPreFirstExamRecord(patient.getIdcard(),hospital);
|
|
|
JSONObject preJson = JSONObject.parseObject(resp);
|
|
|
JSONArray preData = null;
|
|
|
if(preJson.getInteger("status")==200){
|
|
|
preData = preJson.getJSONObject("data").getJSONArray("DATA");
|
|
|
if(preData!=null&&preData.size()>0){
|
|
|
JSONArray rep = new JSONArray();
|
|
|
for (int i=0;i<preData.size();i++){
|
|
|
JSONObject planJson = new JSONObject();
|
|
|
JSONObject pregnancy = preData.getJSONObject(i);
|
|
|
String PREGNANCY_NO = pregnancy.getString("PREGNANCY_NO");//智业产检号
|
|
|
if(map.containsKey(PREGNANCY_NO)){
|
|
|
continue;//去重
|
|
|
}
|
|
|
|
|
|
String END_MANNER = pregnancy.getString("END_MANNER");//妊娠终止方式
|
|
|
String END_TIME = pregnancy.getString("END_TIME");//结束妊娠
|
|
|
String MENSES_LAST = pregnancy.getString("MENSES_LAST");//末次月经
|
|
@ -219,7 +237,6 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
if(plans==null||plans.size()==0){//判断是否已经生成产检记录
|
|
|
//预建卡还没产检,有产检就会生成产检记录,建卡接口就会有数据
|
|
|
Long days = DateUtil.getDays(dueday,date);
|
|
|
// days = days>365?0:days;//老早前的测试数据处理
|
|
|
List<PrenatalInspectorPlanLibrary> libraries = prenatalInspectorPlanLibraryDao.findByDays(days);
|
|
|
plans = new ArrayList<>();
|
|
|
PrenatalInspectorPlan plan = null;
|
|
@ -231,10 +248,7 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
plan.setCzrq(date);
|
|
|
plan.setDel("1");
|
|
|
plan.setCheckItem(library.getCheckItem());
|
|
|
// plan.setInspectionCode(PREGNANCY_NO);//产检号
|
|
|
plan.setInspectionTime(DateUtil.getPrenatalInspectorDate(dueday,-library.getEndDay().intValue()));
|
|
|
// plan.setInspectionEndTime(DateUtil.getPrenatalInspectorDate(lastMenstrualDate,library.getEndDay().intValue()));
|
|
|
// plan.setInspectionStartTime(DateUtil.getPrenatalInspectorDate(dueday,-library.getEndDay().intValue()));
|
|
|
plan.setName(library.getName());
|
|
|
plan.setThisFocus(library.getThisFocus());
|
|
|
plan.setThisNote(library.getThisNote());
|
|
@ -249,7 +263,7 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
//计算距离下次产检时间
|
|
|
Long nextExamDay = 0l;
|
|
|
for (PrenatalInspectorPlan plan:plans) {
|
|
|
Long temp = DateUtil.getDays(date,plan.getInspectionStartTime());
|
|
|
Long temp = DateUtil.getDays(plan.getInspectionTime(),date);
|
|
|
if(nextExamDay==0||nextExamDay>temp){
|
|
|
nextExamDay = temp;
|
|
|
}
|
|
@ -257,11 +271,20 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
planJson.put("plans",plans);//待产检列表
|
|
|
planJson.put("nextExamDay",nextExamDay);//距离下次产检天数
|
|
|
planJson.put("precontractOrgName",null);//产床医院
|
|
|
re.add(planJson);
|
|
|
rep.add(planJson);
|
|
|
}
|
|
|
|
|
|
//重新排序
|
|
|
if(rep.size()>0&&re.size()>0){
|
|
|
for (int i=0;i<re.size();i++){
|
|
|
rep.add(re.getJSONObject(i));
|
|
|
}
|
|
|
return rep;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@ -352,8 +375,8 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
* @param patientCode
|
|
|
* @return
|
|
|
*/
|
|
|
public String reExamRecode(String patientCode,String pregnancyNo){
|
|
|
String re = "";
|
|
|
public JSONArray reExamRecode(String patientCode,String pregnancyNo){
|
|
|
JSONArray re = new JSONArray();
|
|
|
try {
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
|
|
|
String hospital = null;
|
|
@ -363,7 +386,15 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
|
|
|
String response = jwMaternalChildService.getEhrMaternalReExamRecord(patient.getIdcard(),hospital,pregnancyNo);
|
|
|
return response;
|
|
|
JSONObject json = JSONObject.parseObject(response);
|
|
|
JSONArray data = null;
|
|
|
if(json.getInteger("status")==200){
|
|
|
data = json.getJSONObject("data").getJSONArray("DATA");
|
|
|
}
|
|
|
if(data!=null&&data.size()>0){
|
|
|
return data;
|
|
|
}
|
|
|
return re;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@ -513,12 +544,33 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
* 新建产检预建卡
|
|
|
*/
|
|
|
@Transactional
|
|
|
public String addPrenatalInspectorPreCard(PrenatalInspectorPreCard preCard,String patientcCode){
|
|
|
public String addPrenatalInspectorPreCard(PrenatalInspectorPreCard preCard,String patientCode){
|
|
|
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patientcCode);
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
|
|
|
if(signFamily==null){
|
|
|
return "-1";
|
|
|
}
|
|
|
|
|
|
//判断是否有预建卡
|
|
|
try {
|
|
|
String resp = jwMaternalChildService.getEhrMaternalPreFirstExamRecord(preCard.getIdcard(),signFamily.getHospital());
|
|
|
JSONObject preJson = JSONObject.parseObject(resp);
|
|
|
JSONArray preData = null;
|
|
|
if(preJson.getInteger("status")==200){
|
|
|
preData = preJson.getJSONObject("data").getJSONArray("DATA");
|
|
|
if(preData!=null&&preData.size()>0){
|
|
|
JSONObject temp = preData.getJSONObject(0);
|
|
|
String END_MANNER = temp.getString("END_MANNER");//妊娠终止方式
|
|
|
if(StringUtils.isBlank(END_MANNER)){
|
|
|
return "-2";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return "-3";
|
|
|
}
|
|
|
|
|
|
//获取团队长
|
|
|
Doctor doctor = doctorDao.findByAdminTeamId(signFamily.getAdminTeamId());
|
|
|
preCard.setDoctor(doctor.getCode());
|
|
@ -588,4 +640,32 @@ public class PrenatalInspectorPreCardService extends BaseService {
|
|
|
return preCard.getCode();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存体征数据 有保存体征数据才更新
|
|
|
* @param preCard
|
|
|
* @param patientCode
|
|
|
*/
|
|
|
public void saveHealthIndex(PrenatalInspectorPreCard preCard,String patientCode){
|
|
|
if(StringUtils.isNotBlank(preCard.getHeight())&&StringUtils.isNotBlank(preCard.getWeight())){
|
|
|
//先判断体征数据是否变更
|
|
|
DevicePatientHealthIndex index = healthIndexDao.findLastData(patientCode, 3);
|
|
|
String height = index.getValue2();
|
|
|
String weight = index.getValue1();
|
|
|
if(!preCard.getHeight().equals(height)||!preCard.getWeight().equals(weight)){
|
|
|
//更新体征数据
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("time",DateUtil.dateToStrLong(preCard.getCzrq()));
|
|
|
json.put("height",preCard.getHeight());
|
|
|
json.put("weight",preCard.getWeight());
|
|
|
try {
|
|
|
healthIndexService.addPatientHealthIndex(json.toString(), "3", patientCode, null);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
logger.error("预建卡时 保存体征数据失败。。。");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|