Sfoglia il codice sorgente

기록일시와 현재 시간을 비교하여 조건에 맞지 않은 경우 최신데이터에 추가하거나 업데이트하지 않도록 수정

maengje 4 anni fa
parent
commit
9bab029c33

+ 2 - 1
src/main/java/com/lemon/lifecenter/controller/ClinicController.java

@@ -138,6 +138,7 @@ public class ClinicController extends LifeCenterController {
 	        	dto.setFilterList(filterList);
 	        }
 		}
+		
 		if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < 12) {
 			dto.setTimeCriterion("AM");
 		} else {
@@ -164,7 +165,7 @@ public class ClinicController extends LifeCenterController {
 		mv.addObject("searchText", searchText);
 		mv.addObject("filter", filter);
 		mv.addObject("total", total);
-    mv.addObject("config", configDto);
+		mv.addObject("config", configDto);
 //		mv.addObject("items", result);
 
 		return mv;

+ 142 - 116
src/main/java/com/lemon/lifecenter/service/PHRService.java

@@ -2,6 +2,11 @@ package com.lemon.lifecenter.service;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.temporal.ChronoField;
+import java.time.temporal.ChronoUnit;
 import java.util.Date;
 import java.util.List;
 
@@ -33,96 +38,104 @@ public class PHRService {
 	private ClinicConfigurationMapper mapperClinicConfiguration;
 	
 	public void insertPHR(PatientPHRHistoryDTO dto) {
-
+	   
+	    Date time = new Date();	  	   
 	    SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH:mm");
-	    Date time = new Date();
-	    String recordedDateString = format.format(time);
-	
-	    if (dto.getRecordedDate() == null || dto.getRecordedDate().equals("")) {
-	      dto.setRecordedDate(recordedDateString);
+	    
+	    if (dto.getRecordedDate() == null || dto.getRecordedDate().equals("")) {	    	 
+	    	dto.setRecordedDate(format.format(time));
+	    } else {	    	
+	    	try {
+				time = format.parse(dto.getRecordedDate());
+			} catch (ParseException e) {
+				e.printStackTrace();
+			}
 	    }
 	    
 		mapperHistory.insertPHRHistory(dto);
-
-		ClinicConfigurationDTO configurationDTO = new ClinicConfigurationDTO();
-		configurationDTO.setPatientIdx(dto.getPatientIdx());
-		configurationDTO = mapperClinicConfiguration.selectConfigurationWithPatient(configurationDTO);		
-		
-		PatientPHRLatestDTO phrLatestDTO = new PatientPHRLatestDTO();
-		phrLatestDTO.setPatientIdx(dto.getPatientIdx());
-		
-		Date recoredDate = new Date();
-		try {			
-			recoredDate = format.parse(dto.getRecordedDate());
-		} catch (ParseException e) {			
-			e.printStackTrace();
-		}
 		
-		switch (dto.getPhrType()) {
-			case "temperature":
-				String temperatureAlarmYN = "N";
-				if (dto.getPhrValue() >= configurationDTO.getTemperatureThreshold()) {
-					temperatureAlarmYN = "Y";
-				}
-				phrLatestDTO.setTemperature(dto.getPhrValue());
-				phrLatestDTO.setTemperatureCreateDate(recoredDate);
-				phrLatestDTO.setTemperatureAlarmYN(temperatureAlarmYN);
-				break;
-			case "oxygenSaturation":
-				String oxygenSaturationAlarmYN = "N";				
-				if (dto.getPhrValue().intValue() <= configurationDTO.getOxygenSaturationThreshold()) {
-					oxygenSaturationAlarmYN = "Y";
-				}
-				phrLatestDTO.setOxygenSaturation(dto.getPhrValue().intValue());
-				phrLatestDTO.setOxygenSaturationCreateDate(recoredDate);
-				phrLatestDTO.setOxygenSaturationAlarmYN(oxygenSaturationAlarmYN);
-				break;
-			case "pulseRate":
-				String pulseRateAlarmYN = "N";
-				if (dto.getPhrValue().intValue() <= configurationDTO.getPulseRateThresholdMin() || dto.getPhrValue().intValue() >= configurationDTO.getPulseRateThresholdMax()) {
-					pulseRateAlarmYN = "Y";
-				}
-				phrLatestDTO.setPulseRate(dto.getPhrValue().intValue());
-				phrLatestDTO.setPulseRateCreateDate(recoredDate);
-				phrLatestDTO.setPulseRateAlarmYN(pulseRateAlarmYN);
-				break;
-			case "bloodPressure":
-				phrLatestDTO.setSystolicBloodPressure(dto.getPhrValue().intValue());
-				phrLatestDTO.setSystolicBloodPressureCreateDate(recoredDate);
-				phrLatestDTO.setDiastolicBloodPressure(dto.getPhrValue2().intValue());
-				phrLatestDTO.setDiastolicBloodPressureCreateDate(recoredDate);				
-				
-				String highBloodPressureAlarmYN = "N";
-				if (dto.getPhrValue().intValue() >= configurationDTO.getSystolicBloodPressureThresholdMax() || dto.getPhrValue2().intValue() >= configurationDTO.getDiastolicBloodPressureThresholdMax()) {
-					highBloodPressureAlarmYN = "Y";
-				}
-				
-				phrLatestDTO.setHighBloodPressureAlarmYN(highBloodPressureAlarmYN);
-				
-				String lowBloodPressureAlarmYN = "N";
-				if (dto.getPhrValue().intValue() <= configurationDTO.getSystolicBloodPressureThresholdMin() || dto.getPhrValue2().intValue() <= configurationDTO.getDiastolicBloodPressureThresholdMin()) {
-					lowBloodPressureAlarmYN = "Y";
-				}
-				
-				phrLatestDTO.setLowBloodPressureAlarmYN(lowBloodPressureAlarmYN);
-				break;
-			case "bloodSugar":
-				String bloodSugarAlarmYN = "N";
-				if (dto.getPhrValue().intValue() <= configurationDTO.getBloodSugarThresholdMin() || dto.getPhrValue().intValue() >= configurationDTO.getBloodSugarThresholdMax()) {
-					bloodSugarAlarmYN = "Y";
-				}
-				phrLatestDTO.setBloodSugar(dto.getPhrValue().intValue());
-				phrLatestDTO.setBloodSugarCreateDate(recoredDate);
-				phrLatestDTO.setBloodSugarAlarmYN(bloodSugarAlarmYN);
-				break;
-		}		
-		
-		PatientPHRLatestDTO patient = mapperPHRLatest.selectPHRLatest(phrLatestDTO);
-		if (patient == null) {
-			mapperPHRLatest.insertPHRLatest(phrLatestDTO);		
-		} else {			
-			mapperPHRLatest.updatePHRLatest(phrLatestDTO);					
-		}
+		// 기록일시가 오늘보다 과거이면 최신데이터에 추가나 업데이트를 하지 않는다.
+	    LocalDate recordedDate = LocalDate.ofInstant(time.toInstant(), ZoneId.systemDefault());	    
+	    long days = ChronoUnit.DAYS.between(recordedDate, LocalDate.now());
+	    if (days == 0) {	    
+	    	// 현재가 오전이고 기록일시가 오전이거나 현재가 오후이고 기록일시가 오후이면 업데이트
+	    	 LocalDateTime now = LocalDateTime.now();
+	    	 LocalDateTime recordedDateTime = LocalDateTime.ofInstant(time.toInstant(), ZoneId.systemDefault());	    
+	    	if ((now.get(ChronoField.HOUR_OF_DAY) < 12 && recordedDateTime.get(ChronoField.HOUR_OF_DAY) < 12) || (now.get(ChronoField.HOUR_OF_DAY) >= 12 && recordedDateTime.get(ChronoField.HOUR_OF_DAY) >= 12)) { 
+	    		ClinicConfigurationDTO configurationDTO = new ClinicConfigurationDTO();
+	    		configurationDTO.setPatientIdx(dto.getPatientIdx());
+	    		configurationDTO = mapperClinicConfiguration.selectConfigurationWithPatient(configurationDTO);		
+	    		
+	    		PatientPHRLatestDTO phrLatestDTO = new PatientPHRLatestDTO();
+	    		phrLatestDTO.setPatientIdx(dto.getPatientIdx());
+	    		
+	    		switch (dto.getPhrType()) {
+	    			case "temperature":
+	    				String temperatureAlarmYN = "N";
+	    				if (dto.getPhrValue() >= configurationDTO.getTemperatureThreshold()) {
+	    					temperatureAlarmYN = "Y";
+	    				}
+	    				phrLatestDTO.setTemperature(dto.getPhrValue());
+	    				phrLatestDTO.setTemperatureCreateDate(time);
+	    				phrLatestDTO.setTemperatureAlarmYN(temperatureAlarmYN);
+	    				break;
+	    			case "oxygenSaturation":
+	    				String oxygenSaturationAlarmYN = "N";				
+	    				if (dto.getPhrValue().intValue() <= configurationDTO.getOxygenSaturationThreshold()) {
+	    					oxygenSaturationAlarmYN = "Y";
+	    				}
+	    				phrLatestDTO.setOxygenSaturation(dto.getPhrValue().intValue());
+	    				phrLatestDTO.setOxygenSaturationCreateDate(time);
+	    				phrLatestDTO.setOxygenSaturationAlarmYN(oxygenSaturationAlarmYN);
+	    				break;
+	    			case "pulseRate":
+	    				String pulseRateAlarmYN = "N";
+	    				if (dto.getPhrValue().intValue() <= configurationDTO.getPulseRateThresholdMin() || dto.getPhrValue().intValue() >= configurationDTO.getPulseRateThresholdMax()) {
+	    					pulseRateAlarmYN = "Y";
+	    				}
+	    				phrLatestDTO.setPulseRate(dto.getPhrValue().intValue());
+	    				phrLatestDTO.setPulseRateCreateDate(time);
+	    				phrLatestDTO.setPulseRateAlarmYN(pulseRateAlarmYN);
+	    				break;
+	    			case "bloodPressure":
+	    				phrLatestDTO.setSystolicBloodPressure(dto.getPhrValue().intValue());
+	    				phrLatestDTO.setSystolicBloodPressureCreateDate(time);
+	    				phrLatestDTO.setDiastolicBloodPressure(dto.getPhrValue2().intValue());
+	    				phrLatestDTO.setDiastolicBloodPressureCreateDate(time);				
+	    				
+	    				String highBloodPressureAlarmYN = "N";
+	    				if (dto.getPhrValue().intValue() >= configurationDTO.getSystolicBloodPressureThresholdMax() || dto.getPhrValue2().intValue() >= configurationDTO.getDiastolicBloodPressureThresholdMax()) {
+	    					highBloodPressureAlarmYN = "Y";
+	    				}
+	    				
+	    				phrLatestDTO.setHighBloodPressureAlarmYN(highBloodPressureAlarmYN);
+	    				
+	    				String lowBloodPressureAlarmYN = "N";
+	    				if (dto.getPhrValue().intValue() <= configurationDTO.getSystolicBloodPressureThresholdMin() || dto.getPhrValue2().intValue() <= configurationDTO.getDiastolicBloodPressureThresholdMin()) {
+	    					lowBloodPressureAlarmYN = "Y";
+	    				}
+	    				
+	    				phrLatestDTO.setLowBloodPressureAlarmYN(lowBloodPressureAlarmYN);
+	    				break;
+	    			case "bloodSugar":
+	    				String bloodSugarAlarmYN = "N";
+	    				if (dto.getPhrValue().intValue() <= configurationDTO.getBloodSugarThresholdMin() || dto.getPhrValue().intValue() >= configurationDTO.getBloodSugarThresholdMax()) {
+	    					bloodSugarAlarmYN = "Y";
+	    				}
+	    				phrLatestDTO.setBloodSugar(dto.getPhrValue().intValue());
+	    				phrLatestDTO.setBloodSugarCreateDate(time);
+	    				phrLatestDTO.setBloodSugarAlarmYN(bloodSugarAlarmYN);
+	    				break;
+	    		}		
+	    		
+	    		PatientPHRLatestDTO patient = mapperPHRLatest.selectPHRLatest(phrLatestDTO);
+	    		if (patient == null) {
+	    			mapperPHRLatest.insertPHRLatest(phrLatestDTO);		
+	    		} else {			
+	    			mapperPHRLatest.updatePHRLatest(phrLatestDTO);					
+	    		}
+	    	}
+	    }		
 	}
 	
 	public int selectPHRHistoryCount(PatientPHRHistoryDTO dto) {
@@ -130,36 +143,38 @@ public class PHRService {
     }
     
     public List<PatientPHRHistoryDTO> selectPHRHistoryList(PatientPHRHistoryDTO dto) {
-      // 해당 환자가 속해 있는 센터의 설정 정보 가져오기
-		  ClinicConfigurationDTO configDto = new ClinicConfigurationDTO();
-		  configDto.setPatientIdx(dto.getPatientIdx());
-		  configDto = mapperClinicConfiguration.selectConfigurationWithPatient(configDto);
+    	
+    	ClinicConfigurationDTO configDto = new ClinicConfigurationDTO();
+    	configDto.setPatientIdx(dto.getPatientIdx());  
+    	configDto = mapperClinicConfiguration.selectConfigurationWithPatient(configDto);
 
-      List<PatientPHRHistoryDTO> phrList = mapperHistory.selectPHRHistoryList(dto);
-      for (PatientPHRHistoryDTO phrData: phrList) {
-        if (phrData.getPhrType().equals("temperature")) {
-          phrData.setIsWarning(phrData.getPhrValue() != null && (phrData.getPhrValue() >= configDto.getTemperatureThreshold()));
-        }
-        else if (phrData.getPhrType().equals("bloodPressure")) {
-          boolean systolicBP = phrData.getPhrValue() != null && (phrData.getPhrValue() <= configDto.getSystolicBloodPressureThresholdMin() || phrData.getPhrValue() >= configDto.getSystolicBloodPressureThresholdMax());
-          boolean diastolicBP = phrData.getPhrValue2() != null && (phrData.getPhrValue2() <= configDto.getDiastolicBloodPressureThresholdMin() || phrData.getPhrValue2() >= configDto.getDiastolicBloodPressureThresholdMax());
-          phrData.setIsWarning(systolicBP || diastolicBP);
-        }
-        else if (phrData.getPhrType().equals("pulseRate")) {
-          phrData.setIsWarning(phrData.getPhrValue() != null && (phrData.getPhrValue() <= configDto.getPulseRateThresholdMin() || phrData.getPhrValue() >= configDto.getPulseRateThresholdMax()));
-        }
-        else if (phrData.getPhrType().equals("oxygenSaturation")) {
-          phrData.setIsWarning(phrData.getPhrValue() != null && (phrData.getPhrValue() <= configDto.getOxygenSaturationThreshold()));
-        }
-        else if (phrData.getPhrType().equals("bloodSugar")) {
-          phrData.setIsWarning(phrData.getPhrValue() != null && (phrData.getPhrValue() <= configDto.getBloodSugarThresholdMin() || phrData.getPhrValue() >= configDto.getBloodSugarThresholdMax()));
-        }
-      }
-      return phrList;
+    	List<PatientPHRHistoryDTO> phrList = mapperHistory.selectPHRHistoryList(dto);
+    	for (PatientPHRHistoryDTO phrData: phrList) {
+    		if (phrData.getPhrType().equals("temperature")) {
+    			phrData.setIsWarning(phrData.getPhrValue() != null && (phrData.getPhrValue() >= configDto.getTemperatureThreshold()));
+    		}
+    		else if (phrData.getPhrType().equals("bloodPressure")) {
+    			boolean systolicBP = phrData.getPhrValue() != null && (phrData.getPhrValue() <= configDto.getSystolicBloodPressureThresholdMin() || phrData.getPhrValue() >= configDto.getSystolicBloodPressureThresholdMax());
+    			boolean diastolicBP = phrData.getPhrValue2() != null && (phrData.getPhrValue2() <= configDto.getDiastolicBloodPressureThresholdMin() || phrData.getPhrValue2() >= configDto.getDiastolicBloodPressureThresholdMax());
+    			phrData.setIsWarning(systolicBP || diastolicBP);
+    		}
+    		else if (phrData.getPhrType().equals("pulseRate")) {
+    			phrData.setIsWarning(phrData.getPhrValue() != null && (phrData.getPhrValue() <= configDto.getPulseRateThresholdMin() || phrData.getPhrValue() >= configDto.getPulseRateThresholdMax()));
+    		}
+    		else if (phrData.getPhrType().equals("oxygenSaturation")) {
+    			phrData.setIsWarning(phrData.getPhrValue() != null && (phrData.getPhrValue() <= configDto.getOxygenSaturationThreshold()));
+    		}
+    		else if (phrData.getPhrType().equals("bloodSugar")) {
+    			phrData.setIsWarning(phrData.getPhrValue() != null && (phrData.getPhrValue() <= configDto.getBloodSugarThresholdMin() || phrData.getPhrValue() >= configDto.getBloodSugarThresholdMax()));
+    		}
+    	}
+      
+		return phrList;
     }
     
     public void insertSymptom(PatientSymptomSimDTO dto) {
     	mapperSymptom.insertSymptom(dto);
+    	
     	PatientPHRLatestDTO phrLatestDTO = new PatientPHRLatestDTO();
 		phrLatestDTO.setPatientIdx(dto.getPatientIdx());
 		phrLatestDTO.setSymptomYN("Y");
@@ -178,12 +193,23 @@ public class PHRService {
 	    	phrLatestDTO.setSymptomCreateDate(time);
 	    }
 		
-		PatientPHRLatestDTO patient = mapperPHRLatest.selectPHRLatest(phrLatestDTO);
-		if (patient == null) {
-			mapperPHRLatest.insertPHRLatest(phrLatestDTO);		
-		} else {			
-			mapperPHRLatest.updatePHRLatest(phrLatestDTO);					
-		}
+	    // 기록일시가 오늘보다 과거이면 최신데이터에 추가나 업데이트를 하지 않는다.	  
+	    LocalDate recordedDate = LocalDate.ofInstant(time.toInstant(), ZoneId.systemDefault());	    
+	    long days = ChronoUnit.DAYS.between(recordedDate, LocalDate.now());
+	    if (days == 0) {	    
+	    	// 현재가 오전이고 기록일시가 오전이거나 현재가 오후이고 기록일시가 오후이면 업데이트
+	    	 LocalDateTime now = LocalDateTime.now();
+	    	 LocalDateTime recordedDateTime = LocalDateTime.ofInstant(time.toInstant(), ZoneId.systemDefault());	    
+	    	if ((now.get(ChronoField.HOUR_OF_DAY) < 12 && recordedDateTime.get(ChronoField.HOUR_OF_DAY) < 12) || (now.get(ChronoField.HOUR_OF_DAY) >= 12 && recordedDateTime.get(ChronoField.HOUR_OF_DAY) >= 12)) { 
+	    		PatientPHRLatestDTO patient = mapperPHRLatest.selectPHRLatest(phrLatestDTO);
+				if (patient == null) {
+					mapperPHRLatest.insertPHRLatest(phrLatestDTO);		
+				} else {			
+					
+					mapperPHRLatest.updatePHRLatest(phrLatestDTO);					
+				}
+	    	}
+	    }
     }
     
     public int selectSymptomCount(PatientSymptomSimDTO dto) {