| 
					
				 | 
			
			
				@ -15,6 +15,7 @@ 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; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -306,7 +307,8 @@ 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{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ServicePackageSignRecordDO signRecordDO = objectMapper.readValue(jsonData, ServicePackageSignRecordDO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        signRecordDO.setPatient(patientId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<ServicePackageRecordDO> recordDOList = signRecordDO.getRecordDOList(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -340,6 +342,12 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //服务项目 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 +359,26 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(recordDOList.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				               result.put(ResponseContant.resultFlag, ResponseContant.fail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				               result.put(ResponseContant.resultMsg,message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				               return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            CapacityAssessmentRecordDO capacityAssessmentRecordDO = capacityAssessmentRecordService.findAssessmentByPatientId(patientId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            capacityAssessmentRecordDO.setServicePackageStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            capacityAssessmentRecordService.save(capacityAssessmentRecordDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            servicePackageRecordDao.save(recordDOList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        servicePackageRecordDao.save(recordDOList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return signRecordDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultFlag, ResponseContant.success); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultMsg,"分配成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 |