-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from Incredible-Technologies/hospitals-doctors
Hospitals doctors
- Loading branch information
Showing
23 changed files
with
683 additions
and
3 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
backend/src/main/java/com/personal/patient/account/controllers/HospitalController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.personal.patient.account.controllers; | ||
|
||
import com.personal.patient.account.exceptions.NotFoundException; | ||
import com.personal.patient.account.models.CreatingDoctorResponse; | ||
import com.personal.patient.account.models.CreatingHospitalResponse; | ||
import com.personal.patient.account.models.CreatingServices; | ||
import com.personal.patient.account.models.CreatingSpecialization; | ||
import com.personal.patient.account.service.DoctorService; | ||
import com.personal.patient.account.service.HospitalService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/hospitals") | ||
public class HospitalController { | ||
|
||
@ExceptionHandler(NotFoundException.class) | ||
protected ResponseEntity<Object> handleNotFoundException(NotFoundException ex) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getMessage()); | ||
} | ||
|
||
private final HospitalService hospitalService; | ||
|
||
private final DoctorService doctorService; | ||
|
||
@PostMapping("") | ||
public ResponseEntity<?> addHospital(@RequestBody CreatingHospitalResponse creatingHospitalResponse){ | ||
return ResponseEntity.ok(hospitalService.addHospital(creatingHospitalResponse)); | ||
} | ||
|
||
@PostMapping("/doctor") | ||
public ResponseEntity<?> addDoctorToHospital(@RequestBody CreatingDoctorResponse creatingDoctorResponse){ | ||
return ResponseEntity.ok(hospitalService.addDoctorToHospital(creatingDoctorResponse, creatingDoctorResponse.getHospitalId())); | ||
} | ||
|
||
@GetMapping("") | ||
public ResponseEntity<?> allHospital(){ | ||
return ResponseEntity.ok(hospitalService.allHospitals()); | ||
} | ||
|
||
@GetMapping("/doctors/{hospitalId}") | ||
public ResponseEntity<?> allHospitalsDoctor(@PathVariable Long hospitalId){ | ||
return ResponseEntity.ok(hospitalService.allHospitalsDoctors(hospitalId)); | ||
} | ||
|
||
@PostMapping("/doctor/services") | ||
public ResponseEntity<?> addServicesToDoctor(@RequestBody CreatingServices creatingServices, | ||
@RequestParam("doctorId") Long doctorId){ | ||
return ResponseEntity.ok(doctorService.addServices(creatingServices, doctorId)); | ||
} | ||
@PostMapping("/doctor/specializations") | ||
public ResponseEntity<?> addSpecializationsToDoctor(@RequestBody CreatingSpecialization creatingSpecialization, | ||
@RequestParam("doctorId") Long doctorId){ | ||
return ResponseEntity.ok(doctorService.addSpecializations(creatingSpecialization, doctorId)); | ||
} | ||
|
||
@GetMapping("/doctors") | ||
public ResponseEntity<?> allDoctors(){ | ||
return ResponseEntity.ok(doctorService.allDoctors()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
backend/src/main/java/com/personal/patient/account/entities/Doctor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.personal.patient.account.entities; | ||
|
||
import com.personal.patient.account.models.enums.Gender; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "doctor") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Doctor { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name="id") | ||
private Long id; | ||
|
||
@Column(name="firstName") | ||
private String firstName; | ||
|
||
@Column(name="middleName") | ||
private String middleName; | ||
|
||
@Column(name="lastName") | ||
private String lastName; | ||
|
||
@Column(name="date_of_birth") | ||
@Temporal(TemporalType.DATE) | ||
@DateTimeFormat(pattern = "dd/MM/yyyy") | ||
private Date dateOfBirth; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Gender gender; | ||
|
||
@ManyToOne( | ||
cascade = CascadeType.ALL, fetch = FetchType.LAZY | ||
) | ||
@JoinColumn(name="hospital_id") | ||
private Hospital hospital; | ||
|
||
@OneToMany( | ||
cascade = CascadeType.ALL, fetch = FetchType.LAZY, | ||
mappedBy = "doctor" | ||
) | ||
private List<Specialization> specializations = new ArrayList<>(); | ||
|
||
@OneToMany( | ||
cascade = CascadeType.ALL, fetch = FetchType.LAZY, | ||
mappedBy = "doctor" | ||
) | ||
private List<Services> services = new ArrayList<>(); | ||
|
||
|
||
@Column(name="start_time") | ||
@Temporal(TemporalType.TIME) | ||
private Date startTime; | ||
|
||
@Column(name="end_time") | ||
@Temporal(TemporalType.TIME) | ||
private Date endTime; | ||
|
||
@Override | ||
public String toString() { | ||
return "Doctor"; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
backend/src/main/java/com/personal/patient/account/entities/Hospital.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.personal.patient.account.entities; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "hospital") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Hospital { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name="id") | ||
private Long id; | ||
|
||
@Column(name="name") | ||
private String name; | ||
|
||
@Column(name="address") | ||
private String address; | ||
|
||
@OneToMany( | ||
cascade = CascadeType.ALL, fetch = FetchType.EAGER, | ||
mappedBy = "hospital" | ||
) | ||
private List<Doctor> doctors = new ArrayList<>(); | ||
|
||
@Column(name="opening_time") | ||
@Temporal(TemporalType.TIME) | ||
private Date openingTime; | ||
|
||
@Column(name="closing_time") | ||
@Temporal(TemporalType.TIME) | ||
private Date closingTime; | ||
|
||
@Override | ||
public String toString() { | ||
return "Hospital"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
backend/src/main/java/com/personal/patient/account/entities/Services.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.personal.patient.account.entities; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "services") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Services { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name="id") | ||
private Long id; | ||
|
||
@Column(name="name") | ||
private String name; | ||
|
||
@ManyToOne( | ||
cascade = CascadeType.ALL, fetch = FetchType.LAZY | ||
) | ||
@JoinColumn(name="doctor_id") | ||
private Doctor doctor; | ||
|
||
@Column(name = "duration_in_minutes") | ||
private Integer duration; | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/personal/patient/account/entities/Specialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.personal.patient.account.entities; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "specialization") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Specialization { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name="id") | ||
private Long id; | ||
|
||
@Column(name="name") | ||
private String name; | ||
|
||
@ManyToOne( | ||
cascade = CascadeType.ALL, fetch = FetchType.LAZY | ||
) | ||
@JoinColumn(name="doctor_id") | ||
private Doctor doctor; | ||
} |
71 changes: 71 additions & 0 deletions
71
backend/src/main/java/com/personal/patient/account/models/CreatingDoctorRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.personal.patient.account.models; | ||
|
||
import com.personal.patient.account.entities.Doctor; | ||
import com.personal.patient.account.entities.Services; | ||
import com.personal.patient.account.entities.Specialization; | ||
import com.personal.patient.account.models.enums.Gender; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class CreatingDoctorRequest { | ||
private Long id; | ||
|
||
private String firstName; | ||
|
||
private String middleName; | ||
|
||
private String lastName; | ||
|
||
private String dateOfBirth; | ||
|
||
private Gender gender; | ||
|
||
private Long hospitalId; | ||
|
||
private List<CreatingSpecialization> specializations; | ||
|
||
private List<CreatingServices> services; | ||
|
||
private String startTime; | ||
|
||
private String endTime; | ||
|
||
public CreatingDoctorRequest(Doctor doctor){ | ||
this.id = doctor.getId(); | ||
this.firstName = doctor.getFirstName(); | ||
this.middleName = doctor.getMiddleName(); | ||
this.lastName = doctor.getLastName(); | ||
this.lastName = doctor.getLastName(); | ||
this.dateOfBirth = parseDateToString(doctor.getDateOfBirth()); | ||
this.gender = doctor.getGender(); | ||
this.hospitalId = doctor.getHospital().getId(); | ||
this.services = doctor.getServices().stream().map(CreatingServices::new).collect(Collectors.toList()); | ||
this.specializations = doctor.getSpecializations().stream().map(CreatingSpecialization::new).collect(Collectors.toList()); | ||
this.startTime = convertTimeToString(doctor.getStartTime().getTime()); | ||
this.endTime = convertTimeToString(doctor.getEndTime().getTime()); | ||
} | ||
public String convertTimeToString(long timeInMillis) { | ||
Instant instant = Instant.ofEpochMilli(timeInMillis); | ||
LocalTime localTime = LocalDateTime.ofInstant(instant, ZoneOffset.ofHours(3)).toLocalTime(); | ||
|
||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); | ||
return localTime.format(formatter); | ||
} | ||
public String parseDateToString(Date date){ | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
return dateFormat.format(date); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
backend/src/main/java/com/personal/patient/account/models/CreatingDoctorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.personal.patient.account.models; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CreatingDoctorResponse { | ||
private String firstName; | ||
|
||
private String middleName; | ||
|
||
private String lastName; | ||
|
||
private String dateOfBirth; | ||
|
||
private String gender; | ||
|
||
private Long hospitalId; | ||
|
||
private List<CreatingSpecialization> specializations; | ||
|
||
private List<CreatingServices> services; | ||
|
||
private String startTime; | ||
|
||
private String endTime; | ||
} |
Oops, something went wrong.