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-3479 | Backend changes for dateless appointments #145

Merged
merged 21 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
83c5799
Kavitha, Umair | A-1204370983916597| add database column and api chan…
kavitha-sundararajan May 2, 2023
3beec8d
Kavitha | A-1204361352115416 | removed invalid priority and related t…
kavitha-sundararajan May 4, 2023
c9d95cc
Backend migration to create dateless appointments (#105)
kavitha-sundararajan May 5, 2023
2576208
allow dateless appointments if status is waitlist (#108)
kavitha-sundararajan May 17, 2023
6eb60cb
Kavitha, Umair | A-1204370983916597| add database column and api chan…
kavitha-sundararajan May 2, 2023
ba0193b
Kavitha | A-1204361352115416 | removed invalid priority and related t…
kavitha-sundararajan May 4, 2023
1239ada
Backend migration to create dateless appointments (#105)
kavitha-sundararajan May 5, 2023
d464910
allow dateless appointments if status is waitlist (#108)
kavitha-sundararajan May 17, 2023
ae9cbbd
Add logic to filter DateLess Appointments
Phanindra-tw Jun 14, 2023
d088a9a
add. appointment creation date in response (#109)
Arjun-Go May 23, 2023
ceadfce
Add tests to filter DateLess Appointments
Phanindra-tw Jun 15, 2023
f931918
Update POM files
Phanindra-tw Jun 16, 2023
c121103
Fix failing Tests for Search appointments
Phanindra-tw Jun 19, 2023
63f7c4e
Kavitha | add date check and tests for waitlist appointments
kavitha-sundararajan Feb 26, 2024
4fad218
Kavitha | removed Invalid priority
kavitha-sundararajan Feb 26, 2024
02a7993
Kavitha | added missed tests from master branch
kavitha-sundararajan Feb 26, 2024
207916b
Kavitha | rename datelessAppointments to appointmentsWithoutDates
kavitha-sundararajan Feb 27, 2024
ff9dc4e
Kavitha | add default null value to date columns in appt
kavitha-sundararajan Feb 27, 2024
591b78b
Kavitha | removed status check in appointment json
kavitha-sundararajan Feb 29, 2024
a9778b7
Kavitha | removed sorting based on status
kavitha-sundararajan Mar 1, 2024
41a0262
Kavitha | removed unused imports
kavitha-sundararajan Mar 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public interface AppointmentDao {
List<Appointment> search(AppointmentSearchRequest appointmentSearchRequest);

List<Appointment> getAppointmentsForPatient(Integer patientId);

List<Appointment> getAppointmentsWithoutDates(Integer limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,19 @@ public List<Appointment> getAppointmentsForPatient(Integer patientId) {

return criteria.list();
}

@Override
public List<Appointment> getAppointmentsWithoutDates(Integer limit) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Appointment.class);
criteria.createAlias("patient", "patient");
criteria.add(Restrictions.eq("patient.voided", false));
criteria.add(Restrictions.eq("patient.personVoided", false));
criteria.add(Restrictions.isNull("startDateTime"));
criteria.add(Restrictions.isNull("endDateTime"));
criteria.addOrder(Order.asc("dateCreated"));
if (limit != null) {
criteria.setMaxResults(limit);
}
return criteria.list();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ public String getAppointmentAsJsonString(Appointment appointment) throws IOExcep
appointmentJson.put("providerUuid", providerUuid);
String locationUuid = appointment.getLocation() != null ? appointment.getLocation().getUuid() : null;
appointmentJson.put("locationUuid", locationUuid);
appointmentJson.put("startDateTime", appointment.getStartDateTime().toInstant().toString());
appointmentJson.put("endDateTime", appointment.getEndDateTime().toInstant().toString());
String startDate = appointment.getStartDateTime() == null ? null : appointment.getStartDateTime().toInstant().toString();
appointmentJson.put("startDateTime", startDate);
String endDate = appointment.getStartDateTime() == null ? null : appointment.getEndDateTime().toInstant().toString();
appointmentJson.put("endDateTime", endDate);
appointmentJson.put("appointmentKind", appointment.getAppointmentKind().name());
appointmentJson.put("appointmentNotes", appointment.getComments());
String priority = appointment.getPriority() != null ? appointment.getPriority().name() : null;
appointmentJson.put("priority", priority);
ObjectMapper mapperObj = new ObjectMapper();
return String.format("%s", mapperObj.writeValueAsString(appointmentJson));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
public class Appointment extends BaseOpenmrsData implements Serializable {
private Integer appointmentId;
private String appointmentNumber;
private Date dateCreated;
private Patient patient;
private AppointmentServiceDefinition service;
private AppointmentServiceType serviceType;
Expand All @@ -29,6 +30,7 @@ public class Appointment extends BaseOpenmrsData implements Serializable {
private Date endDateTime;
private AppointmentKind appointmentKind;
private AppointmentStatus status;
private AppointmentPriority priority;
private String comments;
private Set<AppointmentProvider> providers;
private AppointmentRecurringPattern appointmentRecurringPattern;
Expand Down Expand Up @@ -177,6 +179,14 @@ public void setStatus(AppointmentStatus status) {
this.status = status;
}

public AppointmentPriority getPriority() {
return priority;
}

public void setPriority(AppointmentPriority priority) {
this.priority = priority;
}

public String getComments() {
return comments;
}
Expand Down Expand Up @@ -230,5 +240,15 @@ public void setNotificationResults(List<NotificationResult> notificationResults)
public List<NotificationResult> getNotificationResults() {
return notificationResults;
}

@Override
public Date getDateCreated() {
return dateCreated;
}

@Override
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
}

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

public enum AppointmentPriority {
AsNeeded("AsNeeded"), Routine("Routine"), Emergency("Emergency");

private final String value;

AppointmentPriority(String value) {
this.value = value;
}
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.openmrs.module.appointments.model;

public enum AppointmentStatus {
Requested("Requested", 0), Scheduled("Scheduled", 1), CheckedIn("CheckedIn", 2), Completed("Completed", 3), Cancelled("Cancelled", 3), Missed("Missed", 3);
Requested("Requested", 0), WaitList("WaitList", 0), Scheduled("Scheduled", 1), CheckedIn("CheckedIn", 2), Completed("Completed", 3), Cancelled("Cancelled", 3), Missed("Missed", 3);

private final String value;
private final int sequence;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,9 @@ public interface AppointmentsService {
@Transactional
@Authorized({MANAGE_APPOINTMENTS, MANAGE_OWN_APPOINTMENTS})
Appointment validateAndSave(Supplier<Appointment> mapper);

@Transactional
@Authorized({VIEW_APPOINTMENTS, MANAGE_APPOINTMENTS})
List<Appointment> searchAppointmentsWithoutDates();
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openmrs.module.appointments.service.impl;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Person;
Expand Down Expand Up @@ -141,6 +142,13 @@ public Appointment validateAndSave(Supplier<Appointment> mapper) {
return appointment;
}

@Override
public List<Appointment> searchAppointmentsWithoutDates() {
String limitString = Context.getAdministrationService().getGlobalProperty("webservices.rest.maxResultsDefault");
Integer limit = StringUtils.isNotEmpty(limitString) ? Integer.parseInt(limitString) : null;
return appointmentDao.getAppointmentsWithoutDates(limit);
}

private void setupTeleconsultation(Appointment appointment) {
if (isVirtual(appointment)) {
appointment.setTeleHealthVideoLink(teleconsultationAppointmentService.generateTeleconsultationLink(appointment.getUuid()));
Expand Down Expand Up @@ -296,6 +304,12 @@ public List<Appointment> search(AppointmentSearchRequest appointmentSearchReques
if (isNull(appointmentSearchRequest.getStartDate())) {
return null;
}
if (!isNull(appointmentSearchRequest.getLimit())) {
String limit = Context.getAdministrationService().getGlobalProperty("webservices.rest.maxResultsDefault");
if (StringUtils.isNotEmpty(limit)) {
appointmentSearchRequest.setLimit(Integer.parseInt(limit));
}
}
return appointmentDao.search(appointmentSearchRequest);
}

Expand Down
6 changes: 6 additions & 0 deletions api/src/main/resources/Appointment.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<param name="useNamed">true</param>
</type>
</property>
<property name="priority" column="priority">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.openmrs.module.appointments.model.AppointmentPriority</param>
<param name="useNamed">true</param>
</type>
</property>
<property name="comments" type="java.lang.String" column="comments"/>

<property name="dateCreated" type="java.util.Date" column="date_created"/>
Expand Down
25 changes: 25 additions & 0 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,29 @@
ALTER TABLE patient_appointment_provider MODIFY voided TINYINT(1) DEFAULT 0;
</sql>
</changeSet>
<changeSet id="create-column-priority-for-appointment-202304191703" author="Kavitha, Umair">
<preConditions onFail="MARK_RAN">
<tableExists tableName="patient_appointment" />
<not>
<columnExists tableName="patient_appointment" columnName="priority" />
</not>
</preConditions>
<addColumn tableName="patient_appointment">
<column name="priority" type="varchar(45)">
<constraints nullable="true"/>
</column>
</addColumn>
</changeSet>
<changeSet id="remove-not-null-constraint-202402271826" author="Kavitha, Umair">
<preConditions onFail="MARK_RAN">
<tableExists tableName="patient_appointment" />
<columnExists tableName="patient_appointment" columnName="start_date_time" />
<columnExists tableName="patient_appointment" columnName="end_date_time" />
</preConditions>
<comment>Update start and end date time of patient appointment table to be nullable</comment>
<sql>
ALTER TABLE patient_appointment MODIFY start_date_time datetime default null;
ALTER TABLE patient_appointment MODIFY end_date_time datetime default null;
</sql>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.openmrs.module.appointments.dao.impl;

import org.hibernate.Criteria;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.module.appointments.BaseIntegrationTest;
Expand All @@ -15,15 +14,12 @@
import java.util.*;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class AppointmentDaoImplIT extends BaseIntegrationTest {

@Autowired
AppointmentDao appointmentDao;


@Autowired
AppointmentServiceDao appointmentServiceDao;

Expand All @@ -35,7 +31,7 @@ public void setUp() throws Exception {
@Test
public void shouldGetAllNonVoidedAppointments() throws Exception {
List<Appointment> allAppointmentServices = appointmentDao.getAllAppointments(null);
assertEquals(11, allAppointmentServices.size());
assertEquals(13, allAppointmentServices.size());
}

@Test
Expand All @@ -48,12 +44,12 @@ public void shouldGetAllNonVoidedAppointmentsForDate() throws Exception {
@Test
public void shouldSaveAppointmentService() throws Exception {
List<Appointment> allAppointments = appointmentDao.getAllAppointments(null);
assertEquals(11, allAppointments.size());
assertEquals(13, allAppointments.size());
Appointment apt = new Appointment();
apt.setPatient(allAppointments.get(0).getPatient());
appointmentDao.save(apt);
allAppointments = appointmentDao.getAllAppointments(null);
assertEquals(12, allAppointments.size());
assertEquals(14, allAppointments.size());
}

@Test
Expand Down Expand Up @@ -144,7 +140,7 @@ public void shouldGetAppointmentsBeforeCurrentDateWhenStartDateIsNotProvided() t
@Test
public void shouldGetAllNonVoidedAppointmentsWhenNoDateRangeIsProvided() throws Exception {
List<Appointment> allAppointmentServices = appointmentDao.getAllAppointmentsInDateRange(null, null);
assertEquals(11, allAppointmentServices.size());
assertEquals(13, allAppointmentServices.size());
}

@Test
Expand All @@ -160,7 +156,7 @@ public void shouldSearchAppointmentsForAPatient() {
appointment.setService(allAppointments.get(0).getService());
appointment.setStatus(null);
List<Appointment> searchedAppointmentList = appointmentDao.search(appointment);
assertEquals(1, searchedAppointmentList.size());
assertEquals(3, searchedAppointmentList.size());
}

@Test
Expand Down Expand Up @@ -263,7 +259,7 @@ public void shouldReturnAllAppointmentsInNoGivenDates() throws ParseException {

List<Appointment> appointments = appointmentDao.search(appointmentSearchRequest);

assertEquals(11, appointments.size());
assertEquals(13, appointments.size());
}

@Test
Expand All @@ -278,6 +274,7 @@ public void shouldReturnEmptyListWhenPatientIsNull() {
assertNotNull(appointments);
assertEquals(0, appointments.size());
}

@Test
gsluthra marked this conversation as resolved.
Show resolved Hide resolved
public void testGetAllAppointments() {
Date forDate = new Date();
Expand All @@ -286,7 +283,6 @@ public void testGetAllAppointments() {
assertEquals(0,appointments.size());
}


@Test
public void testGetAllAppointmentsReminder() {
String hours = "24";
Expand All @@ -303,4 +299,11 @@ public void testSearch() {

assertEquals(0, result.size());
}

@Test
public void shouldReturnAppointmentsWithoutDates() {
List<Appointment> appointments = appointmentDao.getAppointmentsWithoutDates(20);
assertNotNull(appointments);
assertEquals(3, appointments.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
import org.mockito.runners.MockitoJUnitRunner;
import org.openmrs.Patient;
import org.openmrs.api.APIException;
import org.openmrs.module.appointments.model.Appointment;
import org.openmrs.module.appointments.model.AppointmentAudit;
import org.openmrs.module.appointments.model.AppointmentKind;
import org.openmrs.module.appointments.model.AppointmentServiceDefinition;
import org.openmrs.module.appointments.model.AppointmentServiceType;
import org.openmrs.module.appointments.model.AppointmentStatus;
import org.openmrs.module.appointments.model.*;
import org.openmrs.module.appointments.util.DateUtil;
import org.openmrs.module.appointments.validator.AppointmentStatusChangeValidator;
import org.openmrs.module.appointments.validator.AppointmentValidator;
Expand Down Expand Up @@ -134,7 +129,7 @@ public void shouldGetJsonStringOfAppointment() throws ParseException, IOExceptio
String notes = "{\"serviceTypeUuid\":\""+ serviceType.getUuid() +"\",\"startDateTime\":\""+
startDateTime.toInstant().toString() +"\",\"locationUuid\":null,\"appointmentKind\":\"Scheduled\"," +
"\"providerUuid\":null,\"endDateTime\":\""+ endDateTime.toInstant().toString()
+"\",\"serviceUuid\":\""+ service.getUuid() +"\",\"appointmentNotes\":null}";
+"\",\"priority\":null,\"serviceUuid\":\""+ service.getUuid() +"\",\"appointmentNotes\":null}";
assertEquals(notes, jsonString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.openmrs.*;
import org.openmrs.api.APIAuthenticationException;
import org.openmrs.api.APIException;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.UserContext;
import org.openmrs.messagesource.MessageSourceService;
Expand Down Expand Up @@ -123,6 +124,10 @@ public class AppointmentsServiceImplTest {
private PatientAppointmentNotifierService patientAppointmentNotifierService;
@Mock
private UserContext userContext;

@Mock
private AdministrationService administrationService;

@InjectMocks
private AppointmentsServiceImpl appointmentsService;

Expand Down Expand Up @@ -502,6 +507,8 @@ public void shouldReturnAppointmentsByCallingSearchMethodInAppointmentDaoWithApp
appointmentSearchRequest.setStartDate(startDate);
appointmentSearchRequest.setEndDate(endDate);
ArrayList<Appointment> expectedAppointments = new ArrayList<>();
when(Context.getAdministrationService()).thenReturn(administrationService);
when(administrationService.getGlobalProperty("webservices.rest.maxResultsDefault")).thenReturn("20");
when(appointmentDao.search(appointmentSearchRequest)).thenReturn(expectedAppointments);

List<Appointment> actualAppointments = appointmentsService.search(appointmentSearchRequest);
Expand All @@ -516,7 +523,8 @@ public void shouldNotCallSearchMethodInAppointmentDaoAndReturnNullWhenStartDateI
Date endDate = Date.from(Instant.now());
appointmentSearchRequest.setStartDate(null);
appointmentSearchRequest.setEndDate(endDate);

when(Context.getAdministrationService()).thenReturn(administrationService);
when(administrationService.getGlobalProperty("webservices.rest.maxResultsDefault")).thenReturn("20");
List<Appointment> actualAppointments = appointmentsService.search(appointmentSearchRequest);

verify(appointmentDao, never()).search(appointmentSearchRequest);
Expand All @@ -532,6 +540,8 @@ public void shouldCallSearchMethodInAppointmentDaoWhenEndDateIsNull() {

ArrayList<Appointment> expectedAppointments = new ArrayList<>();
when(appointmentDao.search(appointmentSearchRequest)).thenReturn(expectedAppointments);
when(Context.getAdministrationService()).thenReturn(administrationService);
when(administrationService.getGlobalProperty("webservices.rest.maxResultsDefault")).thenReturn("20");
List<Appointment> actualAppointments = appointmentsService.search(appointmentSearchRequest);

verify(appointmentDao, times(1)).search(appointmentSearchRequest);
Expand Down Expand Up @@ -776,4 +786,12 @@ public void shouldThrowErrorWhenTryingToChangeProviderResponseForOtherProvider()

appointmentsService.updateAppointmentProviderResponse(providerRequest);
}

@Test
public void shouldGetAppointmentsWithoutDates() {
when(Context.getAdministrationService()).thenReturn(administrationService);
when(administrationService.getGlobalProperty("webservices.rest.maxResultsDefault")).thenReturn("20");
appointmentsService.searchAppointmentsWithoutDates();
verify(appointmentDao, times(1)).getAppointmentsWithoutDates(20);
}
}
2 changes: 2 additions & 0 deletions api/src/test/resources/appointmentTestData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,7 @@
<patient patient_id="3" creator="1" date_created="2008-08-15 11:10:35.0" voided="true" void_reason=""/>
<patient_identifier patient_identifier_id="2" patient_id="2" identifier="GAN300000" identifier_type="1" preferred="1" location_id="1" creator="1" date_created="2006-01-01 00:00:00.0" voided="false" uuid="35f46473-9ed1-4812-8f3a-4740c13dc54f"/>
<patient_appointment patient_appointment_id="16" patient_id ="3" appointment_service_id="1" appointment_service_type_id="2" start_date_time="2017-08-08 14:00:00.0" end_date_time="2017-08-10 15:00:00.0" status="Scheduled" creator="1" date_created="2108-08-10 15:57:09.0" voided="false" void_reason="" uuid="aeead7f2-fc3d-48bb-9c63-e861aaea4a9c"/>
<patient_appointment patient_appointment_id="17" patient_id ="1" creator="1" date_created="2008-08-16 15:57:09.0" voided="false" void_reason="" uuid="75504r42-3ca8-11e3-bf2b-0800271c1b87" location_id = "1" appointment_service_id="1"/>
<patient_appointment patient_appointment_id="18" patient_id ="1" creator="1" date_created="2008-08-17 15:57:09.0" voided="false" void_reason="" uuid="75504r42-3ca8-11e3-bf2b-0800271c1b98" location_id = "1" appointment_service_id="1"/>

</dataset>
Loading
Loading