Skip to content

Commit

Permalink
Fix eligibility criteria && discontinuation date NPE (#1933)
Browse files Browse the repository at this point in the history
  • Loading branch information
makombe authored Jun 27, 2024
1 parent 3fc4149 commit a6b9cd4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.kenyaemr.calculation.library.ncd;

import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation;
import org.openmrs.module.kenyacore.calculation.BooleanResult;
import org.openmrs.module.kenyacore.calculation.Filters;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
* Calculates whether patients are eligible for Gender Based Violence program
* Eligibility: Alive
*/
public class EligibleForNCDProgramCalculation extends AbstractPatientCalculation {

/**
* @see org.openmrs.calculation.patient.PatientCalculation#evaluate(Collection, Map, PatientCalculationContext)
*/
@Override
public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> params, PatientCalculationContext context) {

Set<Integer> alive = Filters.alive(cohort, context);
CalculationResultMap ret = new CalculationResultMap();
for(Integer ptId: cohort){

boolean eligible = false;
if (alive.contains(ptId)) {
eligible = true;
}
ret.put(ptId, new BooleanResult(eligible, this));
}
return ret;
}
}
1 change: 1 addition & 0 deletions api/src/main/resources/content/kenyaemr.ncd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<bean id="kenyaemr.ncd.program" class="org.openmrs.module.kenyacore.program.ProgramDescriptor">
<property name="targetUuid" value="ffee43c4-9ccd-4e55-8a70-93194e7fafc6" />
<property name="eligibilityCalculation" value="org.openmrs.module.kenyaemr.calculation.library.ncd.EligibleForNCDProgramCalculation" />
<property name="defaultEnrollmentForm" ref="kenyaemr.ncd.form.initial" />
<property name="visitForms">
<set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,10 @@ public Object getEligiblePrograms(HttpServletRequest request, @RequestParam("pat
programObj.put("uuid", descriptor.getTargetUuid());
programObj.put("display", descriptor.getTarget().getName());
programObj.put("enrollmentFormUuid", descriptor.getDefaultEnrollmentForm().getTargetUuid());
programObj.put("discontinuationFormUuid", descriptor.getDefaultCompletionForm().getTargetUuid());
if(descriptor.getDefaultCompletionForm() != null && descriptor.getDefaultCompletionForm().getTargetUuid() != null) {
programObj.put("discontinuationFormUuid", descriptor.getDefaultCompletionForm().getTargetUuid());

}
programObj.put("enrollmentStatus", activePrograms.contains(descriptor) ? "active" : "eligible");
programList.add(programObj);
}
Expand Down Expand Up @@ -1182,8 +1185,11 @@ public ArrayList<SimpleObject> getPatientHistoricalEnrollment(@RequestParam("pat
ArrayList enrollmentDetails = new ArrayList<SimpleObject>();
for(ProgramDescriptor descriptor: programs) {
Program program = descriptor.getTarget();
Form defaultCompletionForm = null ;
Form defaultEnrollmentForm = descriptor.getDefaultEnrollmentForm().getTarget();
Form defaultCompletionForm = descriptor.getDefaultCompletionForm().getTarget();
if(descriptor.getDefaultCompletionForm()!= null) {
defaultCompletionForm = descriptor.getDefaultCompletionForm().getTarget();
}

List<PatientProgram> allEnrollments = programManager.getPatientEnrollments(patient, program);
for (PatientProgram patientProgramEnrollment : allEnrollments) {
Expand Down

0 comments on commit a6b9cd4

Please sign in to comment.