Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAH 2962 | SMS functionality of appointment booking and reminder moved to backend #117

Merged
merged 46 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5640079
BAH-2181 | added sms reminder for appointments
atishbeehyv123 May 22, 2023
8407919
[Rahul] | Fix. teleconsultation-api Version Upgrade
rahu1ramesh Jun 5, 2023
c76b466
BAH-2181 | ConnectionDetails refratored with null check
atishbeehyv123 Jun 5, 2023
bfaf187
BAH-2181 | refractored patientid and clinicName
atishbeehyv123 Jun 8, 2023
12a517d
BAH-2181 | Refractored the process of fetching Clinic name
atishbeehyv123 Jun 13, 2023
0c641e9
BAH-2181 | Moving appointment booking sms to backend
atishbeehyv123 Jun 30, 2023
29857ba
refractored user and template key
atishbeehyv123 Jun 30, 2023
63d0d6f
sms uri to be fetched from global properties now
atishbeehyv123 Jun 30, 2023
a31cef2
refractored the code acc to comments
atishbeehyv123 Jul 3, 2023
4395f39
teleconsultation-api version changed because build failed
atishbeehyv123 Jul 3, 2023
d8900aa
refractored clinic to facility and used sms-user
atishbeehyv123 Jul 4, 2023
aee3b64
refractored code
atishbeehyv123 Jul 4, 2023
1246c0a
refractored code
atishbeehyv123 Jul 4, 2023
4c379be
added tests because of build failure with less coverage
atishbeehyv123 Jul 6, 2023
d88975b
added tests because of build failure with less coverage
atishbeehyv123 Jul 7, 2023
09bc9f7
decreased minimum required branch coverage ratio
atishbeehyv123 Jul 7, 2023
6718e62
Merge remote-tracking branch 'origin/master' into BAH-2181
atishbeehyv123 Jul 7, 2023
e5ee037
Merge remote-tracking branch 'origin/BAH-2181' into BAH-2962
atishbeehyv123 Jul 7, 2023
bd89818
Refractored test for SMSServiceTest
atishbeehyv123 Jul 7, 2023
a8e6d06
Refractored test for SMSServiceTest
atishbeehyv123 Jul 7, 2023
ade2221
Merge remote-tracking branch 'origin/BAH-2962' into BAH-2962
atishbeehyv123 Jul 7, 2023
0f6a3c6
BAH-2962 | refractored sms api to be different api altogether for asy…
atishbeehyv123 Jul 27, 2023
2b8f041
BAH-2962 | used single line imports
atishbeehyv123 Aug 1, 2023
d06a6e3
Added required privileges condition check for appointments sms
atishbeehyv123 Aug 1, 2023
43ee6c8
Added required privileges condition check for appointments sms.
atishbeehyv123 Aug 1, 2023
dfb9347
Merge remote-tracking branch 'origin/BAH-2962' into BAH-2962
atishbeehyv123 Aug 1, 2023
7762a23
Changed condition of privilege for reminder
atishbeehyv123 Aug 9, 2023
7ebe69c
Refactored token sending process
atishbeehyv123 Aug 9, 2023
b19d36e
Removed usage of appointments module to send sms now working as part …
anubhavBeehyv Sep 13, 2023
52d572f
Merge remote-tracking branch 'origin/master' into BAH-2962
anubhavBeehyv Sep 14, 2023
9cbf697
Merge remote-tracking branch 'origin/master' into BAH-2962
anubhavBeehyv Sep 19, 2023
efc4a7e
Event Publisher moved to specific modules.
anubhavBeehyv Sep 28, 2023
cd829d4
Event Publisher moved to specific modules.
anubhavBeehyv Sep 28, 2023
fcc423b
Event publisher now added in appointments module itself.
anubhavBeehyv Sep 29, 2023
ac2b2f3
Removed bahmni-commons dependency
anubhavBeehyv Oct 4, 2023
ede9471
Added communications-module dependency as aware_of.
anubhavBeehyv Oct 4, 2023
86bfd69
Update PrivilegeConstants.java
anubhavBeehyv Oct 5, 2023
d6f376b
Changes to resolve git comments
anubhavBeehyv Oct 5, 2023
551a8f0
Merge remote-tracking branch 'origin/BAH-2962' into BAH-2962
anubhavBeehyv Oct 5, 2023
ae5683c
Changes to resolve git comments
anubhavBeehyv Oct 5, 2023
ce8c9a0
Merge remote-tracking branch 'origin/master' into BAH-2962
anubhavBeehyv Oct 12, 2023
5edc04c
Update AppointmentArgumentsMapperImpl.java
anubhavBeehyv Oct 12, 2023
d608863
Update AppointmentArgumentsMapperImpl.java
anubhavBeehyv Oct 12, 2023
94114bf
Changes to reslove comments
anubhavBeehyv Oct 17, 2023
d68b46c
Merge remote-tracking branch 'origin/BAH-2962' into BAH-2962
anubhavBeehyv Oct 17, 2023
58f3d69
Removed global property clinic timings.
anubhavBeehyv Oct 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
<artifactId>web-clients</artifactId>
<version>0.94.3</version>
</dependency>
<dependency>
<groupId>org.bahmni.module</groupId>
<artifactId>communication-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class PrivilegeConstants {
public static final String RESET_APPOINTMENT_STATUS = "Reset Appointment Status";
public static final String MANAGE_APPOINTMENTS_SERVICE = "Manage Appointment Services";
public static final String VIEW_APPOINTMENTS_SERVICE = "View Appointment Services";

anubhavBeehyv marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.openmrs.module.appointments.events;

import org.openmrs.api.context.Context;
import org.openmrs.module.appointments.model.Appointment;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.UUID;

@Component
atish160384 marked this conversation as resolved.
Show resolved Hide resolved
public class AppointmentBookingEvent extends AppointmentEvent {

private Appointment appointment;

public void createAppointmentEvent(AppointmentEventType eventType, Appointment appointment) {
this.eventType = eventType;
this.appointment = appointment;
this.eventId = UUID.randomUUID().toString();
this.payloadId = appointment.getUuid();
this.publishedDateTime = LocalDateTime.now();
this.userContext= Context.getUserContext();
}

public Appointment getAppointment() {
return appointment;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.openmrs.module.appointments.events;

import org.openmrs.api.context.UserContext;
import org.openmrs.module.appointments.events.AppointmentEventType;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
atish160384 marked this conversation as resolved.
Show resolved Hide resolved
public class AppointmentEvent {
private static final long version = 1L;
public UserContext userContext;
public String eventId;
public AppointmentEventType eventType;
public String payloadId;
public LocalDateTime publishedDateTime;

public UserContext getUserContext() {
return userContext;
}
public String getEventId() {
return eventId;
}
public AppointmentEventType getEventType() {
return eventType;
}
public String getPayloadId() {
return payloadId;
}
public LocalDateTime getPublishedDateTime() {
return publishedDateTime;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.openmrs.module.appointments.events;

public enum AppointmentEventType {
BAHMNI_APPOINTMENT_CREATED("bahmni-appointment"),
BAHMNI_APPOINTMENT_UPDATED("bahmni-appointment"),
BAHMNI_RECURRING_APPOINTMENT_CREATED("bahmni-recurring-appointment"),
BAHMNI_RECURRING_APPOINTMENT_UPDATED("bahmni-recurring-appointment");

private final String topic;
AppointmentEventType(String topic) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't be mixing event with the topic here.
if any mapping needs to be done regarding which topic it must be sent to, then the listener to the spring application event (e.g. bahmni events module) - should use some mapping to identify the topic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.topic = topic;
}

public String topic() {
return topic;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.openmrs.module.appointments.events;
import org.openmrs.api.context.Context;
import org.openmrs.module.appointments.model.AppointmentRecurringPattern;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.UUID;


@Component
atish160384 marked this conversation as resolved.
Show resolved Hide resolved
public class RecurringAppointmentEvent extends AppointmentEvent {
private AppointmentRecurringPattern appointmentRecurringPattern;

public void createRecurringAppointmentEvent(AppointmentEventType eventType, AppointmentRecurringPattern appointmentRecurringPattern) {
this.eventType = eventType;
this.appointmentRecurringPattern = appointmentRecurringPattern;
this.eventId = UUID.randomUUID().toString();
this.payloadId = appointmentRecurringPattern.getAppointments().iterator().next().getUuid();
this.publishedDateTime = LocalDateTime.now();
this.userContext= Context.getUserContext();
}

public AppointmentRecurringPattern getAppointmentRecurringPattern() {
return appointmentRecurringPattern;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.openmrs.module.appointments.events.advice;

import com.google.common.collect.Sets;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openmrs.api.context.Context;
import org.openmrs.module.appointments.events.publisher.AppointmentEventPublisher;
import org.openmrs.module.appointments.model.Appointment;
import org.openmrs.module.appointments.events.AppointmentBookingEvent;
import org.openmrs.module.appointments.events.AppointmentEventType;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import static org.openmrs.module.appointments.events.AppointmentEventType.BAHMNI_APPOINTMENT_CREATED;
import static org.openmrs.module.appointments.events.AppointmentEventType.BAHMNI_APPOINTMENT_UPDATED;

public class AppointmentEventsAdvice implements AfterReturningAdvice, MethodBeforeAdvice {

private final Logger log = LogManager.getLogger(AppointmentEventsAdvice.class);
private final AppointmentEventPublisher eventPublisher;
private final ThreadLocal<Map<String,Integer>> threadLocal = new ThreadLocal<>();
private final String APPOINTMENT_ID_KEY = "appointmentId";
private final Set<String> adviceMethodNames = Sets.newHashSet("validateAndSave");
private final AppointmentBookingEvent appointmentEvent;

public AppointmentEventsAdvice() {
this.eventPublisher=Context.getRegisteredComponent("appointmentEventPublisher",AppointmentEventPublisher.class);
this.appointmentEvent = Context.getRegisteredComponent("appointmentBookingEvent", AppointmentBookingEvent.class);
}

@Override
public void afterReturning(Object returnValue, Method method, Object[] arguments, Object target) {
if (adviceMethodNames.contains(method.getName())) {
Map<String, Integer> patientInfo = threadLocal.get();
if (patientInfo != null) {
AppointmentEventType eventType = patientInfo.get(APPOINTMENT_ID_KEY) == null ? BAHMNI_APPOINTMENT_CREATED : BAHMNI_APPOINTMENT_UPDATED;
threadLocal.remove();

Appointment appointment = (Appointment) returnValue;
appointmentEvent.createAppointmentEvent(eventType, appointment);
eventPublisher.publishEvent(appointmentEvent);
log.info("Successfully published event with uuid : " + appointment.getUuid());
}
}
}
@Override
public void before(Method method, Object[] objects, Object o) {
if (adviceMethodNames.contains(method.getName())) {
Appointment appointment = ((Supplier<Appointment>) objects[0]).get();
Map<String, Integer> appointmentInfo = new HashMap<>(1);
appointmentInfo.put(APPOINTMENT_ID_KEY, appointment.getId());
threadLocal.set(appointmentInfo);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.openmrs.module.appointments.events.advice;

import com.google.common.collect.Sets;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openmrs.api.context.Context;
import org.openmrs.module.appointments.events.publisher.AppointmentEventPublisher;
import org.openmrs.module.appointments.events.AppointmentEventType;
import org.openmrs.module.appointments.model.AppointmentRecurringPattern;
import org.openmrs.module.appointments.events.RecurringAppointmentEvent;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static org.openmrs.module.appointments.events.AppointmentEventType.BAHMNI_RECURRING_APPOINTMENT_CREATED;
import static org.openmrs.module.appointments.events.AppointmentEventType.BAHMNI_RECURRING_APPOINTMENT_UPDATED;

public class RecurringAppointmentEventsAdvice implements AfterReturningAdvice, MethodBeforeAdvice {

private final Logger log = LogManager.getLogger(RecurringAppointmentEventsAdvice.class);
private final AppointmentEventPublisher eventPublisher;
private final ThreadLocal<Map<String, Integer>> threadLocal = new ThreadLocal<>();
private final String RECURRING_APPOINTMENT_ID_KEY = "recurringAppointmentId";
private final Set<String> adviceMethodNames = Sets.newHashSet("validateAndSave");
private final RecurringAppointmentEvent recurringAppointmentEvent;

public RecurringAppointmentEventsAdvice() {
this.eventPublisher = Context.getRegisteredComponent("appointmentEventPublisher", AppointmentEventPublisher.class);
this.recurringAppointmentEvent = Context.getRegisteredComponent("recurringAppointmentEvent", RecurringAppointmentEvent.class);
}

@Override
public void afterReturning(Object returnValue, Method method, Object[] arguments, Object target) {
if (adviceMethodNames.contains(method.getName())) {
Map<String, Integer> appointmentInfo = threadLocal.get();
if (appointmentInfo != null) {
AppointmentEventType eventType = appointmentInfo.get(RECURRING_APPOINTMENT_ID_KEY) == null ? BAHMNI_RECURRING_APPOINTMENT_CREATED : BAHMNI_RECURRING_APPOINTMENT_UPDATED;
threadLocal.remove();
AppointmentRecurringPattern appointmentRecurringPattern = (AppointmentRecurringPattern) returnValue;
recurringAppointmentEvent.createRecurringAppointmentEvent(eventType, appointmentRecurringPattern);
eventPublisher.publishEvent(recurringAppointmentEvent);
log.info("Successfully published event with uuid : " + recurringAppointmentEvent.getPayloadId());
}
}
}

@Override
public void before(Method method, Object[] objects, Object o) {
if (adviceMethodNames.contains(method.getName())) {
AppointmentRecurringPattern appointmentRecurringPattern = (AppointmentRecurringPattern) objects[0];
Map<String, Integer> appointmentInfo = new HashMap<>(1);
appointmentInfo.put(RECURRING_APPOINTMENT_ID_KEY, appointmentRecurringPattern.getId());
threadLocal.set(appointmentInfo);
}
}
}
Loading
Loading