Skip to content

Commit

Permalink
Modified the NUPI Duplicates report to include VL columns and Facilit…
Browse files Browse the repository at this point in the history
…y names
  • Loading branch information
PatrickWaweru committed Jul 30, 2024
1 parent 9f1a130 commit 5bdf6f2
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLCurrentRegLineDataDefinition;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLCurrentRegimenDataDefinition;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLFirstRegimenDataDefinition;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastVLDateDataDefinition;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastVLResultDataDefinition;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLNextAppointmentDateDataDefinition;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.nupi.FacilityDataDefinition;
import org.openmrs.module.metadatadeploy.MetadataUtils;
import org.openmrs.module.reporting.data.DataDefinition;
import org.openmrs.module.reporting.data.converter.DateConverter;
Expand All @@ -53,7 +56,8 @@ protected void addColumns(CohortReportDescriptor report, PatientDataSetDefinitio
DataDefinition nupiIdentifierDef = new ConvertedPatientDataDefinition("identifier", new PatientIdentifierDataDefinition(nupiIdentifierType.getName(), nupiIdentifierType), new IdentifierConverter());
PersonAttributeType duplicateSitesPA = Context.getPersonService().getPersonAttributeTypeByUuid(CommonMetadata._PersonAttributeType.DUPLICATE_NUPI_SITES_WITH_NATIONAL_REGISTRY);
PersonAttributeType duplicateTotalSitesPA = Context.getPersonService().getPersonAttributeTypeByUuid(CommonMetadata._PersonAttributeType.DUPLICATE_NUPI_TOTALSITES_WITH_NATIONAL_REGISTRY);
DataDefinition duplicateSiteNamesDef = new ConvertedPersonDataDefinition("attribute", new PersonAttributeDataDefinition(duplicateSitesPA.getName(), duplicateSitesPA));
// DataDefinition duplicateSiteNamesDef = new ConvertedPersonDataDefinition("attribute", new PersonAttributeDataDefinition(duplicateSitesPA.getName(), duplicateSitesPA));
DataDefinition duplicateSiteNamesDef = new ConvertedPersonDataDefinition("attribute", new FacilityDataDefinition(duplicateSitesPA.getName(), duplicateSitesPA));
DataDefinition duplicateTotalSitesDef = new ConvertedPersonDataDefinition("attribute", new PersonAttributeDataDefinition(duplicateTotalSitesPA.getName(), duplicateTotalSitesPA));

addStandardColumns(report, dsd);
Expand All @@ -67,5 +71,7 @@ protected void addColumns(CohortReportDescriptor report, PatientDataSetDefinitio
dsd.addColumn("Current Regimen", new ETLCurrentRegimenDataDefinition(), "");
dsd.addColumn("Current Regimen Line", new ETLCurrentRegLineDataDefinition(), "");
dsd.addColumn("Next Appointment Date", new ETLNextAppointmentDateDataDefinition(), "", new DateConverter(DATE_FORMAT));
dsd.addColumn("Last VL Date", new ETLLastVLDateDataDefinition(), "");
dsd.addColumn("Last VL Result", new ETLLastVLResultDataDefinition(), "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* 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.reporting.data.converter.definition.evaluator.nupi;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.openmrs.CohortMembership;
import org.openmrs.Location;
import org.openmrs.Person;
import org.openmrs.PersonAttribute;
import org.openmrs.annotation.Handler;
import org.openmrs.api.context.Context;
import org.openmrs.module.kenyaemr.api.KenyaEmrService;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.nupi.FacilityDataDefinition;
import org.openmrs.module.reporting.data.person.EvaluatedPersonData;
import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition;
import org.openmrs.module.reporting.data.person.evaluator.PersonDataEvaluator;
import org.openmrs.module.reporting.evaluation.EvaluationContext;
import org.openmrs.module.reporting.evaluation.EvaluationException;
import org.openmrs.module.reporting.evaluation.service.EvaluationService;
import org.springframework.beans.factory.annotation.Autowired;

@Handler(supports = FacilityDataDefinition.class)
public class FacilityDataEvaluator implements PersonDataEvaluator {

@Autowired
private EvaluationService evaluationService;

@Override
public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException {
Map<Integer, Object> result = new HashMap<Integer, Object>();
EvaluatedPersonData evaluatedEncounterData = new EvaluatedPersonData(definition, context);

// Retrieve the cohort memberships from the context
Collection<CohortMembership> cohortMemberships = context.getBaseCohort().getMemberships();

for (CohortMembership membership : cohortMemberships) {
Integer patientId = membership.getPatientId();

// Get the person
Person person = Context.getPersonService().getPerson(patientId);
if (person != null) {
FacilityDataDefinition facilityDataDefinition = (FacilityDataDefinition) definition;
PersonAttribute attribute = person.getAttribute(facilityDataDefinition.getPersonAttributeType());
if (attribute != null) {
// Get the facility names and append
String originalValue = attribute.getValue();
String modifiedValue = getFacilityNames(originalValue);
result.put(patientId, modifiedValue);
}
}
}

evaluatedEncounterData.setData(result);
return evaluatedEncounterData;
}

/**
* Returns the facility names given a list of MFL codes
* @param facilities the MFL codes separated by commas
* @return
*/
private String getFacilityNames(String facilities) {
String ret = "";
if (facilities != null && !facilities.isEmpty()) {
String[] ids = facilities.split(",");
StringBuilder result = new StringBuilder();

for (String id : ids) {
try {
// int key = Integer.parseInt(id.trim());
id = id.trim();
Location facility = Context.getService(KenyaEmrService.class).getLocationByMflCode(id);
String fname = facility.getName();

if (fname != null) {
result.append(id + ": " + fname).append(",\n<br />"); // Add the fname, a comma and a newline
}
} catch(Exception e) {}
}

// Remove the trailing comma and newline if there are entries
if (result.length() > 0) {
try {
result.setLength(result.length() - 8);
} catch(Exception e){}
}

ret = result.toString();
}
return(ret);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 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.reporting.data.converter.definition.nupi;

import org.openmrs.PersonAttributeType;
import org.openmrs.module.reporting.data.BaseDataDefinition;
import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition;
import org.openmrs.module.reporting.definition.configuration.ConfigurationProperty;

public class FacilityDataDefinition extends BaseDataDefinition implements PersonDataDefinition {

@ConfigurationProperty
private PersonAttributeType personAttributeType;

public FacilityDataDefinition() {
}

public FacilityDataDefinition(String name, PersonAttributeType personAttributeType) {
super.setName(name);
this.personAttributeType = personAttributeType;
}

@Override
public Class<?> getDataType() {
return String.class;
}

public PersonAttributeType getPersonAttributeType() {
return personAttributeType;
}

public void setPersonAttributeType(PersonAttributeType personAttributeType) {
this.personAttributeType = personAttributeType;
}
}

0 comments on commit 5bdf6f2

Please sign in to comment.