Skip to content

Commit

Permalink
Merge pull request #2078 from njorocs/MoH717-V2
Browse files Browse the repository at this point in the history
Mo h717 v2
  • Loading branch information
patryllus authored Dec 17, 2024
2 parents 7903d8d + d70fd35 commit 332fa6e
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.PersonAttributeType;
import org.openmrs.customdatatype.CustomDatatype;
import org.openmrs.customdatatype.datatype.DateDatatype;
import org.openmrs.module.idgen.validator.LuhnMod25IdentifierValidator;
import org.openmrs.module.kenyaemr.EmrConstants;
Expand All @@ -25,9 +24,6 @@
import org.springframework.stereotype.Component;

import org.openmrs.customdatatype.datatype.FreeTextDatatype;
import org.openmrs.customdatatype.datatype.ConceptDatatype;

import java.util.Date;

import static org.openmrs.module.metadatadeploy.bundle.CoreConstructors.encounterType;
import static org.openmrs.module.metadatadeploy.bundle.CoreConstructors.form;
Expand Down Expand Up @@ -163,6 +159,14 @@ public static final class _Form {
public static final String HEARING_SCREENING_CLINICAL_FORM = "270f388f-439f-476a-8919-8211f850d366";
public static final String NEUROLOGY_CLINICAL_FORM = "f97f2bf3-c26b-4adf-aacd-e09d720a14cd";
public static final String POST_MORTEM_CLINICAL_FORM = "016beec1-edff-4293-b3ed-817c7dddaa93";
public static final String EAR_NOSE_THROAT_CLINICAL_FORM = "c5055956-c3bb-45f2-956f-82e114c57aa7";
public static final String ORTHOPAEDIC_CLINICAL_FORM = "beec83df-6606-4019-8223-05a54a52f2b0";
public static final String OCCUPATIONAL_THERAPY_CLINICAL_FORM = "062a24b5-728b-4639-8176-197e8f458490";
public static final String OBSTETRIC_HISTORY_FORM = "d81e8157-317c-4041-9498-9d2318a1f2ed";
public static final String OPHTHAMOLOGY_CLINICAL_FORM = "235900ff-4d4a-4575-9759-96f325f5e291";
public static final String FERTILITY_CLINICAL_FORM = "32e43fc9-6de3-48e3-aafe-3b92f167753d";
public static final String CARDIOLOGY_CLINICAL_FORM = "998be6de-bd13-4136-ba0d-3f772139895f";
public static final String GASTROENTEROLOGY_CLINICAL_FORM = "6b4fa553-f2b3-47d0-a4c5-fc11f38b0b24";
}

public static final class _OrderType {
Expand Down Expand Up @@ -379,6 +383,14 @@ public void install() {
install(form("Hearing Screening Clinical Form", "Form for Hearing screening clinical encounter", _EncounterType.HEARING_SCREENING, "1", _Form.HEARING_SCREENING_CLINICAL_FORM));
install(form("Neurology Clinical Form", "Form for Neurology clinical encounter", _EncounterType.NEUROLOGY, "1", _Form.NEUROLOGY_CLINICAL_FORM));
install(form("Post-Mortem Clinical Form", "Form for Morgue clinical encounter", _EncounterType.POST_MORTEM, "1", _Form.POST_MORTEM_CLINICAL_FORM));
install(form("ENT Clinical Form", "Form for ENT clinical encounter", _EncounterType.CONSULTATION, "1", _Form.EAR_NOSE_THROAT_CLINICAL_FORM));
install(form("Orthopaedic Clinical Form", "Form for Orthopaedic clinical encounter", _EncounterType.CONSULTATION, "1", _Form.ORTHOPAEDIC_CLINICAL_FORM));
install(form("Occupational Therapy Clinical Form", "Form for Occupational therapy encounter", _EncounterType.CONSULTATION, "1", _Form.OCCUPATIONAL_THERAPY_CLINICAL_FORM));
install(form("Obstetric History Form", "Form for Obstetric History", _EncounterType.CONSULTATION, "1", _Form.OBSTETRIC_HISTORY_FORM));
install(form("Ophthamology Clinical Form", "Form for Ophthamology encounter ", _EncounterType.CONSULTATION, "1", _Form.OPHTHAMOLOGY_CLINICAL_FORM));
install(form("Gastroenterology Clinical Form", "Form for Gastroenterology encounter ", _EncounterType.CONSULTATION, "1", _Form.GASTROENTEROLOGY_CLINICAL_FORM));
install(form("Fertility Clinical Form", "Form for Fertility encounter ", _EncounterType.CONSULTATION, "1", _Form.FERTILITY_CLINICAL_FORM));
install(form("Cardiology Clinical Form", "Form for Cardiology encounter ", _EncounterType.CONSULTATION, "1", _Form.CARDIOLOGY_CLINICAL_FORM));

install(globalProperty(EmrConstants.GP_DEFAULT_LOCATION,
"The facility for which this installation is configured",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* FMAP MOH-729 Report
*/
@Component
@Builds({"kenyaemr.etl.common.report.fmap"})
@Builds({"kenyaemr.ehrReports.report.fmap"})
public class FmapReportBuilder extends AbstractReportBuilder {

protected static final Log log = LogFactory.getLog(FmapReportBuilder.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import org.openmrs.module.kenyacore.report.ReportUtils;
import org.openmrs.module.kenyacore.report.builder.AbstractReportBuilder;
import org.openmrs.module.kenyacore.report.builder.Builds;
import org.openmrs.module.kenyaemr.metadata.CommonMetadata;
import org.openmrs.module.kenyaemr.reporting.ColumnParameters;
import org.openmrs.module.kenyaemr.reporting.EmrReportingUtils;
import org.openmrs.module.kenyaemr.reporting.library.moh717.Moh717CohortLibrary;
import org.openmrs.module.kenyaemr.reporting.library.moh717.Moh717IndicatorLibrary;
import org.openmrs.module.kenyaemr.reporting.library.shared.common.CommonDimensionLibrary;
import org.openmrs.module.kenyaemr.util.EmrUtils;
import org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition;
import org.openmrs.module.reporting.dataset.definition.DataSetDefinition;
import org.openmrs.module.reporting.dataset.definition.SqlDataSetDefinition;
Expand All @@ -26,15 +28,13 @@
import org.openmrs.module.reporting.report.definition.ReportDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.openmrs.module.reporting.indicator.CohortIndicator;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import static org.openmrs.module.kenyacore.report.ReportUtils.map;
import static org.openmrs.module.kenyaemr.reporting.MohReportUtils.ReportAddonUtils.getGeneralOutPatientFilters;

/**
* Report builder for MOH717
Expand All @@ -50,6 +50,20 @@ public class MOH717ReportBuilder extends AbstractReportBuilder {

private final Moh717IndicatorLibrary moh717IndicatorLibrary;

static final int NEW_VISIT = 164180, RE_ATT= 160530;

static final ArrayList<String> otherSpecialClinics = new ArrayList<>(Arrays.asList(
CommonMetadata._Form.NEUROLOGY_CLINICAL_FORM,
CommonMetadata._Form.DERMATOLOGY_CLINICAL_FORM,
CommonMetadata._Form.AUDIOLOGY_FORM,
CommonMetadata._Form.SPEECH_AND_LANGAUGE_THERAPY_CLINICAL_FORM,
CommonMetadata._Form.DIABETIC_CLINICAL_FORM,
CommonMetadata._Form.MAXILLOFACIAL_CLINICAL_FORM,
CommonMetadata._Form.GASTROENTEROLOGY_CLINICAL_FORM,
CommonMetadata._Form.CARDIOLOGY_CLINICAL_FORM,
CommonMetadata._Form.FERTILITY_CLINICAL_FORM
));

ColumnParameters femaleChildrenUnder5 = new ColumnParameters(null, "<5", "age=<5|gender=F");
ColumnParameters maleChildrenUnder5 = new ColumnParameters(null, "<5", "age=<5|gender=M");
ColumnParameters females5To59 = new ColumnParameters(null, "5-59, Female", "gender=F|age=5-59");
Expand Down Expand Up @@ -133,6 +147,41 @@ private DataSetDefinition moh717DatasetDefinition() {

dsd.addColumn( "Number of Laboratory tests", "", ReportUtils.map(moh717IndicatorLibrary.laboratoryTests(), indParams), "");
dsd.addColumn("Number of Examinations (XRay & Imaging)", "", ReportUtils.map(moh717IndicatorLibrary.xrayAndImaging(), indParams), "");

// Special Clinics
dsd.addColumn( "ENT Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.EAR_NOSE_THROAT_CLINICAL_FORM, NEW_VISIT), indParams), "");
dsd.addColumn( "ENT Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.EAR_NOSE_THROAT_CLINICAL_FORM, RE_ATT), indParams), "");
dsd.addColumn( "Eye Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.OPHTHAMOLOGY_CLINICAL_FORM,NEW_VISIT), indParams), "");
dsd.addColumn( "Eye Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.OPHTHAMOLOGY_CLINICAL_FORM,RE_ATT), indParams), "");
dsd.addColumn( "TB and Leprosy Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.newOnTBClinic(), indParams), "");
dsd.addColumn( "TB and Leprosy Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.revisitTBClinic(), indParams), "");
dsd.addColumn( "CCC Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.newOnCCClinic(), indParams), "");
dsd.addColumn( "CCC Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.revisitCCClinic(), indParams), "");
dsd.addColumn( "Psychiatry Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.PSYCHIATRIC_FORM, NEW_VISIT), indParams), "");
dsd.addColumn( "Psychiatry Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.PSYCHIATRIC_FORM, RE_ATT), indParams), "");
dsd.addColumn( "Orthopaedic Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.ORTHOPAEDIC_CLINICAL_FORM,NEW_VISIT), indParams), "");
dsd.addColumn( "Orthopaedic Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.ORTHOPAEDIC_CLINICAL_FORM, RE_ATT), indParams), "");
dsd.addColumn( "Occupational Therapy Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.OCCUPATIONAL_THERAPY_CLINICAL_FORM, NEW_VISIT), indParams), "");
dsd.addColumn( "Occupational Therapy Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.OCCUPATIONAL_THERAPY_CLINICAL_FORM, RE_ATT), indParams), "");
dsd.addColumn( "Physiotherapy Therapy Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.PHYSIOTHERAPY_FORM, NEW_VISIT), indParams), "");
dsd.addColumn( "Physiotherapy Therapy Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.PHYSIOTHERAPY_FORM, RE_ATT), indParams), "");
dsd.addColumn( "Medical Clinics (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.MOPC_FORM, NEW_VISIT), indParams), "");
dsd.addColumn( "Medical Clinics (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.MOPC_FORM,RE_ATT), indParams), "");
dsd.addColumn( "Surgical Clinics (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.SOPC_FORM, NEW_VISIT), indParams), "");
dsd.addColumn( "Surgical Clinics (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.SOPC_FORM, RE_ATT), indParams), "");
dsd.addColumn( "Paediatrics (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.POPC_FORM, NEW_VISIT), indParams), "");
dsd.addColumn( "Paediatrics (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.POPC_FORM, RE_ATT), indParams), "");
dsd.addColumn( "Obstetrics and Gynaecology (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.GOPC_FORM,NEW_VISIT), indParams), "");
dsd.addColumn( "Obstetrics and Gynaecology (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.GOPC_FORM, RE_ATT), indParams), "");
dsd.addColumn( "Nutrition Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.NUTRITION, NEW_VISIT), indParams), "");
dsd.addColumn( "Nutrition Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.NUTRITION, RE_ATT), indParams), "");
dsd.addColumn( "Oncology Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.ONCOLOGY_FORM, NEW_VISIT), indParams), "");
dsd.addColumn( "Oncology Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.ONCOLOGY_FORM, RE_ATT), indParams), "");
dsd.addColumn( "Renal Clinic (New)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.UROLOGY_CLINICAL_FORM,NEW_VISIT), indParams), "");
dsd.addColumn( "Renal Clinic (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.specialClinic(CommonMetadata._Form.UROLOGY_CLINICAL_FORM, RE_ATT), indParams), "");
dsd.addColumn( "All other special Clinics (New)", "", ReportUtils.map(moh717IndicatorLibrary.otherSpecialClinics(EmrUtils.formatListWithQuotes(otherSpecialClinics),NEW_VISIT), indParams), "");
dsd.addColumn( "All other special Clinics (Re_Att)", "", ReportUtils.map(moh717IndicatorLibrary.otherSpecialClinics(EmrUtils.formatListWithQuotes(otherSpecialClinics),RE_ATT), indParams), "");

return dsd;
}
private DataSetDefinition totalAmountCollectedDatasetDefinition(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* MOH 711 report
*/
@Component
@Builds({"kenyaemr.common.report.moh711"})
@Builds({"kenyaemr.ehrReports.report.moh711"})
public class Moh711ReportBuilder extends AbstractReportBuilder {

protected static final Log log = LogFactory.getLog(Moh711ReportBuilder.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* MOH 745 Report
*/
@Component
@Builds({"kenyaemr.common.report.moh745"})
@Builds({"kenyaemr.ehrReports.report.moh745"})
public class Moh745ReportBuilder extends AbstractReportBuilder {

protected static final Log log = LogFactory.getLog(Moh745ReportBuilder.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,22 @@ public CohortDefinition xrayAndImaging() {
sql.setQuery("select o.encounter_id from orders o where o.order_type_id = 4 and o.voided = 0 and date(o.date_activated) between date(:startDate) and date(:endDate);");
return sql;
}
public CohortDefinition specialClinic(String clinicFormUUID, int visitType) {
SqlCohortDefinition sql = new SqlCohortDefinition();
sql.setName("Special Clinic");
sql.addParameter(new Parameter("startDate", "Start Date", Date.class));
sql.addParameter(new Parameter("endDate", "End Date", Date.class));
sql.setQuery("select s.patient_id from kenyaemr_etl.etl_special_clinics s where s.special_clinic_form_uuid = '"+clinicFormUUID+"' and s.visit_type = "+visitType+" and s.visit_date between date(:startDate) and date(:endDate);");
return sql;
}
public CohortDefinition otherSpecialClinics(String clinicsFormUUIDS, int visitType) {
SqlCohortDefinition sql = new SqlCohortDefinition();
sql.setName("Other Special Clinics");
sql.addParameter(new Parameter("startDate", "Start Date", Date.class));
sql.addParameter(new Parameter("endDate", "End Date", Date.class));
sql.setQuery("select s.patient_id from kenyaemr_etl.etl_special_clinics s where s.special_clinic_form_uuid in ("+clinicsFormUUIDS+") and s.visit_type = "+visitType+" and s.visit_date between date(:startDate) and date(:endDate);");
return sql;
}
public CohortDefinition totalAmountCollected() {
SqlCohortDefinition sql = new SqlCohortDefinition();
sql.setName("Total Amount Collected");
Expand All @@ -227,6 +243,53 @@ public CohortDefinition totalAmountCollected() {
"where date(transaction_date) between date(:startDate) and date(:endDate);");
return sql;
}

public CohortDefinition newOnTBClinic() {
SqlCohortDefinition sql = new SqlCohortDefinition();
sql.setName("New on TB Clinic");
sql.addParameter(new Parameter("startDate", "Start Date", Date.class));
sql.addParameter(new Parameter("endDate", "End Date", Date.class));
sql.setQuery("select e.patient_id from kenyaemr_etl.etl_tb_enrollment e where e.visit_date between date(:startDate) and date(:endDate);");
return sql;
}
public CohortDefinition revisitTBClinic() {
SqlCohortDefinition sql = new SqlCohortDefinition();
sql.setName("Revisiting TB Clinic");
sql.addParameter(new Parameter("startDate", "Start Date", Date.class));
sql.addParameter(new Parameter("endDate", "End Date", Date.class));
sql.setQuery("select e.patient_id\n" +
"from kenyaemr_etl.etl_tb_enrollment e\n" +
" inner join (select f.patient_id, min(f.visit_date) as first_visit, max(f.visit_date) as latest_visit\n" +
" from kenyaemr_etl.etl_tb_follow_up_visit f\n" +
" group by f.patient_id) f on e.patient_id = f.patient_id\n" +
"where f.latest_visit between date(:startDate) and date(:endDate)\n" +
" and f.first_visit < date(:startDate)\n" +
" and e.visit_date < date(:startDate);");
return sql;
}
public CohortDefinition newOnCCClinic() {
SqlCohortDefinition sql = new SqlCohortDefinition();
sql.setName("New on CCC Clinic");
sql.addParameter(new Parameter("startDate", "Start Date", Date.class));
sql.addParameter(new Parameter("endDate", "End Date", Date.class));
sql.setQuery("select e.patient_id from kenyaemr_etl.etl_hiv_enrollment e where e.patient_type = 164144 and e.visit_date between date(:startDate) and date(:endDate);");
return sql;
}
public CohortDefinition revisitCCClinic() {
SqlCohortDefinition sql = new SqlCohortDefinition();
sql.setName("Revisiting CCC Clinic");
sql.addParameter(new Parameter("startDate", "Start Date", Date.class));
sql.addParameter(new Parameter("endDate", "End Date", Date.class));
sql.setQuery("select e.patient_id\n" +
"from kenyaemr_etl.etl_hiv_enrollment e\n" +
" inner join (select f.patient_id, min(f.visit_date) as first_visit, max(f.visit_date) as latest_visit\n" +
" from kenyaemr_etl.etl_patient_hiv_followup f\n" +
" group by f.patient_id) f on e.patient_id = f.patient_id\n" +
"where f.latest_visit between date(:startDate) and date(:endDate)\n" +
" and f.first_visit < date(:startDate)\n" +
" and e.visit_date < date(:startDate);");
return sql;
}
public CohortDefinition totalAmountReceived() {
SqlCohortDefinition sql = new SqlCohortDefinition();
sql.setName("Total Amount Received");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ public CohortIndicator laboratoryTests() {
public CohortIndicator xrayAndImaging() {
return cohortIndicator("xrays and imaging", ReportUtils.map(moh717CohortLibrary.xrayAndImaging(), "startDate=${startDate},endDate=${endDate}"));
}

public CohortIndicator specialClinic(String clinicFormUUID, int visitType) {
return cohortIndicator("Special Clinics", ReportUtils.map(moh717CohortLibrary.specialClinic(clinicFormUUID,visitType), "startDate=${startDate},endDate=${endDate}"));
}
public CohortIndicator otherSpecialClinics(String clinicFormUUID, int visitType) {
return cohortIndicator("Other special clinics", ReportUtils.map(moh717CohortLibrary.otherSpecialClinics(clinicFormUUID, visitType), "startDate=${startDate},endDate=${endDate}"));
}
public CohortIndicator newOnTBClinic() {
return cohortIndicator("New on TB Clinic", ReportUtils.map(moh717CohortLibrary.newOnTBClinic(), "startDate=${startDate},endDate=${endDate}"));
}
public CohortIndicator revisitTBClinic() {
return cohortIndicator("Revisiting TB Clinic", ReportUtils.map(moh717CohortLibrary.revisitTBClinic(), "startDate=${startDate},endDate=${endDate}"));
}
public CohortIndicator newOnCCClinic() {
return cohortIndicator("New on CCC Clinic", ReportUtils.map(moh717CohortLibrary.newOnCCClinic(), "startDate=${startDate},endDate=${endDate}"));
}
public CohortIndicator revisitCCClinic() {
return cohortIndicator("Revisiting CCC Clinic", ReportUtils.map(moh717CohortLibrary.revisitCCClinic(), "startDate=${startDate},endDate=${endDate}"));
}
public CohortIndicator totalAmountCollected() {
return cohortIndicator("Total Amount Collected", ReportUtils.map(moh717CohortLibrary.totalAmountCollected(), "startDate=${startDate},endDate=${endDate}"));
}
Expand Down
Loading

0 comments on commit 332fa6e

Please sign in to comment.