-
Notifications
You must be signed in to change notification settings - Fork 1
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 #27 from elwyncrestha/appointment
appointment backend
- Loading branch information
Showing
20 changed files
with
677 additions
and
12 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
pemits-api/src/main/java/com/pemits/webcare/api/appointment/entity/Appointment.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,48 @@ | ||
package com.pemits.webcare.api.appointment.entity; | ||
|
||
import java.io.Serializable; | ||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import javax.persistence.Entity; | ||
import javax.persistence.OneToOne; | ||
import javax.validation.constraints.NotEmpty; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
import com.pemits.webcare.api.department.entity.Department; | ||
import com.pemits.webcare.api.doctor.entity.Doctor; | ||
import com.pemits.webcare.api.patient.entity.Patient; | ||
import com.pemits.webcare.core.entity.BaseEntity; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/5/2020 | ||
*/ | ||
@Entity | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = true) | ||
public class Appointment extends BaseEntity<Long> implements Serializable { | ||
|
||
@OneToOne | ||
private Patient patient; | ||
|
||
@NotEmpty(message = "Department is required") | ||
@OneToOne | ||
private Department department; | ||
|
||
@NotEmpty(message = "Doctor is required") | ||
@OneToOne | ||
private Doctor doctor; | ||
|
||
@NotEmpty(message = "Appointment date is required") | ||
private LocalDate appointmentDate; | ||
|
||
@NotEmpty(message = "Appointment time is required") | ||
private LocalTime appointmentTime; | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...pi/src/main/java/com/pemits/webcare/api/appointment/repository/AppointmentRepository.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,15 @@ | ||
package com.pemits.webcare.api.appointment.repository; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.pemits.webcare.api.appointment.entity.Appointment; | ||
import com.pemits.webcare.core.repository.BaseRepository; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/5/2020 | ||
*/ | ||
@Repository | ||
public interface AppointmentRepository extends BaseRepository<Appointment, Long> { | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...api/src/main/java/com/pemits/webcare/api/appointment/repository/spec/AppointmentSpec.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,37 @@ | ||
package com.pemits.webcare.api.appointment.repository.spec; | ||
|
||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Predicate; | ||
import javax.persistence.criteria.Root; | ||
|
||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import com.pemits.webcare.api.appointment.entity.Appointment; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/5/2020 | ||
*/ | ||
public class AppointmentSpec implements Specification<Appointment> { | ||
|
||
private static final String FILTER_BY_NAME = "name"; | ||
|
||
private final String property; | ||
private final String value; | ||
|
||
public AppointmentSpec(String property, String value) { | ||
this.property = property; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Predicate toPredicate(Root<Appointment> root, CriteriaQuery<?> query, | ||
CriteriaBuilder criteriaBuilder) { | ||
switch (property) { | ||
case FILTER_BY_NAME: | ||
return criteriaBuilder.like(root.get(FILTER_BY_NAME), "%" + value + "%"); | ||
} | ||
return null; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../main/java/com/pemits/webcare/api/appointment/repository/spec/AppointmentSpecBuilder.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,24 @@ | ||
package com.pemits.webcare.api.appointment.repository.spec; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import com.pemits.webcare.api.appointment.entity.Appointment; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/5/2020 | ||
*/ | ||
public class AppointmentSpecBuilder extends BaseSpecBuilder<Appointment> { | ||
|
||
public AppointmentSpecBuilder(Map<String, String> params) { | ||
super(params); | ||
} | ||
|
||
@Override | ||
protected Specification<Appointment> getSpecification(String property, String filterValue) { | ||
return new AppointmentSpec(property, filterValue); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
pemits-api/src/main/java/com/pemits/webcare/api/appointment/service/AppointmentService.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,12 @@ | ||
package com.pemits.webcare.api.appointment.service; | ||
|
||
import com.pemits.webcare.api.appointment.entity.Appointment; | ||
import com.pemits.webcare.core.service.BaseService; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/5/2020 | ||
*/ | ||
public interface AppointmentService extends BaseService<Appointment, Long> { | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...-api/src/main/java/com/pemits/webcare/api/appointment/service/AppointmentServiceImpl.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,61 @@ | ||
package com.pemits.webcare.api.appointment.service; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.pemits.webcare.api.appointment.entity.Appointment; | ||
import com.pemits.webcare.api.appointment.repository.AppointmentRepository; | ||
import com.pemits.webcare.api.appointment.repository.spec.AppointmentSpecBuilder; | ||
import com.pemits.webcare.api.patient.entity.Patient; | ||
import com.pemits.webcare.api.patient.service.PatientService; | ||
import com.pemits.webcare.api.user.entity.User; | ||
import com.pemits.webcare.api.user.service.UserService; | ||
import com.pemits.webcare.core.enums.UserType; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
import com.pemits.webcare.core.service.BaseServiceImpl; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/5/2020 | ||
*/ | ||
@Service | ||
public class AppointmentServiceImpl extends BaseServiceImpl<Appointment, Long> implements | ||
AppointmentService { | ||
|
||
private final AppointmentRepository repository; | ||
private final UserService userService; | ||
private final PatientService patientService; | ||
|
||
public AppointmentServiceImpl( | ||
AppointmentRepository repository, | ||
UserService userService, | ||
PatientService patientService) { | ||
super(repository); | ||
|
||
this.repository = repository; | ||
this.userService = userService; | ||
this.patientService = patientService; | ||
} | ||
|
||
@Override | ||
public Appointment save(Appointment appointment) { | ||
Patient patient = appointment.getPatient(); | ||
if (null == patient.getId()) { | ||
User user = patient.getUser(); | ||
user.setUserType(UserType.PATIENT); | ||
user.setUsername(String.valueOf(System.currentTimeMillis())); | ||
User savedUser = userService.save(user); | ||
Patient newPatient = patientService.findByUserId(savedUser.getId()); | ||
newPatient.setAge(patient.getAge()); | ||
Patient savedPatient = patientService.save(newPatient); | ||
appointment.setPatient(savedPatient); | ||
} | ||
return repository.save(appointment); | ||
} | ||
|
||
@Override | ||
protected BaseSpecBuilder<Appointment> getSpec(Map<String, String> filterParams) { | ||
return new AppointmentSpecBuilder(filterParams); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
pemits-api/src/main/java/com/pemits/webcare/api/patient/entity/Patient.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,37 @@ | ||
package com.pemits.webcare.api.patient.entity; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.OneToOne; | ||
import javax.validation.constraints.NotEmpty; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
import com.pemits.webcare.api.user.entity.User; | ||
import com.pemits.webcare.core.entity.AppUser; | ||
import com.pemits.webcare.core.entity.BaseEntity; | ||
import com.pemits.webcare.core.enums.UserType; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/5/2020 | ||
*/ | ||
@Entity | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = true) | ||
public class Patient extends BaseEntity<Long> implements AppUser { | ||
|
||
@OneToOne | ||
private User user; | ||
|
||
@NotEmpty(message = "Age is required") | ||
private int age; | ||
|
||
@Override | ||
public UserType getUserType() { | ||
return UserType.PATIENT; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
pemits-api/src/main/java/com/pemits/webcare/api/patient/repository/PatientRepository.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,16 @@ | ||
package com.pemits.webcare.api.patient.repository; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.pemits.webcare.api.patient.entity.Patient; | ||
import com.pemits.webcare.api.user.entity.User; | ||
import com.pemits.webcare.core.repository.BaseRepository; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/5/2020 | ||
*/ | ||
@Repository | ||
public interface PatientRepository extends BaseRepository<Patient, Long> { | ||
|
||
Patient findPatientByUser(User user); | ||
} |
30 changes: 30 additions & 0 deletions
30
pemits-api/src/main/java/com/pemits/webcare/api/patient/repository/spec/PatientSpec.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.pemits.webcare.api.patient.repository.spec; | ||
|
||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Predicate; | ||
import javax.persistence.criteria.Root; | ||
|
||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import com.pemits.webcare.api.patient.entity.Patient; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/5/2020 | ||
*/ | ||
public class PatientSpec implements Specification<Patient> { | ||
|
||
private final String property; | ||
private final String value; | ||
|
||
public PatientSpec(String property, String value) { | ||
this.property = property; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Predicate toPredicate(Root<Patient> root, CriteriaQuery<?> criteriaQuery, | ||
CriteriaBuilder criteriaBuilder) { | ||
return null; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...-api/src/main/java/com/pemits/webcare/api/patient/repository/spec/PatientSpecBuilder.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,23 @@ | ||
package com.pemits.webcare.api.patient.repository.spec; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import com.pemits.webcare.api.patient.entity.Patient; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/5/2020 | ||
*/ | ||
public class PatientSpecBuilder extends BaseSpecBuilder<Patient> { | ||
|
||
public PatientSpecBuilder(Map<String, String> params) { | ||
super(params); | ||
} | ||
|
||
@Override | ||
protected Specification<Patient> getSpecification(String property, String filterValue) { | ||
return new PatientSpec(property, filterValue); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
pemits-api/src/main/java/com/pemits/webcare/api/patient/service/PatientService.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,12 @@ | ||
package com.pemits.webcare.api.patient.service; | ||
|
||
import com.pemits.webcare.api.patient.entity.Patient; | ||
import com.pemits.webcare.core.service.BaseService; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/5/2020 | ||
*/ | ||
public interface PatientService extends BaseService<Patient, Long> { | ||
|
||
Patient findByUserId(long userId); | ||
} |
40 changes: 40 additions & 0 deletions
40
pemits-api/src/main/java/com/pemits/webcare/api/patient/service/PatientServiceImpl.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,40 @@ | ||
package com.pemits.webcare.api.patient.service; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.pemits.webcare.api.patient.entity.Patient; | ||
import com.pemits.webcare.api.patient.repository.PatientRepository; | ||
import com.pemits.webcare.api.patient.repository.spec.PatientSpecBuilder; | ||
import com.pemits.webcare.api.user.entity.User; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
import com.pemits.webcare.core.service.BaseServiceImpl; | ||
|
||
/** | ||
* @author Elvin Shrestha on 7/5/2020 | ||
*/ | ||
@Service | ||
public class PatientServiceImpl extends BaseServiceImpl<Patient, Long> implements PatientService { | ||
|
||
private final PatientRepository repository; | ||
|
||
protected PatientServiceImpl( | ||
PatientRepository repository) { | ||
super(repository); | ||
|
||
this.repository = repository; | ||
} | ||
|
||
@Override | ||
protected BaseSpecBuilder<Patient> getSpec(Map<String, String> filterParams) { | ||
return new PatientSpecBuilder(filterParams); | ||
} | ||
|
||
@Override | ||
public Patient findByUserId(long userId) { | ||
User user = new User(); | ||
user.setId(userId); | ||
return repository.findPatientByUser(user); | ||
} | ||
} |
Oops, something went wrong.