package com.lemon.lifecenter.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.lemon.lifecenter.dto.ClinicConfigurationDTO; import com.lemon.lifecenter.dto.PatientPHRHistoryDTO; import com.lemon.lifecenter.dto.PatientPHRLatestDTO; import com.lemon.lifecenter.dto.PatientSymptomSimDTO; import com.lemon.lifecenter.mapper.ClinicConfigurationMapper; import com.lemon.lifecenter.mapper.PatientPHRHistoryMapper; import com.lemon.lifecenter.mapper.PatientPHRLatestMapper; import com.lemon.lifecenter.mapper.PatientSymptomSimMapper; @Service public class PHRService { @Autowired private PatientPHRHistoryMapper mapperHistory; @Autowired private PatientPHRLatestMapper mapperPHRLatest; @Autowired private PatientSymptomSimMapper mapperSymptom; @Autowired private ClinicConfigurationMapper mapperClinicConfiguration; public void insertPHR(PatientPHRHistoryDTO dto) { mapperHistory.insertPHRHistory(dto); // 해당 환자가 속해 있는 센터의 설정 정보 가져오기 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.getTemparatureThreshold()) { temperatureAlarmYN = "Y"; } phrLatestDTO.setTemperature(dto.getPhrValue()); phrLatestDTO.setTemperatureAlarmYN(temperatureAlarmYN); break; case "oxygenSaturation": String oxygenSaturationAlarmYN = "N"; if (dto.getPhrValue().intValue() <= configurationDTO.getOxygenSaturationThreshold()) { oxygenSaturationAlarmYN = "Y"; } phrLatestDTO.setOxygenSaturation(dto.getPhrValue().intValue()); 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.setPulseRateAlarmYN(pulseRateAlarmYN); break; case "bloodPressure": String systolicBloodPressureAlarmYN = "N"; if (dto.getPhrValue().intValue() <= configurationDTO.getSystolicBloodPressureThresholdMin() || dto.getPhrValue().intValue() >= configurationDTO.getSystolicBloodPressureThresholdMax()) { systolicBloodPressureAlarmYN = "Y"; } phrLatestDTO.setSystolicBloodPressure(dto.getPhrValue().intValue()); phrLatestDTO.setSystolicBloodPressureAlarmYN(systolicBloodPressureAlarmYN); String diastolicBloodPressureAlarmY = "N"; if (dto.getPhrValue().intValue() <= configurationDTO.getDiastolicBloodPressureThresholdMin() || dto.getPhrValue().intValue() >= configurationDTO.getDiastolicBloodPressureThresholdMax()) { diastolicBloodPressureAlarmY = "Y"; } phrLatestDTO.setDiastolicBloodPressure(dto.getPhrValue2().intValue()); phrLatestDTO.setDiastolicBloodPressureAlarmYN(diastolicBloodPressureAlarmY); break; case "bloodSugar": String bloodSugarAlarmYN = "N"; if (dto.getPhrValue().intValue() <= configurationDTO.getBloodSugarThresholdMin() || dto.getPhrValue().intValue() >= configurationDTO.getBloodSugerThresholdMax()) { bloodSugarAlarmYN = "Y"; } phrLatestDTO.setBloodSugar(dto.getPhrValue().intValue()); phrLatestDTO.setBloodSugarAlarmYN(bloodSugarAlarmYN); break; } mapperPHRLatest.insertPHRLatest(phrLatestDTO); } public int selectPHRHistoryCount(PatientPHRHistoryDTO dto) { return mapperHistory.selectPHRHistoryCount(dto); } public List selectPHRHistoryList(PatientPHRHistoryDTO dto) { return mapperHistory.selectPHRHistoryList(dto); } public void insertSymptom(PatientSymptomSimDTO dto) { mapperSymptom.insertSymptom(dto); PatientPHRLatestDTO phrLatestDTO = new PatientPHRLatestDTO(); phrLatestDTO.setPatientIdx(dto.getPatientIdx()); phrLatestDTO.setSymptomYN("Y"); mapperPHRLatest.insertPHRLatest(phrLatestDTO); } public int selectSymptomCount(PatientSymptomSimDTO dto) { return mapperSymptom.selectSymptomCount(dto); } public List selectSymptomList(PatientSymptomSimDTO dto) { return mapperSymptom.selectSymptomList(dto); } }