Skip to content

Commit

Permalink
Mepts 196 data quality report (#113)
Browse files Browse the repository at this point in the history
* Added Total Tag to the excel report. The Total value still not reflecting,currently outputing a zero.

* Added OnArtForAtleastXmonthsCalculation class for the DSD D1. Currently testing the step 5 of the requirments document for the indicator.

* Added 5a Cohort Definition

* Add initial report set up for the data quality and template to hold the values

* Add the first part of the report awaiting clarification

* Add the required reports paramaters on the report definition

* Added Criteria 5 b: reused the alreday existing Viral load method.
Added Criteria 5C(i): getCD4CountAndCD4Percent

* Combined criteria 5C i and ii into one criteria.

* Add a base cohort for the data quality report( include a list of location and patient states)

* Add the states parameters to the indicator and tie them into the dataset and report definiton

* Added Criteria 5D: Patient with active clinical condition of WHO stage 3 and 4.
Rearranged the methods for proper readability and commenting.

* Added missing concepts in the hivmetadata, 1692-1699, 821, 16, 1406,adverse reactions, poor adherence
5f: No adverse reactions to medication criteria.

* Add the breastfeeding and pregnant cohorts and datasets

* Added 5E : Poor adherence in last 3  clinical visits

* Added the missing concept UUIDs to the global properties configurations.

* Create the first 2 indicators and link them to the patient states defined on the UI

* 5A, 5B working

* Fixed bgs on the Criteria 5 sub queries
Added dissagregations: Adult(15+), 10-14, 5-9, 2-4

* Add EC1 patient listing report, with the patient id and patient idenifier added

* Add gender, name, DOB and a gender converter to the EC1 dataset

* Add a calculation data definition that will be used to evaluate calcultion data

* Add a calculation to determine whether a birthdate is estimated or exact

* D2: Number of active, unstable, patients on ART with complete and respective  disaggregations.

* Added a patient object calculation that can be reused

* Correct the bug on the TxCurr. Had not pass the parameters in the DSD dataset.

* Add the pregnancy criteria and the encounter date columns

* Add the remaining columns to the EC1 data set including the patient status

* Added N1 Indicator with the following set of diaggregations:
	*Total
	*Stable subtotal
	*Unstable subtotal
	*Non-pregnant and Non-Breastfeeding Adults (>=15) stable and unstable
	*Non-pregnant and Non-Breastfeeding Children (2-4, 5-9, 10-14) stable and unstable

* Add properties to enable addition of the columns on the template

* Map the data elements on a report template for the EC1 indicator

* Change the calculations for BNP and PNB to pick active and unstable patient and not TxCurr as before.

* Added the breastfeeding not pregnant and pregnant not breastfeeding disaggregations to the Unstable Active who participate in DSD model

* Poppulate the EC2 dataset and have respective mappings on the excel template

* Initial work on EC3, creation of dataset, link to report definiton and map common columns

* Added N2 Indicator with stable and unstable calculations.

* Add EC3 and EC4 with the common columns mapped and linked to the report defintition

* Added the datasets for the EC5 and EC6 and updated the templates with the common columns

* Mapping of common columns on the template for EC7 to EC14

* Provide respective datasets for the EC7 to EC15 and add licence information

* Provide dataset mappings to the report definition for EC7 to EC15 and options for the repeating sections to be used on the templates

* Corrected the bug on the patientsWhoAreStable method.
Added the diaggregations for N2 Indicator.
Added the N3 indicator, stable and unstable shell.

* Added N3 Indicator Breastfeeding Not Pregnant and Pregnant Not Breastfeeding cohort definitions and respective disaggregations

* Map the remaining datasets to their respective values and report defintion

* Rewrote NextAndPrevDates Calculation for resuse in in N2 and N3 Indicators.
Added scheduled patients based on N3 Indicator Filter criteria.

* Added N4 indicator with respective disaggregations

* Adjust the negative age criteria to include those patients ahving birthdate after date when they were created in the system

* Added the SQl query that returns the patients enrolled in the GAAC program needed in indicator N4.

* Mapped the Indicators to the report template
Corrected the Calculations to include breastfeeding patients on the BP disaggregation.

* Completed all custom columns for the EC3 and code improvements

* Remove temporary files

* Added custom columns for the EC4 and map them on the template

* Added the custom columns for the EC5 and mapped them to the excel template

* Add custom columns for the EC6 and it corresponding mappings on the excel template

* Added EC7 custom columns and provide its mappings

* Add EC8 custom columns and map to the template

* Reuse of the already existing Birthdate class to compute the estimated date of birth

* Add EC9 custom columns and provide its mapping on the template

* Add the custom columns for the EC10 and provide mappings to the template

* Added custom columns to the EC11 and provide its corresponding mappings

* Add EC12 custom columns and provide the mappings to the template

* Added EC12 and EC13 and map them on the template

* Add the remaining EC14 custom columns and provide its mapping to the template

* Reuse of the available code in the reporting API other than duplicating

* Include the patients who are marked as deceased to those marked as dead in the patient states

* Added the logic to the N1 indicator
Added a filter to allEncounter in the EPTS Calculation service to limit the amount of information queried.
Performance: imported the dependencies explicitly.

* Adding death and deceased cohort to EC3,EC4 and EC5, including the location list in the dead criteria as opposed to one location and mapping remaing columns on to the EC11 patient listing

* Resused the hasObs method in the Generic cohort queries class.
Deleted the custom made valudeCoded method.

* Resused the hasNumericObs method in the GenericCohortQueries class.
Deleted the valueNumeric method in the EriDSDCohortQueries class.

* Include a list of locations to the calculation data definition

* Added logic to filter program workflows states based on the ART program

* Uncommented the other datasets of the IMER report

* Reused inbuilt functionality in the API for gender columns

* Reusing already existing and optimized reporting objects

* Move parameters specific to the data quality report in a separate class such that ic=t can be extended separately

* Corrected the D1 indicator Criteria 5Ci to include age for both the absolute and percerntage CD4

* Overload the getIndicator method to accepts several parameters as passed at dataset level

* Added N1 Indicator concepts(New)

* Refer parameters from the report design for the data quality datasets

* Added proper logic (Concepts) to the N1 Indicator.
Added Start Drugs and Continue Regimen concepts.

* Make ART identifier type configurable and get rid of static methods in the commonUtils class so as to reuse other components from elsewhere in it

* Rewrite the date created, date changed and date of death from using PatientDemographicsCalculation to native sql passed in SqlPatientDataDefinition thereby avoiding converters

* Remove the data converters in all the common columns by just using native sql

* Moving getArtProgramConfigurableParameter method into a EptsReportUtils class

* Move data definitions in a separate file and package

* Convert EC15 and EC14 to use sqlDatasetdefinitions as oppossed to patientDatasetDefinition

* Added EC13 to use sql dataset definitions other that patient dataset defintion

* Added EC12 patient listing on the web using Sql dataset definition

* Started working on Tests: NextAndPrevCalculationTest

* Converting EC11 to use sql dataset definition and mapping to excel template

* Added EC10 to use sql dataset definition and mapped to the template

* Remove duplicate code in the indicator dataset

* Added EC9 as an sql dataset definition and mapped on the excel template

* Add 2 missing columns on EC10 patient listing

* Adding more encounter types to the EC11 criteria

* Add the pending columns for the EC11 using the IF function from mysql and mapped to excel template

* Only limiting to the encounter types needed for EC10

* format date fields correctly

* Added EC8 as an sal dataset definition and provide its mappings

* Add EC7 dataset using sql data set definition and provided mappings to excel

* Added EC6 dataset as an sql dataset definition and provided its corresponding mappings

* Add EC5 and EC4 datasets as sql dataset definitions

* Add EC3 as a dataset of type sql dataset definition and provides its mappings

* General clean up of code structure

* Only list identifier type of ART and NOT any other

* provide names to the patients states numbers

* Only pick tha non voided encounters

* Only diplay the last consulatation encounter for the patient as oppssed to all that appeared after a specfic date

* Initial set up of EC1 and EC2 to use sql dataset definition instead of calculation classes

* Adding initial columns for the EC1 and EC2 using sql dataset definition as oppossed to patient dataset definition

* General code clean up and removal of unused classes

* Filter the pregnant male at the sql level and avoid a composition of two queries to accomplish the same

* Added the prginancy filter query to the EC1 sql dataset

* Add EC1 that combine the pregnant male and those enrolled into program

* Include a list of patients who are marked as deceased to the EC3 data set

* Add deceased patients to the EC4 dataset

* Include the deceased patients in the EC5 dataset

* Rewriting of the breastfeeding query to be used for the EC2 indicator aggreagtion

* Removed custom exception to rather use ReportException made available by the reporting framework

* Renamed getArtProgramConfigurableParameter by removing 'Art' since the function is generic for all programs

* Code auto formatting changes

* Add the complete list of the EC2 dataset

* Refatoring code to handle each dataset separately

* Commented out Indicator N1 that is not part of the July release. All the code is in place, to run the indicator in future, just uncomment the N1 methods in the EriDSDCohortQueries class.

* Comment indicator N1 in the EriDSDDataset class.

* Changed the composition string for the stable patients, DSD D1.

* Created a new query to fetch pregnant patients in the last 9 months from endDate. Used the query across the DSD indicators.

* Mepts 193 dsd indicators im er report (#114)

* Setup for the DSD D1 Indicator Total.

* Added Total Tag to the excel report. The Total value still not reflecting,currently outputing a zero.

* Added OnArtForAtleastXmonthsCalculation class for the DSD D1. Currently testing the step 5 of the requirments document for the indicator.

* Added 5a Cohort Definition

* Added Criteria 5 b: reused the alreday existing Viral load method.
Added Criteria 5C(i): getCD4CountAndCD4Percent

* Combined criteria 5C i and ii into one criteria.

* Added Criteria 5D: Patient with active clinical condition of WHO stage 3 and 4.
Rearranged the methods for proper readability and commenting.

* Added missing concepts in the hivmetadata, 1692-1699, 821, 16, 1406,adverse reactions, poor adherence
5f: No adverse reactions to medication criteria.

* Added 5E : Poor adherence in last 3  clinical visits

* Added the missing concept UUIDs to the global properties configurations.

* 5A, 5B working

* Fixed bgs on the Criteria 5 sub queries
Added dissagregations: Adult(15+), 10-14, 5-9, 2-4

* D2: Number of active, unstable, patients on ART with complete and respective  disaggregations.

* Correct the bug on the TxCurr. Had not pass the parameters in the DSD dataset.

* Added N1 Indicator with the following set of diaggregations:
	*Total
	*Stable subtotal
	*Unstable subtotal
	*Non-pregnant and Non-Breastfeeding Adults (>=15) stable and unstable
	*Non-pregnant and Non-Breastfeeding Children (2-4, 5-9, 10-14) stable and unstable

* Change the calculations for BNP and PNB to pick active and unstable patient and not TxCurr as before.

* Added the breastfeeding not pregnant and pregnant not breastfeeding disaggregations to the Unstable Active who participate in DSD model

* Added N2 Indicator with stable and unstable calculations.

* Corrected the bug on the patientsWhoAreStable method.
Added the diaggregations for N2 Indicator.
Added the N3 indicator, stable and unstable shell.

* Added N3 Indicator Breastfeeding Not Pregnant and Pregnant Not Breastfeeding cohort definitions and respective disaggregations

* Rewrote NextAndPrevDates Calculation for resuse in in N2 and N3 Indicators.
Added scheduled patients based on N3 Indicator Filter criteria.

* Added N4 indicator with respective disaggregations

* Added the SQl query that returns the patients enrolled in the GAAC program needed in indicator N4.

* Mapped the Indicators to the report template
Corrected the Calculations to include breastfeeding patients on the BP disaggregation.

* Added the logic to the N1 indicator
Added a filter to allEncounter in the EPTS Calculation service to limit the amount of information queried.
Performance: imported the dependencies explicitly.

* Resused the hasObs method in the Generic cohort queries class.
Deleted the custom made valudeCoded method.

* Resused the hasNumericObs method in the GenericCohortQueries class.
Deleted the valueNumeric method in the EriDSDCohortQueries class.

* Uncommented the other datasets of the IMER report

* Corrected the D1 indicator Criteria 5Ci to include age for both the absolute and percerntage CD4

* Added N1 Indicator concepts(New)

* Added proper logic (Concepts) to the N1 Indicator.
Added Start Drugs and Continue Regimen concepts.

* Started working on Tests: NextAndPrevCalculationTest

* Commented out Indicator N1 that is not part of the July release. All the code is in place, to run the indicator in future, just uncomment the N1 methods in the EriDSDCohortQueries class.

* Comment indicator N1 in the EriDSDDataset class.

* Changed the composition string for the stable patients, DSD D1.

* Created a new query to fetch pregnant patients in the last 9 months from endDate. Used the query across the DSD indicators.

* Added Breastfeeding Query

* Added the Breastfeeding queries for DSD and corrected the bugs on the pregnant queries.

* Added default value for program parameter to select all states by default

* Passing parameters using the String format for the pregnant indicator

* Updated the excel template report, removed N1 indicator. Renamed the indicators to fit the updated user stories.

* Format the breastfeeding indicator query for data quality using String format method for readbilty

* Finished mapping SummaryQueries to use String format method to pass parameters

* Find birthdates that are after any drug pick up encounters for EC15

* Looking for any encounter as oppossed to the last one for the EC11

* Removing the MAX function from the EC10 patient listing sub query

* Remove the MAX function in the EC9 patient listing sub query

* Look for any encounter filled after specific dates as oppossed to last encounter for EC5,EC6 and EC7

* Pick any encounter from as oppossed to LAST for the EC3 and EC4 patient listing datasets

* Including the right encounter types for the EC2 BC3 criteria, both in the indicator and the patient listing

* Provide proper column labelling for EC1 and EC2 following review comments

* EC3 - correct template date of death label and pick the first encounter after death date as adviced by reviews and BA team

* Corrected the Non Pregnant and Non Breastfeeding disggregations for D2

* Made Changes to D1, N1, N2 and N3 on Non Pregnant and No Breastfeeding disaggregations.

* Correcting the breastfeeding label for EC2 and getting distinct rows per the consultations after the met conditions

* Provide the right translation for the EC2 dataset

* Fix a bug in the indicator for the EC15

* Produce only the first row of an encounter after the fail check for EC15

* Pick the first consulations for the EC7 patient listing

* produce unique rows for the EC6 patient listing

* Fixing of EC5 following review and including boundaries in the summary queries

* Match the boundaries and only select unique rows per the ealierst drug pick up date for EC9

* Adding boundaries to EC10 and picking unique rows based on the first consultation date

* Added boundaries to EC8 patient listing

* Adding boundaries to EC11 and picking unique rows based on the consulations encounters

* Add boindaries to the EC7 patient listing data set and pick the first consulatations

* Add boundaries to EC6 and pick the unique rows per the consultations

* Added boundaries to the EC4 patient listing and pick the first entry per the consulation fail criteria

* Removed e from the criteria

* Add boundaries to the EC3 patient listing dataset and pick the first occurence of the consulations

* Restrict EC5 patient listing to only check the lab encounter and return first occurence of such encounters

* Restrictin EC8 to only use the laboratory form and return the first row that occure after the criteria

* Restrict EC11 to only look at the lab encounter and return first row after the fail state

* Changed the calculations On ART atleast x months.

* Added the new composition string for Criteria 5

* Update the template with the latest v3

* Match the state criteria with the consultations encounter dates

* Remove unused rows and columns from the report template

* Adjustments to DSD stable query, criteria D and F to closer match user stories

* Simplified DSD stable criteria C composition query to make logic clearer

* Added new query for Viral load for the DSD report

* Adding mechanisms to get custom columns for the configurations

* Adding custom columns to the configuration dataset

* Added a new query to pick the patients who are on WHO stage 3 and 4

* Changed the query paremeter, annded the endDate parameter.

* Fix a bug on the template for the value of EC15 and simplify the query

* Clean up, removal of redundand code snippets and optimization of the EC3 to EC10 patient listing queries

* Optimize EC11 and remove redundant code

* Updated the DSD criteria 5d to correctly fetch the encounter matching the max datetime

* Optimize the EC12 query and remove repetitive code

* Updated the DSD criteria C to include lab encounters for check when CD4 counts are greater than 200

* Remove of the ART patient identifier type on the details reports so as to match the summary

* DSD report fixed parameter mappings in DSD dataset

* Reverting CD4 operator back to GREATER_THAN to closer match specs

* Fixed DSD criteria 5a to include location in query

* Added a custom dataset to handle the time needed by the report and also to include other parameters

* Add program workflow states in a match readable format

* Format report period to standard dates

* Changed the NextAndPrev Calculation to be reused for N1 and N2, passing parameters dynamically.

* Updated DSD indicators to use the TxNew pregnancy and breastfeeding queries

* Removed unused pregnant and breastfeeding queries for DSD

* Removed unused locations parameter

* Rewriting EC3,EC4 and EC5 to consider those patients who are marked as dead in the person object when comparing such dates with encounters, before we were only checking for the patient state which excluded those

* Corrected the order of upperbound and lowerbound

* DSD report fixed one missing pregnant parameter

* Updated DSD next and previous claculation, still broken though

* DSD report: fixed bug in next and previous calculation for returning single object results

* Fixed stable and unstable quuries for N1 and N2 indicators in DSD to match columns correctly

* DSD report Separated unstable from stable functions which were overlapping

* Changed the N2 subtotal for stable patients.

* Made changes to the N2 stable subtotal

* changed the excel mapping on N1 disggregations

* Added the location parameter to the patientsWhoStable cd

* Added the startDate [aremeter to the Patients who are stable Cohhort Definition

* Added the relevant mappings to the queries.

* DSD report updated breastfeeding and pregnant queries to closer match user story specs

* Corrected the pregnant query for closer matcg to user story specs

* Made changes to the N3 unstable subtotal to include pregnant and breastfeeding patients

* DSD fix for N2 to properly pick the next appointment observation record

* DSD report NextandPrev calculation updated to add a condition if an obs does not have a value_datetime to prevent null pointer Exception

* formatting change

* DSD report: rewrote the LACTANTE query for breastfeeding query to properly pick obs

* DSD report: fixed bug with the unstable subtotals to remove the dependency between the disaggs and the subtotal cohorts

* DSD report: rewrote the INICIOLACTANTE query for breastfeeding cohort to properly pick obs records

* DSD report: updated WHO query to remove inner join on obs so we pick encounters without obs correctly

* Re-enabled the IM-ER indicators
  • Loading branch information
ningosi authored and Nathan Floor committed Aug 2, 2019
1 parent bd26796 commit bdc72af
Show file tree
Hide file tree
Showing 61 changed files with 5,845 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.openmrs.Concept;
import org.openmrs.EncounterType;
import org.openmrs.PatientIdentifierType;
import org.openmrs.Program;
import org.openmrs.ProgramWorkflow;
import org.openmrs.ProgramWorkflowState;
Expand All @@ -28,7 +29,7 @@ public class HivMetadata extends ProgramsMetadata {

private String gpPtvEtvProgramUuid = "eptsreports.ptvEtvProgramUuid";

// Concepts
// Concepts Id = 856
public Concept getHivViralLoadConcept() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.hivViralLoadConceptUuid");
Expand Down Expand Up @@ -310,6 +311,140 @@ public Concept getCD4AbsoluteConcept() {
Context.getAdministrationService().getGlobalProperty("eptsreports.cd4AbsolutoUuid");
return getConcept(uuid);
}
// concept_id=730
public Concept getCD4PercentConcept() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.cd4PercentUuid");
return getConcept(uuid);
}
// concept_id=1714
public Concept getAdherence() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.poorAdherenceUuid");
return getConcept(uuid);
}
// concept_id=2015
public Concept getAdverseReaction() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.adverseReactionUuid");
return getConcept(uuid);
}
// Concept 6292
public Concept getNeutropenia() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.neutropenia");
return getConcept(uuid);
}
// Concept 6293
public Concept getPancreatitis() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.pancreatitis");
return getConcept(uuid);
}
// Concept 6294
public Concept getHepatotoxicity() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.hepatotoxicity");
return getConcept(uuid);
}
// Concept 6295
public Concept getPsychologicalChanges() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.psychologicalChanges");
return getConcept(uuid);
}
// Concept 6296
public Concept getMyopathy() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.myopathy");
return getConcept(uuid);
}
// Concept 6297
public Concept getSkinAllergy() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.skinAllergy");
return getConcept(uuid);
}
// Concept 6298
public Concept getLipodystrophy() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.lipodystrophy");
return getConcept(uuid);
}
// Concept 6299
public Concept getLacticAcidosis() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.lacticAcidosis");
return getConcept(uuid);
}
// Concept 821
public Concept getPeripheralNeuropathy() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.peripheralNeuropathy");
return getConcept(uuid);
}
// Concept 16
public Concept getDiarrhea() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.diarrhea");
return getConcept(uuid);
}
// Concept 1406
public Concept getOtherDiagnosis() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.otherDiagnosis");
return getConcept(uuid);
}
// Concept 23724 GAAC
public Concept getGaac() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.gaac");
return getConcept(uuid);
}
// Concept 23725 AF
public Concept getFamilyApproach() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.familyApproach");
return getConcept(uuid);
}
// Concept 23726 CA
public Concept getAccessionClubs() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.accessionClubs");
return getConcept(uuid);
}
// Concept 23727 PU
public Concept getSingleStop() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.singleStop");
return getConcept(uuid);
}
// Concept 23729 FR
public Concept getRapidFlow() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.rapidFlow");
return getConcept(uuid);
}
// Concept 23730 DT
public Concept getQuarterlyDispensation() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.quarterlyDispensation");
return getConcept(uuid);
}
// Concept 23731 DC
public Concept getCommunityDispensation() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.communityDispensation");
return getConcept(uuid);
}
// Concept 23732 Other Model
public Concept getAnotherModel() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.anotherModel");
return getConcept(uuid);
}
// Concept 1256 Start Drugs
public Concept getStartDrugs() {
String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.startDrugs");
return getConcept(uuid);
}
// Concept 1257 Continue Regimen
public Concept getContinueRegimen() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.continueRegimen");
return getConcept(uuid);
}

// Encounter types
// encounterType_id = 6
public EncounterType getAdultoSeguimentoEncounterType() {
Expand Down Expand Up @@ -432,6 +567,13 @@ public Program getHIVCareProgram() {
return getProgram(uuid);
}

// Identifier types
public PatientIdentifierType getNidServiceTarvIdentifierType() {
String uuid =
Context.getAdministrationService().getGlobalProperty("eptsreports.nidServicoTarvUuid");
return getPatientIdentifierType(uuid);
}

// Program Workflow States
public ProgramWorkflowState getTransferredOutToAnotherHealthFacilityWorkflowState() {
String artProgramUuid = Context.getAdministrationService().getGlobalProperty(gpArtProgramUuid);
Expand Down Expand Up @@ -548,6 +690,7 @@ public ProgramWorkflowState getPateintTransferedFromOtherFacilityHIVCareWorkflow
return getProgramWorkflowState(hivCareProgramUuid, "1", "TRANSFER FROM OTHER FACILITY");
}

// Concept 5356
public Concept getCurrentWHOHIVStageConcept() {
return getConcept(
Context.getAdministrationService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,39 @@ public CalculationResultMap allProgramEnrollment(
return EptsCalculationUtils.evaluateWithReporting(def, cohort, null, null, context);
}

/**
* Evaluates the encounter of a given type of each patient for specified qualifier
*
* @param encounterTypes
* @param qualifier
* @param location
* @param context
* @return
*/
public CalculationResultMap getEncounter(
List<EncounterType> encounterTypes,
TimeQualifier qualifier,
Collection<Integer> cohort,
Location location,
Date onOrBefore,
PatientCalculationContext context) {
EncountersForPatientDataDefinition def = new EncountersForPatientDataDefinition();
if (qualifier != null) {
def.setWhich(qualifier);
} else {
def.setWhich(TimeQualifier.ANY);
}
def.setOnOrBefore(onOrBefore);
def.setLocationList(Arrays.asList(location));
if (encounterTypes != null) {
def.setName("first encounter ");
def.setTypes(encounterTypes);
} else {
def.setName("first encounter of any type");
}
return EptsCalculationUtils.evaluateWithReporting(def, cohort, null, null, context);
}

/**
* Evaluates the first encounter of a given type of each patient
*
Expand All @@ -172,6 +205,33 @@ public CalculationResultMap firstEncounter(
}
return EptsCalculationUtils.evaluateWithReporting(def, cohort, null, null, context);
}
/**
* Evaluates all encounters of a given type of each patient
*
* @param encounterTypes
* @param cohort
* @param location
* @param context
* @return all encounters for the patients
*/
public CalculationResultMap allEncounters(
List<EncounterType> encounterTypes,
Collection<Integer> cohort,
Location location,
Date onOrBefore,
PatientCalculationContext context) {
EncountersForPatientDataDefinition def = new EncountersForPatientDataDefinition();
def.setWhich(TimeQualifier.ANY);
def.setLocationList(Arrays.asList(location));
def.setOnOrBefore(onOrBefore);
if (encounterTypes != null) {
def.setName("all encounters ");
def.setTypes(encounterTypes);
} else {
def.setName("all encounters of any type");
}
return EptsCalculationUtils.evaluateWithReporting(def, cohort, null, null, context);
}

/**
* Evaluates the first Obs for a given question and answer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.openmrs.module.eptsreports.reporting.calculation.dsd;

import java.util.*;
import org.openmrs.*;
import org.openmrs.api.context.Context;
import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.calculation.result.ListResult;
import org.openmrs.module.eptsreports.reporting.calculation.AbstractPatientCalculation;
import org.openmrs.module.eptsreports.reporting.calculation.BooleanResult;
import org.openmrs.module.eptsreports.reporting.calculation.common.EPTSCalculationService;
import org.openmrs.module.eptsreports.reporting.utils.EptsCalculationUtils;
import org.openmrs.module.reporting.common.TimeQualifier;
import org.springframework.stereotype.Component;

@Component
public class NextAndPrevDatesCalculation extends AbstractPatientCalculation {
@Override
public CalculationResultMap evaluate(
Collection<Integer> cohort,
Map<String, Object> parameterValues,
PatientCalculationContext context) {

EPTSCalculationService ePTSCalculationService =
Context.getRegisteredComponents(EPTSCalculationService.class).get(0);

Date onOrBefore = (Date) context.getFromCache("onOrBefore");
Location location = (Location) context.getFromCache("location");
CalculationResultMap map = new CalculationResultMap();
Concept concept = (Concept) parameterValues.get("conceptId");
Integer lowerBound = (Integer) parameterValues.get("lowerBound");
Integer upperBound = (Integer) parameterValues.get("upperBound");
List<EncounterType> encounterTypes =
(List<EncounterType>) parameterValues.get("encounterTypes");

// Step 1: Search for last encounter visit for this patient
CalculationResultMap lastEncounterMap =
ePTSCalculationService.getEncounter(
encounterTypes, TimeQualifier.LAST, cohort, location, onOrBefore, context);

// Step 2.1: Search for next return drug pick/appointment for patient
CalculationResultMap lastReturnVisitObsMap =
ePTSCalculationService.getObs(
concept,
encounterTypes,
cohort,
Arrays.asList(location),
null,
TimeQualifier.ANY,
null,
context);

for (Integer pId : cohort) {
boolean scheduled = false;
ListResult returnVisitObsResult = (ListResult) lastReturnVisitObsMap.get(pId);
List<Obs> returnVisitList = EptsCalculationUtils.extractResultValues(returnVisitObsResult);
Encounter lastEncounter = EptsCalculationUtils.resultForPatient(lastEncounterMap, pId);
Obs lastReturnVisitObs = null;

// Step 2.2: identify last return visit obs record
Iterator<Obs> iterator = returnVisitList.iterator();
while (iterator.hasNext()) {
Obs obs = iterator.next();
if (obs.getVoided()
|| obs.getEncounter() == null
|| (obs.getEncounter() != null
&& (obs.getEncounter().getEncounterId() != lastEncounter.getEncounterId()))) {
iterator.remove();
}
}
Collections.sort(
returnVisitList,
new Comparator<Obs>() {
@Override
public int compare(Obs obs, Obs t1) {
return t1.getValueDate().compareTo(obs.getValueDatetime());
}
});

if (returnVisitList.size() > 0) {
lastReturnVisitObs = returnVisitList.get(returnVisitList.size() - 1);
}

// Step 3: compare against boundaries
if (lastEncounter != null
&& lastReturnVisitObs != null
&& lastReturnVisitObs.getValueDate() != null) {

Date lowerBoundary =
EptsCalculationUtils.addDays(lastEncounter.getEncounterDatetime(), lowerBound);
Date upperBoundary =
EptsCalculationUtils.addDays(lastEncounter.getEncounterDatetime(), upperBound);

if (lastReturnVisitObs.getValueDate().compareTo(lowerBoundary) >= 0
&& lastReturnVisitObs.getValueDate().compareTo(upperBoundary) <= 0) {
scheduled = true;
}
}

map.put(pId, new BooleanResult(scheduled, this));
}
return map;
}
}
Loading

0 comments on commit bdc72af

Please sign in to comment.