|
@ -2,6 +2,7 @@ package com.yihu.jw.care.service.sign;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.care.dao.apply.PatientBedApplyDao;
|
|
|
import com.yihu.jw.care.dao.sign.*;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
@ -11,10 +12,12 @@ import com.yihu.jw.entity.base.servicePackage.ServicePackageDO;
|
|
|
import com.yihu.jw.entity.base.servicePackage.ServicePackageItemDO;
|
|
|
import com.yihu.jw.entity.base.servicePackage.ServicePackageRecordDO;
|
|
|
import com.yihu.jw.entity.base.servicePackage.ServicePackageSignRecordDO;
|
|
|
import com.yihu.jw.entity.care.apply.PatientBedApplyDo;
|
|
|
import com.yihu.jw.entity.care.archive.ArchiveDO;
|
|
|
import com.yihu.jw.entity.care.sign.CapacityAssessmentRecordDO;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.patient.service.BasePatientMedicardCardService;
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
|
import com.yihu.jw.restmodel.web.PageEnvelop;
|
|
|
import com.yihu.jw.util.common.IdCardUtil;
|
|
|
import com.yihu.jw.utils.StringUtil;
|
|
@ -66,6 +69,8 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
|
|
|
private BasePatientMedicardCardService basePatientMedicardCardService;
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
@Autowired
|
|
|
private PatientBedApplyDao bedApplyDao;
|
|
|
|
|
|
/**
|
|
|
* 查找签约机构
|
|
@ -306,7 +311,9 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
|
|
|
* @param doctorId
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public ServicePackageSignRecordDO servicePackageSign(String jsonData,String doctorId,String patientId) throws Exception{
|
|
|
public JSONObject servicePackageSign(String jsonData,String doctorId,String patientId) throws Exception{
|
|
|
BasePatientDO patientDO = patientDao.findById(patientId);
|
|
|
JSONObject result = new JSONObject();
|
|
|
ServicePackageSignRecordDO signRecordDO = objectMapper.readValue(jsonData, ServicePackageSignRecordDO.class);
|
|
|
signRecordDO.setPatient(patientId);
|
|
|
List<ServicePackageRecordDO> recordDOList = signRecordDO.getRecordDOList();
|
|
@ -334,12 +341,23 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
|
|
|
archiveDao.save(archiveDO);
|
|
|
}
|
|
|
}else{
|
|
|
ArchiveDO archiveDO = archiveDao.findByPatientAndDoctorCode(patientId,doctorId);
|
|
|
if(archiveDO!=null){
|
|
|
archiveDO.setSignStatus(1);
|
|
|
archiveDao.save(archiveDO);
|
|
|
}
|
|
|
signId = signRecordDOs.get(0).getId();
|
|
|
List<ServicePackageRecordDO> existList = servicePackageRecordDao.findBySignId(signId);
|
|
|
idList = existList.stream().map(ServicePackageRecordDO::getServicePackageId).collect(Collectors.toList());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//服务项目 emergencyAssistance 只能签约一个
|
|
|
String sqlItem = "select item.`code`,item.name from base_service_package_item item INNER JOIN base_service_package_record pr on item.service_package_id = pr.service_package_id\n" +
|
|
|
"where pr.sign_id='"+signId+"' GROUP BY item.`code`";
|
|
|
List<Map<String,Object>> itemList = jdbcTemplate.queryForList(sqlItem);
|
|
|
Map<String,List<Map<String,Object>>> signItem = itemList.stream().collect(Collectors.groupingBy(e->e.get("code").toString()));
|
|
|
|
|
|
Iterator<ServicePackageRecordDO> iterator = recordDOList.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
ServicePackageRecordDO recordDO = iterator.next();
|
|
@ -351,12 +369,32 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
|
|
|
|
|
|
}
|
|
|
if(recordDOList.size()>0){
|
|
|
CapacityAssessmentRecordDO capacityAssessmentRecordDO = capacityAssessmentRecordService.findAssessmentByPatientId(patientId);
|
|
|
capacityAssessmentRecordDO.setServicePackageStatus(1);
|
|
|
capacityAssessmentRecordService.save(capacityAssessmentRecordDO);
|
|
|
List<String> packages = recordDOList.stream().map(ServicePackageRecordDO::getServicePackageId).collect(Collectors.toList());
|
|
|
String packagesId = packages.stream().map(String::valueOf).collect(Collectors.joining("','"));
|
|
|
sqlItem = "select item.`code`,item.name from base_service_package_item item " +
|
|
|
"where item.service_package_id in ('"+packagesId+"') GROUP BY item.`code`";
|
|
|
itemList = jdbcTemplate.queryForList(sqlItem);
|
|
|
Map<String,List<Map<String,Object>>> newItem = itemList.stream().collect(Collectors.groupingBy(e->e.get("code").toString()));
|
|
|
if (newItem.containsKey("emergencyAssistance")&&signItem.containsKey("emergencyAssistance")){
|
|
|
String message = "重复签约服务项目:"+newItem.get("emergencyAssistance").get(0).get("name").toString();
|
|
|
throw new Exception(message);
|
|
|
}
|
|
|
}
|
|
|
CapacityAssessmentRecordDO capacityAssessmentRecordDO = capacityAssessmentRecordService.findAssessmentByPatientId(patientId);
|
|
|
capacityAssessmentRecordDO.setServicePackageStatus(1);
|
|
|
capacityAssessmentRecordService.save(capacityAssessmentRecordDO);
|
|
|
servicePackageRecordDao.save(recordDOList);
|
|
|
return signRecordDO;
|
|
|
|
|
|
//修改床位生请状态为已完成
|
|
|
PatientBedApplyDo bedApplyDo = bedApplyDao.findByIdcardAndStatus(patientDO.getIdcard(),2);
|
|
|
if (bedApplyDo!=null) {
|
|
|
bedApplyDo.setStatus(0);
|
|
|
bedApplyDao.save(bedApplyDo);
|
|
|
}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg,signRecordDO);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
@ -405,7 +443,7 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
|
|
|
|
|
|
public List<Map<String,Object>> serviceItemByPackageId(String packageId){
|
|
|
String sql ="select it.code,it.name,count(it.code)count,pack.introduce,pack.type,pack.`name` from base_service_package_item it " +
|
|
|
"INNER JOIN base_service_package pack on it.service_package_id = pack.id where it.service_package_id='"+packageId+"' group by it.code ";
|
|
|
"INNER JOIN base_service_package pack on it.service_package_id = pack.id where it.service_package_id='"+packageId+"' and pack.del=1 group by it.code ";
|
|
|
List<Map<String,Object>> result = jdbcTemplate.queryForList(sql);
|
|
|
return result;
|
|
|
}
|
|
@ -415,14 +453,14 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
|
|
|
String sql="select DISTINCT pack.*,CASE WHEN pack.type=1 THEN '养老服务' WHEN pack.type=2 THEN '医疗服务'\n" +
|
|
|
"WHEN pack.type=3 THEN '安防监护' WHEN pack.type=4 THEN '慢病管理' ELSE pack.type\n" +
|
|
|
"END as 'typeName' from base_service_package_record re, base_service_package_item item,base_service_package pack \n" +
|
|
|
"where re.service_package_id = item.service_package_id and item.service_package_id = pack.id and item.code='"+serverItem+"' and re.sign_id in (\n" +
|
|
|
"where re.service_package_id = item.service_package_id and item.service_package_id = pack.id and pack.del=1 and item.code='"+serverItem+"' and re.sign_id in (\n" +
|
|
|
"select rd.id from base_service_package_sign_record rd where rd.patient='"+patient+"' and rd.status=1) ";
|
|
|
List<Map<String,Object>> resultSql = jdbcTemplate.queryForList(sql);
|
|
|
//查询服务包的服务项目
|
|
|
for (Map<String,Object> map:resultSql){
|
|
|
String packageId = map.get("id").toString();
|
|
|
sql="select DISTINCT it.code serverItem,it.name,pack.introduce,pack.type packageType,pack.`name` packageName from base_service_package_item it \n" +
|
|
|
"INNER JOIN base_service_package pack on it.service_package_id = pack.id where it.service_package_id='"+packageId+"' group by it.code";
|
|
|
"INNER JOIN base_service_package pack on it.service_package_id = pack.id where pack.del=1 and it.service_package_id='"+packageId+"' group by it.code";
|
|
|
List<Map<String,Object>> resultTmp = jdbcTemplate.queryForList(sql);
|
|
|
map.put("serverItems",resultTmp);
|
|
|
}
|
|
@ -437,13 +475,13 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
|
|
|
"CASE WHEN doc.doctor_level=1 THEN '(社区医生)' ELSE '(助老员)' END) as name,doc.photo,doc.mobile\n" +
|
|
|
"from base_service_package_item item ,base_service_package pack,base_team_member mem,base_doctor doc\n" +
|
|
|
"where item.`code`='"+serverItem+"' and item.service_package_id='"+packageId+"' and item.service_package_id = pack.id " +
|
|
|
"and item.team_code = mem.team_code and mem.doctor_code = doc.id and mem.del=1 ";
|
|
|
"and item.team_code = mem.team_code and mem.doctor_code = doc.id and mem.del=1 and pack.del=1 ";
|
|
|
List<Map<String,Object>>result = jdbcTemplate.queryForList(sql);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public Map<String,Object> getPackageDetailById(String packageId){
|
|
|
String sql="select * from base_service_package where id='"+packageId+"' ";
|
|
|
String sql="select * from base_service_package where id='"+packageId+"' and del=1 ";
|
|
|
Map<String,Object>result = jdbcTemplate.queryForMap(sql);
|
|
|
sql = "select org_code,org_name,introduce from base_service_package_item where service_package_id='"+packageId+"'\n" +
|
|
|
"GROUP BY org_code ORDER BY create_time desc ";
|