Skip to content

Commit

Permalink
Merge pull request #1957 from PatrickWaweru/createDuplicateNUPIreport
Browse files Browse the repository at this point in the history
Added NUPI Duplicates report
  • Loading branch information
patryllus authored Jul 22, 2024
2 parents 1bd5994 + 9837b3c commit b453451
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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.nupi;

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

import org.openmrs.Patient;
import org.openmrs.PersonAttributeType;
import org.openmrs.api.PatientService;
import org.openmrs.api.context.Context;
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.kenyaemr.metadata.CommonMetadata;

/**
* Calculate whether a patient has high IIT risk score based on data pulled from NDWH
*/
public class DuplicateNUPICalculation extends AbstractPatientCalculation {

/**
* @see org.openmrs.calculation.patient.PatientCalculation#evaluate(Collection, Map,
* PatientCalculationContext)
* @should determine whether a patient has high IIT risk
*/
@Override
public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) {

PersonAttributeType duplicateStatusPA = Context.getPersonService().getPersonAttributeTypeByUuid(CommonMetadata._PersonAttributeType.DUPLICATE_NUPI_STATUS_WITH_NATIONAL_REGISTRY);
PatientService patientService = Context.getPatientService();
CalculationResultMap ret = new CalculationResultMap();

try {
for(Integer ptId: cohort){
Patient patient = patientService.getPatient(ptId);
try {
if (patient.getAttribute(duplicateStatusPA) != null) {
// Has a duplicate?
if (patient.getAttribute(duplicateStatusPA).getValue().trim().equalsIgnoreCase("true")) {
ret.put(patient.getId(), new BooleanResult(true, this, context));
}
}
} catch(Exception em) {
System.err.println("Duplicate NUPI Error reporting: " + em.getMessage());
em.printStackTrace();
}
}
} catch(Exception ex) {
System.err.println("Duplicate NUPI Error reporting: " + ex.getMessage());
ex.printStackTrace();
}

return ret;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* 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.builder.nupi;

import javax.persistence.AttributeConverter;

import org.openmrs.PatientIdentifierType;
import org.openmrs.PersonAttributeType;
import org.openmrs.api.context.Context;
import org.openmrs.module.kenyacore.report.CohortReportDescriptor;
import org.openmrs.module.kenyacore.report.builder.Builds;
import org.openmrs.module.kenyacore.report.builder.CalculationReportBuilder;
import org.openmrs.module.kenyacore.report.data.patient.definition.CalculationDataDefinition;
import org.openmrs.module.kenyaemr.calculation.library.hiv.art.DateOfEnrollmentArtCalculation;
import org.openmrs.module.kenyaemr.metadata.CommonMetadata;
import org.openmrs.module.kenyaemr.metadata.HivMetadata;
import org.openmrs.module.kenyaemr.reporting.calculation.converter.DateArtStartDateConverter;
import org.openmrs.module.kenyaemr.reporting.data.converter.IdentifierConverter;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLArtStartDateDataDefinition;
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.ETLNextAppointmentDateDataDefinition;
import org.openmrs.module.metadatadeploy.MetadataUtils;
import org.openmrs.module.reporting.data.DataDefinition;
import org.openmrs.module.reporting.data.converter.DateConverter;
import org.openmrs.module.reporting.data.patient.definition.ConvertedPatientDataDefinition;
import org.openmrs.module.reporting.data.patient.definition.PatientIdentifierDataDefinition;
import org.openmrs.module.reporting.data.person.definition.ConvertedPersonDataDefinition;
import org.openmrs.module.reporting.data.person.definition.PersonAttributeDataDefinition;
import org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition;
import org.springframework.stereotype.Component;

@Component
@Builds({ "kenyaemr.common.report.duplicateNUPI" })
public class DuplicateNUPIReportBuilder extends CalculationReportBuilder {

public static final String DATE_FORMAT = "dd/MM/yyyy";

@Override
protected void addColumns(CohortReportDescriptor report, PatientDataSetDefinition dsd) {
PatientIdentifierType upn = MetadataUtils.existing(PatientIdentifierType.class, HivMetadata._PatientIdentifierType.UNIQUE_PATIENT_NUMBER);
DataDefinition cccIdentifierDef = new ConvertedPatientDataDefinition("identifier", new PatientIdentifierDataDefinition(upn.getName(), upn), new IdentifierConverter());
PatientIdentifierType nupiIdentifierType = MetadataUtils.existing(PatientIdentifierType.class, CommonMetadata._PatientIdentifierType.NATIONAL_UNIQUE_PATIENT_IDENTIFIER);
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 duplicateTotalSitesDef = new ConvertedPersonDataDefinition("attribute", new PersonAttributeDataDefinition(duplicateTotalSitesPA.getName(), duplicateTotalSitesPA));

addStandardColumns(report, dsd);
dsd.addColumn("CCC", cccIdentifierDef, "");
dsd.addColumn("NUPI", nupiIdentifierDef, "");
dsd.addColumn("Active Facilities", duplicateSiteNamesDef, "");
dsd.addColumn("Total Sites", duplicateTotalSitesDef, "");
dsd.addColumn("Enrollment Date", new CalculationDataDefinition("Enrollment Date", new DateOfEnrollmentArtCalculation()), "", new DateArtStartDateConverter());
dsd.addColumn("Art Start Date", new ETLArtStartDateDataDefinition(), "", new DateConverter(DATE_FORMAT));
dsd.addColumn("First Regimen", new ETLFirstRegimenDataDefinition(), "");
dsd.addColumn("Current Regimen", new ETLCurrentRegimenDataDefinition(), "");
dsd.addColumn("Current Regimen Line", new ETLCurrentRegLineDataDefinition(), "");
dsd.addColumn("Next Appointment Date", new ETLNextAppointmentDateDataDefinition(), "", new DateConverter(DATE_FORMAT));
}
}
9 changes: 9 additions & 0 deletions api/src/main/resources/content/kenyaemr.common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<ref bean="kenyaemr.common.report.moh711"/>
<ref bean="kenyaemr.common.report.sgbvlinelist"/>
<ref bean="kenyaemr.common.report.sgbvRegister"/>
<ref bean="kenyaemr.common.report.duplicateNUPI"/>
</set>
</property>
<property name="ehrReports">
Expand All @@ -106,6 +107,14 @@
</property>
</bean>

<bean id="kenyaemr.common.report.duplicateNUPI" class="org.openmrs.module.kenyacore.report.CalculationReportDescriptor">
<property name="targetUuid" value="7b60235c-f565-48ee-82ed-38a8dd5e9e53" />
<property name="name" value="Duplicate NUPI" />
<property name="description" value="Patients with Duplicate NUPI" />
<property name="calculation" value="org.openmrs.module.kenyaemr.calculation.library.nupi.DuplicateNUPICalculation" />
<property name="apps"><set><ref bean="kenyaemr.app.reports" /></set></property>
</bean>

<bean id="kenyaemr.config.regimen" class="org.openmrs.module.kenyaemr.regimen.RegimenConfiguration">
<property name="definitionsPath" value="regimens.xml" />
</bean>
Expand Down

0 comments on commit b453451

Please sign in to comment.