package com.lemon.lifecenter.dto;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.springframework.stereotype.Repository;

@Repository
public class PatientPHRLatestDTO {

	private int patientIdx;
	private String patientName;
	private String centerCode;	
	private String wardNumber;
	private String roomNumber;
	private Float temperature;
	private Date temperatureCreateDate;
	private Integer oxygenSaturation;
	private Date oxygenSaturationCreateDate;
	private Integer pulseRate;
	private Date pulseRateCreateDate;
	private Integer systolicBloodPressure;
	private Date systolicBloodPressureCreateDate;
	private Integer diastolicBloodPressure;
	private Date diastolicBloodPressureCreateDate;
	private Integer bloodSugar;
	private Date bloodSugarCreateDate;
	private int memoCount;
	private Date symptomLastDate;	
	private String searchText;	
	private int limit;
	private int limitMax;
	
	private boolean needCheckValue(Date targetDate) {
		boolean needCheck = true;
		Calendar todayCalendar = Calendar.getInstance();
		Calendar targetCalendar = Calendar.getInstance();
		
		try {
			todayCalendar.setTime(new Date());
			targetCalendar.setTime(targetDate);
			
			if (targetCalendar.get(Calendar.YEAR) == todayCalendar.get(Calendar.YEAR) 
					&& targetCalendar.get(Calendar.MONTH) == todayCalendar.get(Calendar.MONTH) 
					&& targetCalendar.get(Calendar.DAY_OF_MONTH) == todayCalendar.get(Calendar.DAY_OF_MONTH)
					&& targetCalendar.get(Calendar.AM_PM) == todayCalendar.get(Calendar.AM_PM)) {
				needCheck = false;
			}
		}
		catch (Exception e) {
			// 체크가 필요한 것으로 처리
		}
		
		return needCheck;
	}
	public int getPatientIdx() {
		return patientIdx;
	}
	public void setPatientIdx(int patientIdx) {
		this.patientIdx = patientIdx;
	}
	public String getCenterCode() {
		return centerCode;
	}
	public void setCenterCode(String centerCode) {
		this.centerCode = centerCode;
	}
	public String getPatientName() {
		return patientName;
	}
	public void setPatientName(String patientName) {
		this.patientName = patientName;
	}
	public String getWardNumber() {
		return wardNumber;
	}
	public void setWardNumber(String wardNumber) {
		this.wardNumber = wardNumber;
	}
	public String getRoomNumber() {
		return roomNumber;
	}
	public void setRoomNumber(String roomNumber) {
		this.roomNumber = roomNumber;
	}
	public Float getTemperature() {
		return temperature;
	}
	public void setTemperature(float temperature) {
		this.temperature = temperature;
	}
	public Date getTemperatureCreateDate() {
		return temperatureCreateDate;
	}
	public Integer getOxygenSaturation() {
		return oxygenSaturation;
	}
	public void setOxygenSaturation(int oxygenSaturation) {
		this.oxygenSaturation = oxygenSaturation;
	}
	public Date getOxygenSaturationCreateDate() {
		return oxygenSaturationCreateDate;
	}	
	public Integer getPulseRate() {
		return pulseRate;
	}
	public void setPulseRate(int pulseRate) {
		this.pulseRate = pulseRate;
	}
	public Date getPulseRateCreateDate() {
		return pulseRateCreateDate;
	}	
	public Integer getSystolicBloodPressure() {
		return systolicBloodPressure;
	}
	public void setSystolicBloodPressure(int systolicBloodPressure) {
		this.systolicBloodPressure = systolicBloodPressure;
	}
	public Date getSystolicBloodPressureCreateDate() {
		return systolicBloodPressureCreateDate;
	}	
	public Integer getDiastolicBloodPressure() {
		return diastolicBloodPressure;
	}
	public void setDiastolicBloodPressure(int diastolicBloodPressure) {
		this.diastolicBloodPressure = diastolicBloodPressure;
	}
	public Date getDiastolicBloodPressureCreateDate() {
		return diastolicBloodPressureCreateDate;
	}	
	public Integer getBloodSugar() {
		return bloodSugar;
	}
	public void setBloodSugar(int bloodSugar) {
		this.bloodSugar = bloodSugar;
	}
	public Date getBloodSugarCreateDate() {
		return bloodSugarCreateDate;
	}	
	public int getMemoCount() {
		return memoCount;
	}
	public void setMemoCount(int memoCount) {
		this.memoCount = memoCount;
	}
	public Date getSymptomLastDate() {
		return symptomLastDate;
	}
	public String getSearchText() {
		return searchText;
	}
	public void setSearchText(String searchText) {
		this.searchText = searchText;
	}
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}
	public int getLimitMax() {
		return limitMax;
	}
	public void setLimitMax(int limitMax) {
		this.limitMax = limitMax;
	}
	public String getBloodPressureDisplay() {
		String systolicBloodPressureString = "--";
		if (this.systolicBloodPressure != null) {
			systolicBloodPressureString = this.systolicBloodPressure.toString();
		}
		String diastolicBloodPressureString = "--";
		if (this.diastolicBloodPressure != null) {
			diastolicBloodPressureString = this.diastolicBloodPressure.toString();
		}
		return systolicBloodPressureString + " / " + diastolicBloodPressureString;
	}
	public boolean getNeedTemperatureCheck() {
		return needCheckValue(this.temperatureCreateDate);
	}
	public boolean getNeedBloodPressCheck() {
		return needCheckValue(this.systolicBloodPressureCreateDate) || needCheckValue(this.diastolicBloodPressureCreateDate);
	}
	public boolean getNeedOxygenSaturationCheck() {
		return needCheckValue(this.oxygenSaturationCreateDate);
	}
	public boolean getIsTemperatureWarning() {
		if (this.temperature == null) return false;
		
		return this.temperature > 37.5;
	}
	public boolean getIsBloodPressureWarning() {
		if (this.systolicBloodPressure == null || this.diastolicBloodPressure == null) return false;
		
		boolean highBP = this.systolicBloodPressure > 140 || this.diastolicBloodPressure > 90;
		boolean lowBP = this.systolicBloodPressure < 80 || this.diastolicBloodPressure < 60;
		
		return highBP || lowBP;
	}
	public boolean getIsOxygenSaturationeWarning() {
		if (this.oxygenSaturation == null) return false;
		
		return this.oxygenSaturation < 95;
	}
	public boolean getHasTodaySymptom() {
		boolean ret = false;
		Calendar todayCalendar = Calendar.getInstance();
		Calendar symptomCalendar = Calendar.getInstance();
		
		try {
			todayCalendar.setTime(new Date());
			symptomCalendar.setTime(this.symptomLastDate);
			
			if (symptomCalendar.get(Calendar.YEAR) == todayCalendar.get(Calendar.YEAR) 
					&& symptomCalendar.get(Calendar.MONTH) == todayCalendar.get(Calendar.MONTH) 
					&& symptomCalendar.get(Calendar.DAY_OF_MONTH) == todayCalendar.get(Calendar.DAY_OF_MONTH)) {
				ret = true;
			}
		}
		catch (Exception e) {
			// 없는 것으로 처리
		}
		
		return ret;
	}
}
