Skip to content

Commit

Permalink
Feature: Integrated appointment confirmation.
Browse files Browse the repository at this point in the history
  • Loading branch information
elwyncrestha committed Jul 12, 2020
1 parent 185f861 commit ebb9990
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.pemits.webcare.api.doctor.entity.Doctor;
import com.pemits.webcare.api.patient.entity.Patient;
import com.pemits.webcare.core.entity.BaseEntity;
import com.pemits.webcare.core.enums.AppointmentStatus;

/**
* @Author Mohammad Hussain
Expand Down Expand Up @@ -45,4 +46,6 @@ public class Appointment extends BaseEntity<Long> implements Serializable {
@NotEmpty(message = "Appointment time is required")
private LocalTime appointmentTime;

private AppointmentStatus status;

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Appointment save(Appointment appointment) {
.status(NotificationStatus.UNSEEN)
.from(saved.getPatient().getUser())
.to(saved.getDoctor().getUser())
.message(NOTIFY_NEW_APPOINTMENT)
.message(String.format(NOTIFY_NEW_APPOINTMENT, saved.getPatient().getUser().getName()))
.build();
notificationComponent.sendAndSaveMessage(notification);
return saved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class AppConstant {
public static final String SOCKET_PUBLISHER = "/webcare-publisher";
public static final String SOCKET_SUBSCRIBER = "/webcare-subscriber";

public static final String NOTIFY_NEW_APPOINTMENT = "You have a new appointment";
public static final String NOTIFY_NEW_APPOINTMENT = "You have a new appointment with %s";
public static final String NOTIFY_APPROVED_APPOINTMENT = "Your appointment with %s has been approved.";
public static final String NOTIFY_REJECTED_APPOINTMENT = "Your appointment with %s has been rejected.";

private AppConstant() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public final class EmailConstant {
public enum Template {
REGISTRATION_CREDENTIALS("Registration Credentials!!!"),
PATIENT_REGISTRATION("Patient Registration Credentials!!!"),
RESET_PASSWORD("Reset your password!!!");
RESET_PASSWORD("Reset your password!!!"),
APPOINTMENT_CONFIRMATION("Appointment Confirmation!!!");

private final String subject;

Expand All @@ -29,6 +30,7 @@ public String get() {
.put(Template.REGISTRATION_CREDENTIALS, "/mail/registration-credentials")
.put(Template.PATIENT_REGISTRATION, "/mail/patient-registration")
.put(Template.RESET_PASSWORD, "/mail/reset-password.html")
.put(Template.APPOINTMENT_CONFIRMATION, "/mail/appointment-confirmation.html")
.build();

private EmailConstant() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class EmailDto {
private String webUrl;
private String patientId;
private String resetToken;
private String message;

private Template template;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.pemits.webcare.core.enums;

/**
* @author Elvin Shrestha on 7/12/2020
*/
public enum AppointmentStatus {
PENDING, APPROVED, REJECTED
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
package com.pemits.webcare.web.appointment;

import static com.pemits.webcare.core.constant.AppConstant.NOTIFY_APPROVED_APPOINTMENT;
import static com.pemits.webcare.core.constant.AppConstant.NOTIFY_REJECTED_APPOINTMENT;
import static com.pemits.webcare.web.appointment.AppointmentController.URL;

import java.util.Optional;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.pemits.webcare.api.appointment.entity.Appointment;
import com.pemits.webcare.api.appointment.service.AppointmentService;
import com.pemits.webcare.api.notification.component.NotificationComponent;
import com.pemits.webcare.api.notification.entity.Notification;
import com.pemits.webcare.api.user.entity.User;
import com.pemits.webcare.api.user.service.UserService;
import com.pemits.webcare.core.constant.EmailConstant.Template;
import com.pemits.webcare.core.controller.BaseController;
import com.pemits.webcare.core.dto.EmailDto;
import com.pemits.webcare.core.dto.RestResponseDto;
import com.pemits.webcare.core.enums.AppointmentStatus;
import com.pemits.webcare.core.enums.NotificationStatus;
import com.pemits.webcare.core.service.EmailService;

/**
* @Author Mohammad Hussain
Expand All @@ -20,8 +38,61 @@
public class AppointmentController extends BaseController<Appointment, Long> {

static final String URL = "/v1/appointment";
private final AppointmentService service;
private final UserService userService;
private final NotificationComponent notificationComponent;
private final EmailService emailService;

protected AppointmentController(AppointmentService appointmentService) {
protected AppointmentController(
AppointmentService appointmentService,
UserService userService,
NotificationComponent notificationComponent,
EmailService emailService) {
super(appointmentService, log.getClass());

this.service = appointmentService;
this.userService = userService;
this.notificationComponent = notificationComponent;
this.emailService = emailService;
}

@GetMapping("/confirm")
public ResponseEntity<?> confirmAppointment(@RequestParam Long appointmentId, @RequestParam
AppointmentStatus status) {
Optional<Appointment> appointment = service.findOne(appointmentId);

if (!appointment.isPresent()) {
return new RestResponseDto().fail(HttpStatus.NOT_FOUND, Optional.of("Appointment not found"));
}

appointment.get().setStatus(status);
Appointment saved = service.save(appointment.get());

// send socket notification
User logged = userService.getAuthenticated();
String msg = null;
if (saved.getStatus().equals(AppointmentStatus.APPROVED)) {
msg = String.format(NOTIFY_APPROVED_APPOINTMENT, saved.getDoctor().getUser().getName());
} else if (saved.getStatus().equals(AppointmentStatus.REJECTED)) {
msg = String.format(NOTIFY_REJECTED_APPOINTMENT, saved.getDoctor().getUser().getName());
}
Notification notification = Notification.builder()
.status(NotificationStatus.UNSEEN)
.from(logged)
.to(saved.getPatient().getUser())
.message(msg)
.build();
notificationComponent.sendAndSaveMessage(notification);

// send email
EmailDto emailDto = EmailDto.builder()
.template(Template.APPOINTMENT_CONFIRMATION)
.to(saved.getPatient().getUser().getEmail())
.toName(saved.getPatient().getUser().getName())
.message(msg)
.build();
emailService.send(emailDto);

return new RestResponseDto().success(saved);
}
}
12 changes: 12 additions & 0 deletions pemits-web/src/main/resources/db/changelog/changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,16 @@
</createTable>
</changeSet>

<changeSet id="10-alter-appointment-add-status" author="Elvin Shrestha">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="appointment" columnName="status"/>
</not>
</preConditions>

<addColumn tableName="appointment">
<column name="status" type="INT"/>
</addColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<!DOCTYPE html>
<html xmlns:th="http:https://www.thymeleaf.org">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
</head>
<style>
.custom-para {
margin: 0;
color: #4c4c4c;
font-weight: 400;
font-size: 16px;
line-height: 1.25
}
</style>
<body>

<div
style="padding:0;margin:0 auto;width:100%!important;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">

<table align="center" bgcolor="#EDF0F3" border="0" cellpadding="0" cellspacing="0"
style="background-color:#edf0f3;table-layout:fixed" width="100%">
<tbody>
<tr>
<td align="center">
<table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0"
style="background-color:#ffffff;margin:0 auto;max-width:512px;width:inherit"
width="512">
<tbody>
<tr>
<td bgcolor="#F6F8FA"
style="background-color:#f6f8fa;padding:12px;border-bottom:1px solid #ececec">
<table border="0" cellpadding="0" cellspacing="0"
style="width:100%!important;min-width:100%!important"
width="100%">
<tbody>
<tr>
<td align="left" valign="middle"><a
style="color:#008cc9;display:inline-block;text-decoration:none">
<!--<img alt=""
border="0"
height="50"
src=""
style="outline:none;color:#ffffff;text-decoration:none"
width="150">-->
</a></td>
<td align="right" style="padding:0 0 0 10px" width="100%"><a
style="margin:0;color:#008cc9;display:inline-block;text-decoration:none">
<span
style="word-wrap:break-word;color:#4c4c4c;word-break:break-word;font-weight:400;font-size:14px;line-height:1.429"><span
th:text="${data.getTo()}"></span></span>
</a></td>
<td width="1">&nbsp;</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td style="padding:20px 24px 32px 24px">
<table border="0" cellpadding="0" cellspacing="0"
width="100%">
<tbody>
<tr>
<td style="padding-bottom:20px"><h2
style="margin:0;color:#262626;font-weight:700;font-size:20px;line-height:1.2">
Hello <span
th:text="${data.getToName()}"></span>,</h2></td>
</tr>
<tr>
<td style="padding-bottom:20px">
<p class="custom-para">
<span th:text="${data.getMessage()}"></span>
</p>
<hr>
<p class="custom-para">
Regards, <br/>
<em>The PEMITS Team</em>
</p>
<hr/>
<p class="custom-para">
Note: Please do not reply to this email, as
this is an automated email
and any email sent to
this email will not be answered.
</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table align="center" bgcolor="#EDF0F3" border="0" cellpadding="0"
cellspacing="0"
style="background-color:#edf0f3;padding:0 24px;color:#6a6c6d;text-align:center"
width="100%">
<tbody>
<tr>
<td align="center"
style="padding:16px 0 0 0;text-align:center"></td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0"
width="100%">
<tbody>
<tr>
<td align="center"
style="padding:0 0 12px 0;text-align:center"><p
style="margin:0;color:#6a6c6d;font-weight:400;font-size:12px;line-height:1.333"></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>

</body>
</html>

0 comments on commit ebb9990

Please sign in to comment.