Skip to content

Commit

Permalink
Merge pull request #164 from Werick/upn-revised
Browse files Browse the repository at this point in the history
KenyEmr Ehancements
  • Loading branch information
alaboso authored Oct 31, 2016
2 parents 978534e + d488a4b commit ccc4498
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public String getNextHivUniquePatientNumber(String comment) {

String prefix = Context.getService(KenyaEmrService.class).getDefaultLocationMflCode();
String sequentialNumber = Context.getService(IdentifierSourceService.class).generateIdentifier(source, comment);
return prefix + sequentialNumber;
return prefix+sequentialNumber;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.openmrs.module.kenyaemr.calculation.library;

import org.openmrs.Patient;
import org.openmrs.PatientProgram;
import org.openmrs.Program;
import org.openmrs.api.context.Context;
import org.openmrs.calculation.patient.PatientCalculationContext;
import org.openmrs.calculation.patient.PatientCalculationService;
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.CalculationUtils;
import org.openmrs.module.kenyaemr.Metadata;
import org.openmrs.module.reporting.cohort.EvaluatedCohort;
import org.openmrs.module.reporting.cohort.definition.InProgramCohortDefinition;

import java.util.*;

/**
* Created by dev on 9/24/16.
*/
public class PatientProgramCalculation extends AbstractPatientCalculation {
@Override
public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> map, PatientCalculationContext context) {
CalculationResultMap ret = new CalculationResultMap();
InProgramCohortDefinition cd = new InProgramCohortDefinition();
List<Program> programs = new ArrayList<Program>();
programs.add(Context.getProgramWorkflowService().getProgramByUuid(Metadata.Program.HIV));
programs.add(Context.getProgramWorkflowService().getProgramByUuid(Metadata.Program.MCH_CS));
programs.add(Context.getProgramWorkflowService().getProgramByUuid(Metadata.Program.MCH_MS));
programs.add(Context.getProgramWorkflowService().getProgramByUuid(Metadata.Program.TB));
cd.setPrograms(programs);

EvaluatedCohort patientProgramCohort = CalculationUtils.evaluateWithReporting(cd, cohort, null, context);

Map<String, Object> params = new HashMap<String, Object>();
params.put("program", programs.get(0));
CalculationResultMap hivProgram = new InProgramCalculation().evaluate(cohort, params, Context.getService(PatientCalculationService.class).createCalculationContext());

params.put("program", programs.get(1));
CalculationResultMap mch_csProgram = new InProgramCalculation().evaluate(cohort, params, Context.getService(PatientCalculationService.class).createCalculationContext());

params.put("program", programs.get(2));
CalculationResultMap mch_msProgram = new InProgramCalculation().evaluate(cohort, params, Context.getService(PatientCalculationService.class).createCalculationContext());

params.put("program", programs.get(3));
CalculationResultMap tbProgram = new InProgramCalculation().evaluate(cohort, params, Context.getService(PatientCalculationService.class).createCalculationContext());


for(Integer ptId: cohort){
String patientProgram = "";
if(patientProgramCohort.contains(ptId)) {
if ((Boolean)hivProgram.get(ptId).getValue()) {
patientProgram = "HIV";
}

if ((Boolean)tbProgram.get(ptId).getValue()) {
patientProgram = patientProgram.equalsIgnoreCase("")? "TB" : patientProgram+",TB";
}

if ((Boolean)mch_csProgram.get(ptId).getValue()) {
patientProgram = patientProgram.equalsIgnoreCase("")? "MCH_CS" : patientProgram+",MCH_CS";
}

if ((Boolean)mch_msProgram.get(ptId).getValue()) {
patientProgram = patientProgram.equalsIgnoreCase("")? "MCH_MS" : patientProgram+",MCH_MS";
}
}
ret.put(ptId, new SimpleResult(patientProgram, this));
}

//List<PatientProgram> pp= Context.getProgramWorkflowService().getPatientPrograms(cohort,programs);
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Obj
CalculationResultMap viralLoadList = Calculations.allObs(Dictionary.getConcept(Dictionary.HIV_VIRAL_LOAD), cohort, context);
//check for non detectables
CalculationResultMap ldlViralLoad = Calculations.allObs(Dictionary.getConcept(Dictionary.HIV_VIRAL_LOAD_QUALITATIVE), cohort, context);

//check for test orders
CalculationResultMap testOrders = Calculations.allObs(Dictionary.getConcept(Dictionary.TESTS_ORDERED), cohort, context);

//check for last ldl
CalculationResultMap ldlLast = Calculations.lastObs(Dictionary.getConcept(Dictionary.HIV_VIRAL_LOAD_QUALITATIVE), cohort, context);

Expand All @@ -77,13 +81,18 @@ public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Obj
Obs viralLoadObs = EmrCalculationUtils.obsResultForPatient(viralLoad, ptId);
Date dateInitiated = EmrCalculationUtils.datetimeResultForPatient(artStartDate, ptId);
ListResult listResult = (ListResult) viralLoadList.get(ptId);
ListResult testOrdersList = (ListResult) testOrders.get(ptId);
List<Obs> testObsList = CalculationUtils.extractResultValues(testOrdersList);
List<Obs> listObsViralLoads = CalculationUtils.extractResultValues(listResult);
ListResult ldlList = (ListResult) ldlViralLoad.get(ptId);
List<List> listLdl = CalculationUtils.extractResultValues(ldlList);
Obs lastLdlObs = EmrCalculationUtils.obsResultForPatient(ldlLast, ptId);
//find pregnancy obs
Obs pregnantEdd = EmrCalculationUtils.obsResultForPatient(pregStatusObss, ptId);

//Find latest viral load test order
Obs lastVlTestOrder = getLatestVlOrder(testObsList);

if(inHivProgram.contains(ptId) && onArt.contains(ptId)){
if(listObsViralLoads.size() == 0 && listLdl.size() == 0 && dateInitiated != null && (daysSince(dateInitiated, context) >= 180)) {
needsViralLoadTest = true;
Expand Down Expand Up @@ -136,6 +145,15 @@ public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Obj
}
}

//check if has vl test order within 6 months
if (lastVlTestOrder!= null && daysSince(lastVlTestOrder.getObsDatetime(), context) >= 180) {
needsViralLoadTest = true;
}

if (lastVlTestOrder!= null && daysSince(lastVlTestOrder.getObsDatetime(), context) < 180) {
needsViralLoadTest = false;
}

}

ret.put(ptId, new BooleanResult(needsViralLoadTest, this));
Expand All @@ -149,4 +167,21 @@ int monthsBetween(Date d1, Date d2) {
DateTime dateTime2 = new DateTime(d2.getTime());
return Math.abs(Months.monthsBetween(dateTime1, dateTime2).getMonths());
}

Obs getLatestVlOrder(List<Obs> lstObs) {
Obs latestObs = null;
for(Obs o:lstObs) {
if(o.getValueCoded() == Dictionary.getConcept(Dictionary.HIV_VIRAL_LOAD)) {
if(latestObs == null) {
latestObs =o;
} else {
if (o.getObsDatetime().after(latestObs.getObsDatetime()) ) {
latestObs =o;
}
}

}
}
return latestObs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void install() {
install(form("MOH 257 Visit Summary", null, _EncounterType.HIV_CONSULTATION, "1", _Form.MOH_257_VISIT_SUMMARY));
install(form("HIV Discontinuation", null, _EncounterType.HIV_DISCONTINUATION, "1", _Form.HIV_DISCONTINUATION));

install(patientIdentifierType("Unique Patient Number", "Assigned to every HIV patient", "\\d+", "Facility code followed by sequential number",
install(patientIdentifierType("Unique Patient Number", "Assigned to every HIV patient", "^[0-9]{10}$", "Facility code followed by sequential number",
null, LocationBehavior.NOT_USED, false, _PatientIdentifierType.UNIQUE_PATIENT_NUMBER));

install(program("HIV", "Treatment for HIV-positive patients", Dictionary.HIV_PROGRAM, _Program.HIV));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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.NumberOfDaysLateCalculation;
import org.openmrs.module.kenyaemr.calculation.library.PatientProgramCalculation;
import org.openmrs.module.kenyaemr.calculation.library.TelephoneNumberCalculation;
import org.openmrs.module.kenyaemr.calculation.library.hiv.LastReturnVisitDateCalculation;
import org.openmrs.module.kenyaemr.metadata.HivMetadata;
Expand Down Expand Up @@ -36,6 +37,7 @@ protected void addColumns(CohortReportDescriptor report, PatientDataSetDefinitio
dsd.addColumn("Appointment date", new CalculationDataDefinition("Appointment date", new LastReturnVisitDateCalculation()), "", new CalculationResultConverter());
dsd.addColumn("Number of days late", new CalculationDataDefinition("Number of days late", new NumberOfDaysLateCalculation()), "", new CalculationResultConverter());
dsd.addColumn("Phone number", new CalculationDataDefinition("Phone number", new TelephoneNumberCalculation()), "", new CalculationResultConverter());
dsd.addColumn("Program", new CalculationDataDefinition("Program", new PatientProgramCalculation()), "", new CalculationResultConverter());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
var encounterDate = new Date(getValue('encounter-date.value')).getTime();
var encouterDateValue = new Date(getValue('encounter-date.value'));
var fourMonthsFromEncounterDate = encouterDateValue.setDate(encouterDateValue.getDate() + 120);
if ((returnDate &lt; encounterDate) || (returnDate &gt; fourMonthsFromEncounterDate)) {
getField('returnVisitDate.error').html('Return Visit date should be after encounter date and NOT more than four months from Encounter Date').show();
if (returnDate &lt; encounterDate) {
getField('returnVisitDate.error').html('Return Visit date should be after encounter date').show();
return false;
}

if (returnDate &gt; fourMonthsFromEncounterDate) {
alert('Return Visit date is more than four months from Encounter Date');
}
return true;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
return false;
}*/

if(/^[0-9]{5}-[0-9]{5}$/.test(upn) === false) {
alert("Invalid Unique Patien Number(UPN) Format! Should be mfl-clinic number, each 5 digits");
return false;
}

if (encounterDate &lt; birthDate) {
getField('encounter-date.error').html('Encounter date, should not be earlier than birth date').show();
return false;
Expand Down Expand Up @@ -155,7 +160,7 @@
<tr>
<td>Unique Patient Number (UPN)</td>
<td>
<span id="hiv-id"><patient field="identifier" identifierTypeId="05ee9cf4-7242-4a17-b4d4-00f707265c8a" /></span>
<span id="hiv-id"><patient id="upn" field="identifier" identifierTypeId="05ee9cf4-7242-4a17-b4d4-00f707265c8a" /></span>
<input type="button" id="generate-hiv-id" value="Generate"/>
</td>
</tr>
Expand Down
30 changes: 29 additions & 1 deletion omod/src/main/webapp/resources/htmlforms/labResults.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,22 @@
}
}

function getLatedtVlOrder(){
var testOrderDate=new Date("<lookup expression="fn.latestObs(1271).obsDatetime"/>");
var testOrderVlConcept=<lookup expression="fn.latestObs(1271).valueCoded"/>

if (testOrderVlConcept == 856) {
//alert(testOrderVlConcept)
var month = testOrderDate.getMonth()+1;
var display ="VL last ordered on: " + testOrderDate.getDate()+"-"+ month +"-"+testOrderDate.getFullYear();
jq('#lastVl').html(display);
}
}

jq(function() {
getField('ldl.value').change(viralLoadValidation);
viralLoadValidation;
getLatedtVlOrder();
});

</script>
Expand All @@ -43,73 +56,88 @@
<tr>
<th> </th>
<th>Test</th>
<th>Ordered</th>
<th>Date Ordered</th>
<th>Result</th>
<th>Date Collected (if not today)</th>
</tr>
<tr>
<td>01.</td>
<td>CD4 Count</td>
<td><obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="5497AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
<td><obs conceptId="5497AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" showUnits="true" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
</tr>
<tr>
<td>02.</td>
<td>CD4%</td>
<td><obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="730AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
<td><obs conceptId="730AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" showUnits="true" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>

</tr>
<tr>
<td>03.</td>
<td>VDRL</td>
<td><obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="299AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
<td><obs conceptId="299AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>

</tr>
<tr>
<td>04.</td>
<td>ALT</td>
<td><obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="654AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
<td><obs conceptId="654AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" showUnits="true" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>

</tr>
<tr>
<td>05.</td>
<td>Creatinine</td>
<td><obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="790AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
<td><obs conceptId="790AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" showUnits="true" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>

</tr>
<tr>
<td>06 (a).</td>
<td>HIV Viral Load</td>
<td>
<obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="856AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/>
<span id="lastVl"></span>
</td>
<td id="vLoadResults">
<obs conceptId="856AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" showUnits="true" dateLabel="&lt;/td&gt;&lt;td&gt;"/>

</td>

</tr>
<tr>
<td>06 (b).</td>
<td>HIV Viral Load(LDL)</td>
<td></td>
<td><obs conceptId="1305AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="1302AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="LDL" id="ldl" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
</tr>
<tr>
<td>07.</td>
<td>HIV DNA PCR</td>
<td><obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="1030AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
<td><obs conceptId="1030AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>

</tr>
<tr>
<td>08.</td>
<td>Hemoglobin</td>
<td><obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
<td><obs conceptId="21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>

</tr>
<tr>
<td>09.</td>
<td>Urinalysis</td>
<td><obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="302AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
<td><obs conceptId="302AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>

</tr>
<tr>
<td>10.</td>
<td>Malaria Smear</td>
<td><obs conceptId="1271AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerConceptId="32AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" answerLabel="" style="checkbox" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>
<td><obs conceptId="32AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" dateLabel="&lt;/td&gt;&lt;td&gt;"/></td>

</tr>
Expand Down
23 changes: 13 additions & 10 deletions omod/src/main/webapp/resources/htmlforms/triage.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@
getField('height.value').change(onWeightOrHeightChange);
onWeightOrHeightChange();

var pbirthdate = new Date("<lookup expression="
patient.birthdate
" />"
).
getTime();
var pgender = "<lookup expression="
patient.gender
" />";
//limit letters only in text field
jQuery('#rsn').keypress(function(event) {
var code = (event.keyCode ? event.keyCode : event.which);
//alert(code)
if (code &gt;= 48 &amp;&amp; code &lt;= 57) //numbers
event.preventDefault();
});

if (pgender == 'F') {

var pbirthdate = new Date("<lookup expression="patient.birthdate" />").getTime();
var pgender = "<lookup expression="patient.gender" />";

if (pgender === 'F') {
beforeSubmit.push(function () {
var lmpdate = new Date(getValue('lmp-date.value')).getTime();
if (lmpdate &lt; pbirthdate) {
Expand Down Expand Up @@ -78,7 +81,7 @@
<tr>
<td>Reason for visit</td>
<td>
<obs conceptId="160430AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" rows="2" cols="80"/>
<obs id="rsn" conceptId="160430AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" rows="2" cols="80"/>
</td>
</tr>
</table>
Expand Down

0 comments on commit ccc4498

Please sign in to comment.