package com.clinichelper.Entity;

import com.clinichelper.Tools.AccessForm;
import com.clinichelper.Tools.AppointmentType;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.UUID;

/**
 * Created by eva_c on 9/25/2016.
 */
@Entity
@Table(name="appointments")
public class Appointment implements Serializable{
    // Attributes
    @Id
    private String appointmentId;
    @NotNull
    private Date appointmentDate;
    @NotNull
    private Timestamp appointmentTime;
    @ManyToOne
    @NotNull
    private Patient patient;
    @Column(length = 500)
    private String appointmentDescription;
    private AccessForm appointmentAccessFrom;
    private AppointmentType appointmentType;
    @ManyToOne
    private Clinic clinic;

    // Constructors
    public Appointment(){

    }

    public Appointment(Clinic clinic, Date appointmentDate, Patient patient, String appointmentDescription){
        this.setAppointmentId(clinic.getClinicPrefix() + "-SOLICIT-" + UUID.randomUUID().toString().split("-")[0].toUpperCase());
        this.setAppointmentDate(appointmentDate);
        this.setPatient(patient);
        this.setAppointmentDescription(appointmentDescription);
        this.setAppointmentAccessFrom(AccessForm.WEB);
        this.setClinic(clinic);
        this.setAppointmentType(AppointmentType.CONSULTATION);
    }

    public Appointment(Clinic clinic, Date appointmentDate, Timestamp appointmentTime, Patient patient, String appointmentDescription, AppointmentType appointmentType){
        this.setAppointmentId(clinic.getClinicPrefix() + "-A-" + UUID.randomUUID().toString().split("-")[0].toUpperCase());
        this.setAppointmentDate(appointmentDate);
        this.setAppointmentTime(appointmentTime);
        this.setPatient(patient);
        this.setAppointmentDescription(appointmentDescription);
        this.setAppointmentAccessFrom(AccessForm.CLINIC);
        this.setClinic(clinic);
        this.setAppointmentType(appointmentType);
    }

    //Getters and Setters
    public String getAppointmentId() {
        return appointmentId;
    }

    public void setAppointmentId(String appointmentId) {
        this.appointmentId = appointmentId;
    }

    public Date getAppointmentDate() {
        return appointmentDate;
    }

    public void setAppointmentDate(Date appointmentDate) {
        this.appointmentDate = appointmentDate;
    }

    public Timestamp getAppointmentTime() {
        return appointmentTime;
    }

    public String getStringAppointmentTime(){
        Date date = new Date(appointmentTime.getTime());
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
        return sdf.format(date).substring(11,16);
    }

    public void setAppointmentTime(Timestamp appointmentTime) {
        this.appointmentTime = appointmentTime;
    }

    public Patient getPatient() {
        return patient;
    }

    public void setPatient(Patient patient) {
        this.patient = patient;
    }

    public AccessForm getAppointmentAccessFrom() {
        return appointmentAccessFrom;
    }

    public void setAppointmentAccessFrom(AccessForm appointmentAccessFrom) {
        this.appointmentAccessFrom = appointmentAccessFrom;
    }

    public String getAppointmentDescription() {
        return appointmentDescription;
    }

    public void setAppointmentDescription(String appointmentDescription) {
        this.appointmentDescription = appointmentDescription;
    }

    public Clinic getClinic() {
        return clinic;
    }

    public void setClinic(Clinic clinic) {
        this.clinic = clinic;
    }

    public AppointmentType getAppointmentType() {
        return appointmentType;
    }

    public void setAppointmentType(AppointmentType appointmentType) {
        this.appointmentType = appointmentType;
    }

    public String getSimplifiedTime()
    {

        SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
        return sdf.format(appointmentTime);
    }
}

@@ -69,16 +69,65 @@
 ssForm;%0A
+import com.clinichelper.Tools.AppointmentStatus;%0A
 import c
@@ -165,16 +165,16 @@
 ntType;%0A
-
 %0Aimport 
@@ -876,24 +876,73 @@
 ntmentType;%0A
+    private AppointmentStatus appointmentStatus;%0A
     @ManyToO
@@ -1563,16 +1563,78 @@
 ATION);%0A
+        this.setAppointmentStatus(AppointmentStatus.PENDING);%0A
     %7D%0A%0A 
@@ -2259,24 +2259,86 @@
 tmentType);%0A
+        this.setAppointmentStatus(AppointmentStatus.PENDING);%0A
     %7D%0A%0A    /
@@ -4260,24 +4260,24 @@
 (%22h:mm a%22);%0A
-
         retu
@@ -4313,11 +4313,241 @@
 );%0A    %7D
+%0A%0A    public AppointmentStatus getAppointmentStatus() %7B%0A        return appointmentStatus;%0A    %7D%0A%0A    public void setAppointmentStatus(AppointmentStatus appointmentStatus) %7B%0A        this.appointmentStatus = appointmentStatus;%0A    %7D
 %0A%7D%0A

Refactor appointment entity