Skip to content

Commit

Permalink
U4X-663: Use DSDM mixed approach of obs and workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaluku authored Jul 16, 2024
1 parent a72243c commit 5310c7d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 264 deletions.
6 changes: 0 additions & 6 deletions api/src/main/resources/metadata/Programs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
<program_workflow_state program_workflow_state_id="19" program_workflow_id="5" concept_id="165139" initial="0" terminal="0" creator="1" date_created="2024-03-17 15:15:44" retired="0" uuid="5e122a20-3e23-4e65-bb1b-9f1324f97396"/>
<program_workflow_state program_workflow_state_id="20" program_workflow_id="5" concept_id="165141" initial="0" terminal="0" creator="1" date_created="2024-03-17 15:15:44" retired="0" uuid="0ca3db87-567f-4159-acc0-0ec14d0b8036"/>
<program_workflow_state program_workflow_state_id="21" program_workflow_id="5" concept_id="165142" initial="0" terminal="0" creator="1" date_created="2024-03-17 15:15:44" retired="0" uuid="7e2acb9c-25e9-4b8f-b012-8436051d5c32"/>




<!-- HIV Program - Attributes -->
<program_attribute_type program_attribute_type_id="9" name="ART Baseline Regimen" description="The regimen the patient started with on the start of ART" datatype="org.openmrs.customdatatype.datatype.ConceptDatatype" min_occurs="0" max_occurs="1" creator="1" date_created="2020-07-29 09:30:34" uuid="f19f1d6e-5d44-4523-9352-4988144021e6"/>
<program_attribute_type program_attribute_type_id="10" name="ART Baseline Regimen Start Date" description="The date the patient started ART" datatype="org.openmrs.customdatatype.datatype.DateDatatype" min_occurs="0" max_occurs="1" creator="1" date_created="2020-07-29 09:30:34" uuid="6bcdd5ea-c140-4edf-9f57-77b0584a196d"/>
Expand All @@ -64,12 +60,10 @@
<program_workflow_state program_workflow_state_id="15" program_workflow_id="4" concept_id="166498" initial="1" terminal="0" creator="1" date_created="2021-08-25 19:33:45" retired="0" changed_by="1" date_changed="2021-08-25 19:33:56" uuid="a6a0ab45-b7dc-43b2-b28c-45a91f968ebf"/>
<program_workflow_state program_workflow_state_id="16" program_workflow_id="4" concept_id="166497" initial="1" terminal="0" creator="1" date_created="2021-08-25 19:33:45" retired="0" changed_by="1" date_changed="2021-08-25 19:33:56" uuid="1b9b83d4-eaca-40da-a7c6-53b8ea3436ad"/>


<!-- Retire DSDM Programs -->
<program program_id="5" concept_id="165138" creator="2" date_created="2019-08-21 09:14:57" changed_by="1" date_changed="2024-03-17 15:55:01" retired="1" name="FBIM" description="Facility Based Individual Management a DSDM model for patients that need extra management at the health centre" uuid="de5d54ae-c304-11e8-9ad0-529269fb1459"/>
<program program_id="6" concept_id="165140" creator="2" date_created="2019-08-21 09:14:57" changed_by="1" date_changed="2019-08-21 09:14:57" retired="1" name="FGB" description="Facility Based Groups a DSDM for stable or unstable clients who need peer support" uuid="de5d5b34-c304-11e8-9ad0-529269fb1459"/>
<program program_id="7" concept_id="165139" creator="2" date_created="2019-08-21 09:14:57" changed_by="1" date_changed="2019-08-21 09:14:57" retired="1" name="FTR" description="Fast Track Drug Refill is a DSDM Model for patients who only pick drugs at the health centre" uuid="de5d5896-c304-11e8-9ad0-529269fb1459"/>
<program program_id="8" concept_id="165141" creator="2" date_created="2019-08-21 09:14:57" changed_by="1" date_changed="2024-03-17 15:53:50" retired="1" name="CCLAD" description="Community Client Led ART Delivery is a DSDM Model with client lead groups with rotation drug pickup by client them selves and distribution" uuid="de5d5da0-c304-11e8-9ad0-529269fb1459"/>
<program program_id="9" concept_id="165142" creator="2" date_created="2019-08-21 09:14:57" changed_by="1" date_changed="2024-03-17 15:52:23" retired="1" name="CDDP" description="Community Drug Distribution Point DSDM Model in community where patients pick drugs from a distribution point in community set by their health centre" uuid="de5d6034-c304-11e8-9ad0-529269fb1459"/>

</dataset>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.openmrs.module.ugandaemr.UgandaEMRConstants.CONCEPT_ID_TRANSFERED_OUT;

/**
* Enrolls patients into DSDM programs
* Post form submission for patient
*/
public class HIVClinicalAssessmentSubmissionAction implements CustomFormSubmissionAction {

Expand All @@ -31,15 +31,6 @@ public void applyAction(FormEntrySession session) {
return;
}

//Create DSDM Program on entry of ART Summary Page
if (mode.equals(Mode.ENTER)
&& session.getEncounter().getEncounterType() == Context.getEncounterService().getEncounterTypeByUuid(
"8d5b27bc-c2cc-11de-8d13-0010c6dffd0f")) {
createPatientProgram(session.getEncounter().getPatient(), session.getEncounter().getEncounterDatetime(), Context
.getProgramWorkflowService().getProgramByUuid("de5d54ae-c304-11e8-9ad0-529269fb1459"));
return;
}

if (ugandaEMRService.getPreviousQueue(session.getPatient(), session.getEncounter().getLocation(), PatientQueue.Status.PENDING) != null) {
ugandaEMRService.processLabTestOrdersFromEncounterObs(session, true);
ugandaEMRService.processDrugOrdersFromEncounterObs(session, true);
Expand All @@ -49,208 +40,12 @@ public void applyAction(FormEntrySession session) {
orderViralLoadTest(session);
}

Patient patient = session.getPatient();
Set<Obs> obsList = session.getEncounter().getAllObs();
List<PatientProgram> patientPrograms = getActivePatientProgramAfterThisEncounter(patient, null, session
.getEncounter().getEncounterDatetime());

List<Program> dsdmPrograms = getDSDMPrograms();

if (mode.equals(Mode.EDIT)
&& session.getEncounter().getEncounterType() != Context.getEncounterService().getEncounterTypeByUuid(
"8d5b27bc-c2cc-11de-8d13-0010c6dffd0f")) {
List<PatientProgram> patientProgramOnEncounterDate = getActivePatientProgramAfterThisEncounter(patient, session
.getEncounter().getEncounterDatetime(), session.getEncounter().getEncounterDatetime());

if (obsList != null && getProgramByConceptFromObs(obsList) == null && patientProgramOnEncounterDate.size() > 0) {
for (PatientProgram currentPatientProgram : patientProgramOnEncounterDate) {
/**
* Void DSDM Program whose obs has been voided
*/
voidPatientProgram(currentPatientProgram, "Matching Observation voided", session.getEncounter()
.getChangedBy(), session.getEncounter().getDateChanged());

List<PatientProgram> previousPatientPrograms = openPreviouslyClosedPatientProgram(patient,
currentPatientProgram.getDateEnrolled(), session.getEncounter().getChangedBy());

if (previousPatientPrograms.size() > 0) {
for (PatientProgram previousPatientProgram : previousPatientPrograms) {
if (dsdmPrograms.contains(currentPatientProgram.getProgram())) {

/**
* Void Previous DSDM Program
*/
voidPatientProgram(previousPatientProgram, "Matching Observation voided", session
.getEncounter().getChangedBy(), session.getEncounter().getDateChanged());

/**
* Recreate Voided Program
*/
createPatientProgram(patient, previousPatientProgram.getDateEnrolled(),
previousPatientProgram.getProgram());
}
}
}
}

} else if (obsList != null && patientProgramOnEncounterDate.size() > 0
&& getProgramByConceptFromObs(obsList) != null
&& getProgramByConceptFromObs(obsList) != patientProgramOnEncounterDate.get(0).getProgram()) {

for (PatientProgram patientProgram : patientProgramOnEncounterDate) {
voidPatientProgram(patientProgram, "Matching Observation voided", session.getEncounter().getChangedBy(),
session.getEncounter().getDateChanged());
}
}
}

/**
* Terminate wen patient is already enrolled in the program selected.
*/
for (PatientProgram patientProgram : patientPrograms) {
/**
* Check if Same program is enrolled
*/
if (patientProgram.getProgram() == getProgramByConceptFromObs(obsList)) {
return;
}
/**
* Check if Same program is enrolled on the same date
*/
if (patientProgram.getProgram() == getProgramByConceptFromObs(obsList)
&& patientProgram.getDateEnrolled() == session.getEncounter().getEncounterDatetime()) {
return;
}
}

/**
* Completing all DSDM active programs of the patient
*/
if (!patientPrograms.isEmpty()) {
for (PatientProgram previousPatientDSDMProgram : patientPrograms) {
/**
* Check if program to enroll is greater than
*/
if (session.getEncounter().getEncounterDatetime().compareTo(previousPatientDSDMProgram.getDateEnrolled()) > 0) {
if (getDSDMPrograms().contains(previousPatientDSDMProgram.getProgram())) {
previousPatientDSDMProgram.setDateCompleted(session.getEncounter().getEncounterDatetime());
Context.getProgramWorkflowService().savePatientProgram(previousPatientDSDMProgram);
}
}
}
}

/**
* Enroll patient in new PatientProgram
*/
if (getProgramByConceptFromObs(obsList) != null) {
createPatientProgram(patient, session.getEncounter().getEncounterDatetime(), getProgramByConceptFromObs(obsList));
}


/**
* Create TransferOut encounter When Patient is Transferred Out
*/
createTransferOutEncounter(session);
}

private PatientProgram createPatientProgram(Patient patient, Date enrollmentDate, Program program) {
PatientProgram patientProgram = new PatientProgram();
patientProgram.setPatient(patient);
patientProgram.setDateEnrolled(enrollmentDate);
patientProgram.setProgram(program);
patientProgram.setDateCompleted(null);
return Context.getProgramWorkflowService().savePatientProgram(patientProgram);
}

private PatientProgram voidPatientProgram(PatientProgram patientProgram, String reason, User user, Date changedDated) {
patientProgram.setVoided(true);
patientProgram.setVoidedBy(user);
patientProgram.setVoidReason(reason);
patientProgram.setDateChanged(changedDated);
return Context.getProgramWorkflowService().savePatientProgram(patientProgram);
}

private List<PatientProgram> openPreviouslyClosedPatientProgram(Patient patient, Date date, User user) {
return getCompletedPatientProgramOnDate(patient, date);
}

/**
* Get Program from selected value of the DSDM field on the form
*
* @param obsList
* @return
*/
private Program getProgramByConceptFromObs(Set<Obs> obsList) {
List<Program> programList = new ArrayList<>();
Program program = null;
String dsdmConceptId = Context.getAdministrationService().getGlobalProperty(GP_DSDM_CONCEPT_ID);
for (Obs obs : obsList) {
if (obs.getConcept().getConceptId() == Integer.parseInt(dsdmConceptId) && obs.getConcept().getDatatype() == Context.getConceptService().getConceptDatatypeByName("Coded")) {
programList = Context.getProgramWorkflowService().getProgramsByConcept(obs.getValueCoded());
}
}
if (!programList.isEmpty()) {
program = programList.get(0);
}
return program;
}

/**
* This takes in a patient program and weather previous or after search and determines if there
* is a previous program or there is an after program
*
* @param patient
* @param minEnrollmentDate
* @param maxEnrollmentDate
* @return
*/
private List<PatientProgram> getActivePatientProgramAfterThisEncounter(Patient patient, Date minEnrollmentDate,
Date maxEnrollmentDate) {
List<PatientProgram> patientPrograms = new ArrayList<PatientProgram>();

patientPrograms = Context.getProgramWorkflowService().getPatientPrograms(patient, null, minEnrollmentDate,
maxEnrollmentDate, null, null, false);
return patientPrograms;
}

/**
* This takes in a patient program and weather previous or after search and determines if there
* is a previous program or there is an after program
*
* @param patient
* @param completionDate
* @return
*/
private List<PatientProgram> getCompletedPatientProgramOnDate(Patient patient, Date completionDate) {
List<PatientProgram> patientPrograms = new ArrayList<PatientProgram>();

patientPrograms = Context.getProgramWorkflowService().getPatientPrograms(patient, null, null, null, completionDate,
completionDate, false);
return patientPrograms;
}

/**
* Get List of DSDM Programs
*
* @return
*/
public List<Program> getDSDMPrograms() {
String dsdmuuids = Context.getAdministrationService().getGlobalProperty(GP_DSDM_PROGRAM_UUID_NAME);

List<String> listOfDSDMPrograms = Arrays.asList(dsdmuuids.split("\\s*,\\s*"));
List<Program> dsdmPrograms = new ArrayList<>();

for (String s : listOfDSDMPrograms) {

Program dsdmProgram = Context.getProgramWorkflowService().getProgramByUuid(s);
if (dsdmProgram != null) {
dsdmPrograms.add(dsdmProgram);
}
}
return dsdmPrograms;
}

private void completeClinicianQueue(Encounter encounter) {
UgandaEMRService ugandaEMRService = Context.getService(UgandaEMRService.class);
for (Obs obs : encounter.getAllObs(false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,11 @@
}

</style>
<ifMode mode="ENTER">
<div class="hidden" id="dsdm_approach">
<workflowState workflowId="5" labelText="Approach" stateId="17" type="hidden" />
</div>
</ifMode>

<!-- Beging of HTML Form -->
<div class="poc-page-frame">
Expand Down
Loading

0 comments on commit 5310c7d

Please sign in to comment.