forked from I-TECH/openmrs-module-kenyaemr
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1957 from PatrickWaweru/createDuplicateNUPIreport
Added NUPI Duplicates report
- Loading branch information
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...n/java/org/openmrs/module/kenyaemr/calculation/library/nupi/DuplicateNUPICalculation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
|
71 changes: 71 additions & 0 deletions
71
...n/java/org/openmrs/module/kenyaemr/reporting/builder/nupi/DuplicateNUPIReportBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters