|
@ -2,6 +2,7 @@ package com.yihu.jw.hospital.family.service;
|
|
|
|
|
|
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.hospital.family.BasePatientMemberDictDO;
|
|
|
import com.yihu.jw.entity.hospital.family.WlyyPatientFamilyMemberDO;
|
|
|
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
|
|
@ -9,7 +10,9 @@ import com.yihu.jw.hospital.family.dao.BasePatientMemberDictDao;
|
|
|
import com.yihu.jw.hospital.family.dao.WlyyPatientFamilyMemberDao;
|
|
|
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
|
|
|
import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
|
|
|
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
|
|
|
import com.yihu.jw.restmodel.web.Envelop;
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
|
import com.yihu.jw.rm.base.BaseRequestMapping;
|
|
@ -20,6 +23,7 @@ import net.sf.json.JSONArray;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@ -42,9 +46,18 @@ public class WlyyFamilyMemberService extends BaseJpaService<WlyyPatientFamilyMem
|
|
|
private BasePatientDao basePatientDao;
|
|
|
@Autowired
|
|
|
private HibenateUtils hibenateUtils;
|
|
|
@Autowired
|
|
|
private YkyyEntranceService ykyyEntranceService;
|
|
|
@Autowired
|
|
|
private BasePatientMedicareCardDao basePatientMedicareCardDao;
|
|
|
@Value("${wechat.id}")
|
|
|
private String wxId;
|
|
|
|
|
|
//添加关联家属
|
|
|
@Transactional
|
|
|
public MixEnvelop addFamily(String id,String patientId, String familyName, String dictId, String cardType, String idCard, String phoneNum,boolean demo) throws Exception {
|
|
|
public MixEnvelop addFamily(String id,String patientId, String familyName, String dictId, String cardType, String idCard, String phoneNum,boolean demo,String medicareType,String medicare) throws Exception {
|
|
|
MixEnvelop mixEnvelop = new MixEnvelop();
|
|
|
try{
|
|
|
BasePatientMemberDictDO basePatientMemberDictDO = basePatientMemberDictDao.findOne(dictId);
|
|
|
BasePatientDO basePatientDO = basePatientDao.findByIdcard(idCard);
|
|
|
Map<String,Object> resultMap = new HashMap<>();
|
|
@ -59,92 +72,149 @@ public class WlyyFamilyMemberService extends BaseJpaService<WlyyPatientFamilyMem
|
|
|
if (StringUtils.isNotBlank(id)){
|
|
|
result = wlyyPatientFamilyMemberDao.findOne(id);
|
|
|
}
|
|
|
MixEnvelop mixEnvelop = new MixEnvelop();
|
|
|
|
|
|
String dictName = "";
|
|
|
if (null!=basePatientMemberDictDO){
|
|
|
dictName = basePatientMemberDictDO.getRelationName();
|
|
|
}
|
|
|
String familyId="";
|
|
|
String birth = "";
|
|
|
int sex=3;
|
|
|
//获取his家属数据
|
|
|
JSONArray jsonArray = entranceService.BS10008(idCard,"","","","","",demo);
|
|
|
if(jsonArray!=null&&jsonArray.size()>0){
|
|
|
net.sf.json.JSONObject jsonObject= net.sf.json.JSONObject.fromObject(jsonArray.get(0).toString());
|
|
|
String familyId="";
|
|
|
//如果病人id为空则没有就诊记录
|
|
|
if (null!=jsonObject.get("Patient_Id")){
|
|
|
familyId = jsonObject.getString("Patient_Id");
|
|
|
String Pat_name = jsonObject.getString("Pat_Name");
|
|
|
if (null!=jsonObject.get("Phone_Number_Business")){
|
|
|
String Next_Of_Kin_Phone = jsonObject.get("Phone_Number_Business").toString();
|
|
|
if(!Next_Of_Kin_Phone.equalsIgnoreCase(phoneNum)){
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
if("xm_ykyy_wx".equalsIgnoreCase(wxId)){
|
|
|
jsonArray = ykyyEntranceService.findHisPatientBymMedicare(medicare,false);
|
|
|
if(jsonArray!=null&&jsonArray.size()>0){
|
|
|
net.sf.json.JSONObject jsonObject= net.sf.json.JSONObject.fromObject(jsonArray.get(0).toString());
|
|
|
if (null!=jsonObject.get("brid")){
|
|
|
String Pat_name = jsonObject.getString("brxm");
|
|
|
if (!Pat_name.equalsIgnoreCase(familyName)) {
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("您所添加的家属的电话有误,无法添加");
|
|
|
mixEnvelop.setMessage("您所添加的家属的名称有误,无法添加");
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
}
|
|
|
if(!Pat_name.equalsIgnoreCase(familyName)){
|
|
|
familyId= jsonObject.getString("brid");
|
|
|
birth= jsonObject.getString("csny");
|
|
|
long lt = new Long(birth);
|
|
|
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
birth = sf.format(lt);
|
|
|
System.out.println("眼科转换后的csny"+birth);
|
|
|
}else {
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("您所添加的家属的名称有误,无法添加");
|
|
|
mixEnvelop.setMessage("您所添加的家属无就诊记录无法添加");
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
result.setFamilyRelation(dictId);
|
|
|
result.setFamilyRelationName(dictName);
|
|
|
result.setIsDel(1);
|
|
|
result.setPatient(patientId);
|
|
|
result.setCardNo(idCard);
|
|
|
result.setCardType(cardType);
|
|
|
//保存到base_patient表中
|
|
|
basePatientDO.setMobile(phoneNum);
|
|
|
if(null!=jsonObject.get("Birth_Date")){
|
|
|
String birth = jsonObject.get("Birth_Date").toString();
|
|
|
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date saveBirth = sf.parse(birth);
|
|
|
basePatientDO.setBirthday(saveBirth);
|
|
|
}
|
|
|
basePatientDO.setName(familyName);
|
|
|
basePatientDO.setIdcard(idCard);
|
|
|
basePatientDO.setRegister("0");
|
|
|
basePatientDO.setDel("1");
|
|
|
if(null!=jsonObject.get("Sex")){
|
|
|
basePatientDO.setSex(Integer.parseInt(jsonObject.get("Sex").toString()));
|
|
|
}
|
|
|
BasePatientDO sucessPatient= basePatientDao.save(basePatientDO);
|
|
|
String patientNewId= "";
|
|
|
if (sucessPatient!=null){
|
|
|
patientNewId=sucessPatient.getId();
|
|
|
}
|
|
|
result.setFamilyMember(patientNewId);
|
|
|
wlyyPatientFamilyMemberDao.save(result);
|
|
|
patientMappingDO.setIdcard(idCard);
|
|
|
patientMappingDO.setSource("1");
|
|
|
patientMappingDO.setPatientName(familyName);
|
|
|
patientMappingDO.setMappingCode(familyId);
|
|
|
patientMappingDO.setPatient(patientNewId);
|
|
|
patientMappingDO.setCreateTime(new Date());
|
|
|
patientMappingDao.save(patientMappingDO);
|
|
|
resultMap.put("patientId",patientId);
|
|
|
resultMap.put("familyMember",patientNewId);
|
|
|
resultMap.put("idCard",idCard);
|
|
|
resultMap.put("phoneNum",phoneNum);
|
|
|
resultMap.put("relationName",dictName);
|
|
|
resultMap.put("name",familyName);
|
|
|
resultMap.put("cardType",cardType);
|
|
|
List<Map<String,Object>> resultList = new ArrayList();
|
|
|
resultList.add(resultMap);
|
|
|
mixEnvelop.setStatus(200);
|
|
|
mixEnvelop.setMessage("添加成功");
|
|
|
mixEnvelop.setDetailModelList(resultList);
|
|
|
}else {
|
|
|
|
|
|
}
|
|
|
}else if ("xm_zsyy_wx".equalsIgnoreCase(wxId)) {
|
|
|
jsonArray = entranceService.BS10008(idCard, "", "", "", "", "", demo);
|
|
|
if (jsonArray != null && jsonArray.size() > 0) {
|
|
|
net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(jsonArray.get(0).toString());
|
|
|
//如果病人id为空则没有就诊记录
|
|
|
if (null != jsonObject.get("Patient_Id")) {
|
|
|
familyId = jsonObject.getString("Patient_Id");
|
|
|
String Pat_name = jsonObject.getString("Pat_Name");
|
|
|
if (null != jsonObject.get("Phone_Number_Business")) {
|
|
|
String Next_Of_Kin_Phone = jsonObject.get("Phone_Number_Business").toString();
|
|
|
if (!Next_Of_Kin_Phone.equalsIgnoreCase(phoneNum)) {
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("您所添加的家属的电话有误,无法添加");
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
}
|
|
|
if (!Pat_name.equalsIgnoreCase(familyName)) {
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("您所添加的家属的名称有误,无法添加");
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
if(null!=jsonObject.get("Birth_Date")){
|
|
|
birth = jsonObject.get("Birth_Date").toString();
|
|
|
}
|
|
|
if(null!=jsonObject.get("Sex")){
|
|
|
sex = Integer.parseInt(jsonObject.get("Sex").toString());
|
|
|
}
|
|
|
}else {
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("您所添加的家属无就诊记录,无法添加");
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("心脏中心暂未开放");
|
|
|
}
|
|
|
else {
|
|
|
basePatientDO.setSex(sex);
|
|
|
SimpleDateFormat sf3 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date saveBirth1 = sf3.parse(birth);
|
|
|
System.out.println("====="+saveBirth1);
|
|
|
basePatientDO.setBirthday(saveBirth1);
|
|
|
result.setFamilyRelation(dictId);
|
|
|
result.setFamilyRelationName(dictName);
|
|
|
result.setIsDel(1);
|
|
|
result.setPatient(patientId);
|
|
|
result.setCardNo(idCard);
|
|
|
result.setCardType(cardType);
|
|
|
//保存到base_patient表中
|
|
|
basePatientDO.setMobile(phoneNum);
|
|
|
|
|
|
basePatientDO.setName(familyName);
|
|
|
basePatientDO.setIdcard(idCard);
|
|
|
basePatientDO.setRegister("0");
|
|
|
basePatientDO.setDel("1");
|
|
|
|
|
|
BasePatientDO sucessPatient= basePatientDao.save(basePatientDO);
|
|
|
String patientNewId= "";
|
|
|
if (sucessPatient!=null){
|
|
|
patientNewId=sucessPatient.getId();
|
|
|
}
|
|
|
result.setFamilyMember(patientNewId);
|
|
|
wlyyPatientFamilyMemberDao.save(result);
|
|
|
patientMappingDO.setIdcard(idCard);
|
|
|
patientMappingDO.setSource("1");
|
|
|
patientMappingDO.setPatientName(familyName);
|
|
|
patientMappingDO.setMappingCode(familyId);
|
|
|
patientMappingDO.setPatient(patientNewId);
|
|
|
patientMappingDO.setCreateTime(new Date());
|
|
|
patientMappingDao.save(patientMappingDO);
|
|
|
resultMap.put("patientId",patientId);
|
|
|
resultMap.put("familyMember",patientNewId);
|
|
|
resultMap.put("idCard",idCard);
|
|
|
resultMap.put("phoneNum",phoneNum);
|
|
|
resultMap.put("relationName",dictName);
|
|
|
resultMap.put("name",familyName);
|
|
|
resultMap.put("cardType",cardType);
|
|
|
List<Map<String,Object>> resultList = new ArrayList();
|
|
|
resultList.add(resultMap);
|
|
|
mixEnvelop.setStatus(200);
|
|
|
mixEnvelop.setMessage("添加成功");
|
|
|
mixEnvelop.setDetailModelList(resultList);
|
|
|
if ("xm_ykyy_wx".equalsIgnoreCase(wxId)){
|
|
|
PatientMedicareCardDO patientMedicareCardDO = basePatientMedicareCardDao.findByCode(medicare);
|
|
|
if (null==patientMedicareCardDO){
|
|
|
patientMedicareCardDO = new PatientMedicareCardDO();
|
|
|
}
|
|
|
if (null!=patientMedicareCardDO){
|
|
|
if (!patientMedicareCardDO.getPatientCode().equalsIgnoreCase(sucessPatient.getId())){
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("请确认该就诊卡为当前家人的就诊卡");
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
}
|
|
|
patientMedicareCardDO.setCode(medicare);
|
|
|
patientMedicareCardDO.setType(medicareType);
|
|
|
patientMedicareCardDO.setPatientCode(patientNewId);
|
|
|
patientMedicareCardDO.setDel("1");
|
|
|
basePatientMedicareCardDao.save(patientMedicareCardDO);
|
|
|
}
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
mixEnvelop.setStatus(408);
|
|
|
mixEnvelop.setMessage("您所添加的家属无就诊记录,无法添加");
|
|
|
mixEnvelop.setMessage("添加失败");
|
|
|
}
|
|
|
|
|
|
|
|
|
return mixEnvelop;
|
|
|
}
|
|
|
|
|
|
//根据患者id查询关联家属
|
|
|
public List<Map<String,Object>> findFamilyByPatientId(String patientId) throws ParseException {
|
|
|
String sql = "select t.id as \"id\",t.card_type as \"cardType\", " +
|