Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Release 1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MJozefow committed Dec 7, 2023
1 parent c8a7069 commit 8e625e0
Show file tree
Hide file tree
Showing 90 changed files with 4,202 additions and 1,284 deletions.
6 changes: 5 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>cflcore</artifactId>
<version>1.11.1</version>
<version>1.12.0</version>
</parent>

<artifactId>cflcore-api</artifactId>
Expand Down Expand Up @@ -60,6 +60,10 @@
<groupId>org.openmrs.module</groupId>
<artifactId>messages-api</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>visits-api</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>metadatasharing-api</artifactId>
Expand Down
34 changes: 34 additions & 0 deletions api/src/main/java/org/openmrs/module/cflcore/CFLConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ public final class CFLConstants {

public static final String UPDATE_REGIMEN_JOB_NAME = "Update Regimen Job";

public static final String SCHEDULED_TASKS_TO_DELETE_CLASS_NAMES_KEY = "cfl.scheduledTasksToDelete.classNames";

public static final String SCHEDULED_TASKS_CLEANUP_JOB_NAME = "Scheduled Tasks Cleanup Job";

public static final String CFL_ADDRESS_DATA_SERVICE_BEAN_NAME = "cfl.addressService";

public static final String CFL_VISIT_SERVICE_BEAN_NAME = "cfl.visitService";
Expand All @@ -354,6 +358,32 @@ public final class CFLConstants {
public static final String IS_LAST_DOSING_VISIT_ATTR_TYPE_UUID =
"1e566e6d-108e-11ec-a36a-0242ac130002";

public static final String UP_WINDOW_ATTR_TYPE_DATATYPE =
FreeTextDatatype.class.getName();

public static final String UP_WINDOW_ATTR_TYPE_DESCRIPTION =
"Visit attribute type used to determine time window after the visit";

public static final String UP_WINDOW_ATTR_TYPE_UUID =
"5899e8d4-5eac-11ee-8c99-0242ac120002";

public static final String LOW_WINDOW_ATTR_TYPE_DATATYPE =
FreeTextDatatype.class.getName();

public static final String LOW_WINDOW_ATTR_TYPE_DESCRIPTION =
"Visit attribute type used to determine time window before the visit";

public static final String LOW_WINDOW_ATTR_TYPE_UUID =
"5899ed48-5eac-11ee-8c99-0242ac120002";

public static final String DOSE_NUMBER_ATTR_TYPE_DATATYPE =
FreeTextDatatype.class.getName();

public static final String DOSE_NUMBER_ATTR_TYPE_DESCRIPTION =
"Visit attribute type used to determine vaccine dose number";

public static final String DOSE_NUMBER_ATTR_TYPE_UUID =
"5899ee92-5eac-11ee-8c99-0242ac120002";
public static final String MAIN_CONFIG = "biometric.api.config.main";

public static final String REGIMEN_TAG_NAME = "regimen";
Expand Down Expand Up @@ -390,6 +420,10 @@ public final class CFLConstants {

public static final String FIND_CAREGIVER_APP_NAME = CFL_UI_APP_PREFIX.concat("findCaregiver");

public static final String VISITS_ASSIGNMENT_HANDLER_GP_NAME = "visits.assignmentHandler";

public static final String PATIENT_FLAGS_OVERVIEW_APP_NAME = "cfl.patientFlagsOverview";

private CFLConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

package org.openmrs.module.cflcore;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.PersonAttributeType;
Expand All @@ -22,6 +19,7 @@
import org.openmrs.api.PersonService;
import org.openmrs.api.UserService;
import org.openmrs.api.context.Context;
import org.openmrs.api.handler.NoVisitAssignmentHandler;
import org.openmrs.module.BaseModuleActivator;
import org.openmrs.module.DaemonToken;
import org.openmrs.module.DaemonTokenAware;
Expand All @@ -31,14 +29,21 @@
import org.openmrs.module.cflcore.api.event.CflEventListenerHelper;
import org.openmrs.module.cflcore.api.event.listener.subscribable.BaseListener;
import org.openmrs.module.cflcore.api.htmlformentry.tag.RegimenHandler;
import org.openmrs.module.cflcore.api.scheduler.job.ScheduledTasksCleanupJobDefinition;
import org.openmrs.module.cflcore.api.util.GlobalPropertiesConstants;
import org.openmrs.module.cflcore.api.util.GlobalPropertyUtils;
import org.openmrs.module.emrapi.utils.MetadataUtil;
import org.openmrs.module.htmlformentry.HtmlFormEntryService;
import org.openmrs.module.messages.api.constants.MessagesConstants;
import org.openmrs.module.messages.api.service.MessagesSchedulerService;
import org.openmrs.module.messages.api.util.CountryPropertyUtils;
import org.openmrs.module.metadatadeploy.api.MetadataDeployService;
import org.openmrs.module.metadatadeploy.bundle.MetadataBundle;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* This class contains the logic that is run every time this module is either started or shutdown
*/
Expand All @@ -55,11 +60,13 @@ public void started() {
try {
attachProgramsManagingPrivilegesToSuperUser();
ensureCorrectRolesAreAssignedToAdmin();
configureOrCreateScheduledTasksCleanupJob();

// These 3 are Global Properties
createPersonOverviewConfig();
createGlobalSettings();
createCountrySettings();
updateGlobalSettings();

CflEventListenerHelper.registerEventListeners();

Expand Down Expand Up @@ -115,9 +122,7 @@ private void createPersonAttributeTypes() {
createPersonIdentifierAttributeType();
}

/**
* Creates person attribute type used to store information about additional person identifier.
*/
/** Creates person attribute type used to store information about additional person identifier. */
private void createPersonIdentifierAttributeType() {
PersonAttributeType attributeType = new PersonAttributeType();
attributeType.setName(CFLConstants.PERSON_IDENTIFIER_ATTRIBUTE_TYPE_NAME);
Expand Down Expand Up @@ -255,6 +260,18 @@ private void createGlobalSettings() {
GlobalPropertiesConstants.AD_HOC_SMS_MESSAGE_TEMPLATE);
GlobalPropertyUtils.createGlobalSettingIfNotExists(
GlobalPropertiesConstants.AD_HOC_WHATS_APP_MESSAGE_TEMPLATE);
GlobalPropertyUtils.createGlobalSettingIfNotExists(
GlobalPropertiesConstants.SCHEDULED_TASK_CONFIG_CLASS_NAMES);
GlobalPropertyUtils.createGlobalSettingIfNotExists(
GlobalPropertiesConstants.SHOULD_CREATE_FIRST_VISIT);
GlobalPropertyUtils.createGlobalSettingIfNotExists(
GlobalPropertiesConstants.SHOULD_CREATE_FUTURE_VISITS);
GlobalPropertyUtils.createGlobalSettingIfNotExists(
GlobalPropertiesConstants.SHOULD_SEND_REMINDER_VIA_SMS);
GlobalPropertyUtils.createGlobalSettingIfNotExists(
GlobalPropertiesConstants.SHOULD_SEND_REMINDER_VIA_CALL);
GlobalPropertyUtils.createGlobalSettingIfNotExists(
GlobalPropertiesConstants.SHOULD_SEND_REMINDER_VIA_WHATSAPP);
}

private void createCountrySettings() {
Expand Down Expand Up @@ -295,13 +312,13 @@ private void createCountrySettings() {
Boolean.FALSE.toString(),
CountryPropertyConstants.SHOULD_SEND_REMINDER_VIA_CALL_PROP_DESC);
CountryPropertyUtils.createDefaultCountrySettingIfNotExists(
CountryPropertyConstants.SEND_WHATSAPP_ON_PATIENT_REGISTRATION_PROP_NAME,
Boolean.FALSE.toString(),
CountryPropertyConstants.SEND_WHATSAPP_ON_PATIENT_REGISTRATION_PROP_DESC);
CountryPropertyConstants.SEND_WHATSAPP_ON_PATIENT_REGISTRATION_PROP_NAME,
Boolean.FALSE.toString(),
CountryPropertyConstants.SEND_WHATSAPP_ON_PATIENT_REGISTRATION_PROP_DESC);
CountryPropertyUtils.createDefaultCountrySettingIfNotExists(
CountryPropertyConstants.SHOULD_SEND_REMINDER_VIA_WHATSAPP_PROP_NAME,
Boolean.FALSE.toString(),
CountryPropertyConstants.SHOULD_SEND_REMINDER_VIA_WHATSAPP_PROP_DESC);
CountryPropertyConstants.SHOULD_SEND_REMINDER_VIA_WHATSAPP_PROP_NAME,
Boolean.FALSE.toString(),
CountryPropertyConstants.SHOULD_SEND_REMINDER_VIA_WHATSAPP_PROP_DESC);
CountryPropertyUtils.createDefaultCountrySettingIfNotExists(
CountryPropertyConstants.SHOULD_CREATE_FIRST_VISIT_PROP_NAME,
Boolean.FALSE.toString(),
Expand All @@ -312,6 +329,13 @@ private void createCountrySettings() {
CountryPropertyConstants.SHOULD_CREATE_FUTURE_VISIT_PROP_DESC);
}

private void updateGlobalSettings() {
Context.getAdministrationService()
.setGlobalProperty(
CFLConstants.VISITS_ASSIGNMENT_HANDLER_GP_NAME,
NoVisitAssignmentHandler.class.getName());
}

private void createPersonOverviewConfig() {
GlobalPropertyUtils.createGlobalSettingIfNotExists(
ConfigConstants.FIND_PERSON_FILTER_STRATEGY_KEY,
Expand Down Expand Up @@ -365,4 +389,15 @@ private void addTagHandlers() {
Context.getService(HtmlFormEntryService.class)
.addHandler(CFLConstants.REGIMEN_TAG_NAME, new RegimenHandler());
}

private void configureOrCreateScheduledTasksCleanupJob() {
final Long oneWeekInSeconds = 7L * 24 * 60 * 60;
getSchedulerService()
.rescheduleOrCreateNewTask(new ScheduledTasksCleanupJobDefinition(), oneWeekInSeconds);
}

private MessagesSchedulerService getSchedulerService() {
return Context.getRegisteredComponent(
MessagesConstants.SCHEDULER_SERVICE, MessagesSchedulerService.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
* <p>
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/

package org.openmrs.module.cflcore.advice;

import org.openmrs.Encounter;
import org.openmrs.Order;
import org.openmrs.api.EncounterService;
import org.openmrs.api.context.Context;
import org.openmrs.module.cflcore.db.ExtendedOrderDAO;
import org.springframework.aop.AfterReturningAdvice;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

/** Modifies logic of EncounterService to fit SHIP CFL requirements. */
public class EncounterAdvice implements AfterReturningAdvice {
private final Map<Method, Consumer<Encounter>> encounterMethodCallbacks = new HashMap<>();

public EncounterAdvice() {
try {
encounterMethodCallbacks.put(
EncounterService.class.getMethod("voidEncounter", Encounter.class, String.class),
this::clearPreviousOrderStoppedDate);
} catch (NoSuchMethodException nsme) {
throw new IllegalStateException(
"EncounterAdvice implementation incompatible with EncounterService.", nsme);
}
}

@Override
public void afterReturning(Object o, Method method, Object[] objects, Object o1) {
if (encounterMethodCallbacks.containsKey(method)) {
encounterMethodCallbacks.get(method).accept((Encounter) objects[0]);
}
}

private void clearPreviousOrderStoppedDate(Encounter encounter) {
for (Order encounterOrder : encounter.getOrders()) {
final Order previousOrder = encounterOrder.getPreviousOrder();

if (previousOrder == null || previousOrder.getVoided()) {
continue;
}

getExtendedOrderDAO().restartOrder(previousOrder);
}
}

private ExtendedOrderDAO getExtendedOrderDAO() {
final List<ExtendedOrderDAO> implementations =
Context.getRegisteredComponents(ExtendedOrderDAO.class);

if (implementations.isEmpty()) {
throw new IllegalStateException("Missing an ExtendedOrderDAO Spring bean.");
}

return implementations.get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ public class CountrySetting {
private String call;
private boolean performCallOnPatientRegistration;
private boolean sendSmsOnPatientRegistration;
private boolean shouldSendReminderViaCall;
private boolean shouldSendReminderViaSms;
private boolean sendWhatsAppOnPatientRegistration;
private boolean shouldSendReminderViaWhatsApp;
private boolean shouldCreateFirstVisit;
private boolean shouldCreateFutureVisit;
private String patientNotificationTimeWindowFrom;
private String patientNotificationTimeWindowTo;

Expand All @@ -34,25 +29,15 @@ public CountrySetting() {}
String call,
boolean performCallOnPatientRegistration,
boolean sendSmsOnPatientRegistration,
boolean shouldSendReminderViaCall,
boolean shouldSendReminderViaSms,
boolean sendWhatsAppOnPatientRegistration,
boolean shouldSendReminderViaWhatsApp,
boolean shouldCreateFirstVisit,
boolean shouldCreateFutureVisit,
String patientNotificationTimeWindowFrom,
String patientNotificationTimeWindowTo) {
this.sms = sms;
this.whatsApp = whatsApp;
this.call = call;
this.performCallOnPatientRegistration = performCallOnPatientRegistration;
this.sendSmsOnPatientRegistration = sendSmsOnPatientRegistration;
this.shouldSendReminderViaCall = shouldSendReminderViaCall;
this.shouldSendReminderViaSms = shouldSendReminderViaSms;
this.sendWhatsAppOnPatientRegistration = sendWhatsAppOnPatientRegistration;
this.shouldSendReminderViaWhatsApp = shouldSendReminderViaWhatsApp;
this.shouldCreateFirstVisit = shouldCreateFirstVisit;
this.shouldCreateFutureVisit = shouldCreateFutureVisit;
this.patientNotificationTimeWindowFrom = patientNotificationTimeWindowFrom;
this.patientNotificationTimeWindowTo = patientNotificationTimeWindowTo;
}
Expand Down Expand Up @@ -97,22 +82,6 @@ public void setSendSmsOnPatientRegistration(boolean sendSmsOnPatientRegistration
this.sendSmsOnPatientRegistration = sendSmsOnPatientRegistration;
}

public boolean isShouldSendReminderViaCall() {
return shouldSendReminderViaCall;
}

public void setShouldSendReminderViaCall(boolean shouldSendReminderViaCall) {
this.shouldSendReminderViaCall = shouldSendReminderViaCall;
}

public boolean isShouldSendReminderViaSms() {
return shouldSendReminderViaSms;
}

public void setShouldSendReminderViaSms(boolean shouldSendReminderViaSms) {
this.shouldSendReminderViaSms = shouldSendReminderViaSms;
}

public boolean isSendWhatsAppOnPatientRegistration() {
return sendWhatsAppOnPatientRegistration;
}
Expand All @@ -121,30 +90,6 @@ public void setSendWhatsAppOnPatientRegistration(boolean sendWhatsAppOnPatientRe
this.sendWhatsAppOnPatientRegistration = sendWhatsAppOnPatientRegistration;
}

public boolean isShouldSendReminderViaWhatsApp() {
return shouldSendReminderViaWhatsApp;
}

public void setShouldSendReminderViaWhatsApp(boolean shouldSendReminderViaWhatsApp) {
this.shouldSendReminderViaWhatsApp = shouldSendReminderViaWhatsApp;
}

public boolean isShouldCreateFirstVisit() {
return shouldCreateFirstVisit;
}

public void setShouldCreateFirstVisit(boolean shouldCreateFirstVisit) {
this.shouldCreateFirstVisit = shouldCreateFirstVisit;
}

public boolean isShouldCreateFutureVisit() {
return shouldCreateFutureVisit;
}

public void setShouldCreateFutureVisit(boolean shouldCreateFutureVisit) {
this.shouldCreateFutureVisit = shouldCreateFutureVisit;
}

public String getPatientNotificationTimeWindowFrom() {
return patientNotificationTimeWindowFrom;
}
Expand Down
Loading

0 comments on commit 8e625e0

Please sign in to comment.