Skip to content

Commit

Permalink
Merge pull request #1045 from gabriel090/KHP3-285
Browse files Browse the repository at this point in the history
KHP3-285: KNH/KDO patient summary
  • Loading branch information
patryllus authored Apr 8, 2022
2 parents e2aafdc + ea2c578 commit 00a48da
Show file tree
Hide file tree
Showing 11 changed files with 2,482 additions and 1,561 deletions.
18 changes: 18 additions & 0 deletions api/src/main/distro/metadata/concepts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,22 @@
<ref key= "TRF_VERIFICATION_DATE" uuid="164133AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "TRF_OUT_VERIFIED" uuid="1285AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "LOST_TO_FOLLOWUP" uuid="5240AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "PULSE_RATE" uuid="5087AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "BLOOD_PRESSURE" uuid="5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "BLOOD_PRESSURE_1" uuid="5086AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "RESPIRATORY_RATE" uuid="5242AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "OXYGEN_SATURATION" uuid="5092AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "LMP" uuid="1427AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "TB_START_DATE" uuid="1113AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "TB_END_DATE" uuid="159431AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" />
<ref key= "CACX_SCREENING" uuid="06398e78-0d3e-43d5-8017-f2fc3865e2e0" />
<ref key= "TB_SCREENING" uuid="cddbf6fe-4bcd-40b6-a7ea-8573e4080192" />
<ref key= "STI_SCREENING" uuid="ec1b6d72-728f-4ab0-a4e4-7335731075b9" />
<ref key= "KDOD_NUMBER" uuid="b51ffe55-3e76-44f8-89a2-14f5eaf11079" />
<ref key= "KDOD_CADRE" uuid="96a99acd-2f11-45bb-89f7-648dbcac5ddf" />
<ref key= "KDOD_RANK" uuid="9f1f8254-20ea-4be4-a14d-19201fe217bf" />
<ref key= "KDOD_UNIT" uuid="848f5688-41c6-464c-b078-ea6524a3e971" />



</refs>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* 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.hiv.art;
import org.openmrs.Obs;
import org.openmrs.Patient;
import org.openmrs.Program;
import org.openmrs.api.PatientService;
import org.openmrs.api.PersonService;
import org.openmrs.api.context.Context;
import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.calculation.result.SimpleResult;
import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation;
import org.openmrs.module.kenyacore.calculation.Calculations;
import org.openmrs.module.kenyacore.calculation.Filters;
import org.openmrs.module.kenyaemr.Dictionary;
import org.openmrs.module.kenyaemr.calculation.EmrCalculationUtils;
import org.openmrs.module.kenyaemr.metadata.MchMetadata;
import org.openmrs.module.metadatadeploy.MetadataUtils;

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

/**
* Calculate the bmi at last visit
*/
public class BMICalculation extends AbstractPatientCalculation {

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

CalculationResultMap weightMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.WEIGHT_KG), cohort, context);
CalculationResultMap heightMap = Calculations.lastObs(Dictionary.getConcept(Dictionary.HEIGHT_CM), cohort, context);


PersonService service = Context.getPersonService();


CalculationResultMap ret = new CalculationResultMap();
for (Integer ptId : cohort) {

Double visitWeight = null;
Double visitHeight = null;
String bmiStr = null;

Obs lastWeightObs = EmrCalculationUtils.obsResultForPatient(weightMap, ptId);
Obs lastHeightObs = EmrCalculationUtils.obsResultForPatient(heightMap, ptId);
//find pregnancy obs

if (lastHeightObs !=null && lastWeightObs != null ){
visitHeight = lastHeightObs.getValueNumeric();
visitWeight = lastWeightObs.getValueNumeric();
Double bmi = visitWeight / ((visitHeight/100) * (visitHeight/100));
bmiStr = String.format("%.2f", bmi);
ret.put(ptId, new SimpleResult(bmiStr, this, context));
}
}
return ret;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* 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.hiv.art;

import org.openmrs.Concept;
import org.openmrs.Obs;
import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.calculation.result.ListResult;
import org.openmrs.calculation.result.SimpleResult;
import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation;
import org.openmrs.module.kenyacore.calculation.CalculationUtils;
import org.openmrs.module.kenyacore.calculation.Calculations;
import org.openmrs.module.kenyaemr.Dictionary;
import org.openmrs.module.kenyaemr.calculation.EmrCalculationUtils;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;


public class BloodPressureCalculation extends AbstractPatientCalculation {

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

Concept currentBloodPressure = Dictionary.getConcept(Dictionary.BLOOD_PRESSURE);
CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), cohort, context);
CalculationResultMap bloodPressureObss = Calculations.allObs(currentBloodPressure, cohort, context);

CalculationResultMap ret = new CalculationResultMap();
for (Integer ptId : cohort) {
SimpleResult result = null;
Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId);
ListResult bloodPressureObsResult = (ListResult) bloodPressureObss.get(ptId);

if (artStartDate != null && bloodPressureObsResult != null && !bloodPressureObsResult.isEmpty()) {
List<Obs> bloodPressure = CalculationUtils.extractResultValues(bloodPressureObsResult);
Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(bloodPressure, artStartDate);

if (lastBeforeArtStart != null) {
Double bloodPressureValue = lastBeforeArtStart.getValueNumeric();
if (bloodPressureValue != null) {
result = new SimpleResult(bloodPressureValue, this);
}
}
}

ret.put(ptId, result);
}
return ret;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* 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.hiv.art;

import org.openmrs.Concept;
import org.openmrs.Obs;
import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.calculation.result.ListResult;
import org.openmrs.calculation.result.SimpleResult;
import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation;
import org.openmrs.module.kenyacore.calculation.CalculationUtils;
import org.openmrs.module.kenyacore.calculation.Calculations;
import org.openmrs.module.kenyaemr.Dictionary;
import org.openmrs.module.kenyaemr.calculation.EmrCalculationUtils;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;


public class HeightAtArtInitiationCalculation extends AbstractPatientCalculation {

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

Concept currentHeight = Dictionary.getConcept(Dictionary.HEIGHT_CM);
CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), cohort, context);
CalculationResultMap heightObss = Calculations.allObs(currentHeight, cohort, context);

CalculationResultMap ret = new CalculationResultMap();
for (Integer ptId : cohort) {
SimpleResult result = null;
Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId);
ListResult heightObsResult = (ListResult) heightObss.get(ptId);

if (artStartDate != null && heightObsResult != null && !heightObsResult.isEmpty()) {
List<Obs> height = CalculationUtils.extractResultValues(heightObsResult);
Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(height, artStartDate);

if (lastBeforeArtStart != null) {
Double heightValue = lastBeforeArtStart.getValueNumeric();
if (heightValue != null) {
result = new SimpleResult(heightValue, this);
}
}
}

ret.put(ptId, result);
}
return ret;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* 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.hiv.art;

import org.openmrs.Concept;
import org.openmrs.Obs;
import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.calculation.result.ListResult;
import org.openmrs.calculation.result.SimpleResult;
import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation;
import org.openmrs.module.kenyacore.calculation.CalculationUtils;
import org.openmrs.module.kenyacore.calculation.Calculations;
import org.openmrs.module.kenyaemr.Dictionary;
import org.openmrs.module.kenyaemr.calculation.EmrCalculationUtils;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;


public class LMPCalculation extends AbstractPatientCalculation {

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

Concept currentLMP = Dictionary.getConcept(Dictionary.LMP);
CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), cohort, context);
CalculationResultMap lmpObss = Calculations.allObs(currentLMP, cohort, context);

CalculationResultMap ret = new CalculationResultMap();
for (Integer ptId : cohort) {
SimpleResult result = null;
Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId);
ListResult lmpObsResult = (ListResult) lmpObss.get(ptId);

if (artStartDate != null && lmpObsResult != null && !lmpObsResult.isEmpty()) {
List<Obs> lmp = CalculationUtils.extractResultValues(lmpObsResult);
Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(lmp, artStartDate);

if (lastBeforeArtStart != null) {
Double lmpValue = lastBeforeArtStart.getValueNumeric();
if (lmpValue != null) {
result = new SimpleResult(lmpValue, this);
}
}
}

ret.put(ptId, result);
}
return ret;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* 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.hiv.art;

import org.openmrs.Concept;
import org.openmrs.Obs;
import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.calculation.result.ListResult;
import org.openmrs.calculation.result.SimpleResult;
import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation;
import org.openmrs.module.kenyacore.calculation.CalculationUtils;
import org.openmrs.module.kenyacore.calculation.Calculations;
import org.openmrs.module.kenyaemr.Dictionary;
import org.openmrs.module.kenyaemr.calculation.EmrCalculationUtils;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;


public class OxygenSaturationCalculation extends AbstractPatientCalculation {

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

Concept currentOxygenSaturation = Dictionary.getConcept(Dictionary.OXYGEN_SATURATION);
CalculationResultMap artStartDates = calculate(new InitialArtStartDateCalculation(), cohort, context);
CalculationResultMap oxygenSaturationObss = Calculations.allObs(currentOxygenSaturation, cohort, context);

CalculationResultMap ret = new CalculationResultMap();
for (Integer ptId : cohort) {
SimpleResult result = null;
Date artStartDate = EmrCalculationUtils.datetimeResultForPatient(artStartDates, ptId);
ListResult oxygenSaturationObsResult = (ListResult) oxygenSaturationObss.get(ptId);

if (artStartDate != null && oxygenSaturationObsResult != null && !oxygenSaturationObsResult.isEmpty()) {
List<Obs> oxygenSaturation = CalculationUtils.extractResultValues(oxygenSaturationObsResult);
Obs lastBeforeArtStart = EmrCalculationUtils.findLastOnOrBefore(oxygenSaturation, artStartDate);

if (lastBeforeArtStart != null) {
Double oxygenSaturationValue = lastBeforeArtStart.getValueNumeric();
if (oxygenSaturationValue != null) {
result = new SimpleResult(oxygenSaturationValue, this);
}
}
}

ret.put(ptId, result);
}
return ret;
}
}
Loading

0 comments on commit 00a48da

Please sign in to comment.