Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: New ev/en analytics query tests [DHIS2-18695] #19560

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hisp.dhis.analytics.ValidationHelper.validateHeader;
import static org.hisp.dhis.analytics.ValidationHelper.validateRow;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;

import java.util.List;
import java.util.Map;
import org.hisp.dhis.AnalyticsApiTest;
import org.hisp.dhis.test.e2e.actions.analytics.AnalyticsEnrollmentsActions;
Expand Down Expand Up @@ -104,4 +106,157 @@ public void financialYear2022Sep() throws JSONException {

// Assert rows.
}

@Test
public void programIndicatorWeightGainBetweenBirthAndLastPostnatal() throws JSONException {
// Given
QueryParamsBuilder params =
new QueryParamsBuilder()
.add("includeMetadataDetails=true")
.add("headers=ouname,lastupdated,qhTkqwAJLMv")
.add("lastUpdated=LAST_6_MONTHS")
.add("displayProperty=NAME")
.add("totalPages=false")
.add("rowContext=true")
.add("pageSize=10")
.add("outputType=ENROLLMENT")
.add("page=1")
.add("dimension=ou:USER_ORGUNIT,qhTkqwAJLMv:EQ:NV")
.add("desc=lastupdated")
.add("relativePeriodDate=2019-02-01");

// When
ApiResponse response = actions.query().get("IpHINAT79UW", JSON, JSON, params);

// Then
response
.validate()
.statusCode(200)
.body("headers", hasSize(equalTo(3)))
.body("rows", hasSize(equalTo(10)))
.body("height", equalTo(10))
.body("width", equalTo(3))
.body("headerWidth", equalTo(3));

// Assert metaData.
String expectedMetaData =
"{\"pager\":{\"page\":1,\"pageSize\":10,\"isLastPage\":false},\"items\":{\"ImspTQPwCqd\":{\"uid\":\"ImspTQPwCqd\",\"code\":\"OU_525\",\"name\":\"Sierra Leone\",\"dimensionItemType\":\"ORGANISATION_UNIT\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\"},\"LAST_6_MONTHS\":{\"name\":\"Last 6 months\"},\"IpHINAT79UW\":{\"uid\":\"IpHINAT79UW\",\"name\":\"Child Programme\"},\"ZzYYXq4fJie\":{\"uid\":\"ZzYYXq4fJie\",\"name\":\"Baby Postnatal\",\"description\":\"Baby Postnatal\"},\"USER_ORGUNIT\":{\"organisationUnits\":[\"ImspTQPwCqd\"]},\"ou\":{\"uid\":\"ou\",\"name\":\"Organisation unit\",\"dimensionType\":\"ORGANISATION_UNIT\"},\"A03MvHHogjR\":{\"uid\":\"A03MvHHogjR\",\"name\":\"Birth\",\"description\":\"Birth of the baby\"},\"qhTkqwAJLMv\":{\"uid\":\"qhTkqwAJLMv\",\"name\":\"Weight gain(in g) between birth and last postnatal\",\"description\":\"The average number of grams the baby has gained through the postnatal period. Only counted among the babies that has completed the postnatal period.\",\"dimensionItemType\":\"PROGRAM_INDICATOR\",\"valueType\":\"NUMBER\",\"aggregationType\":\"AVERAGE\",\"totalAggregationType\":\"SUM\"}},\"dimensions\":{\"pe\":[],\"ou\":[\"ImspTQPwCqd\"],\"qhTkqwAJLMv\":[]}}";
String actualMetaData = new JSONObject((Map) response.extract("metaData")).toString();
assertEquals(expectedMetaData, actualMetaData, false);

// Assert headers.
validateHeader(
response, 0, "ouname", "Organisation unit name", "TEXT", "java.lang.String", false, true);
validateHeader(
response,
1,
"lastupdated",
"Last updated on",
"DATETIME",
"java.time.LocalDateTime",
false,
true);
validateHeader(
response,
2,
"qhTkqwAJLMv",
"Weight gain(in g) between birth and last postnatal",
"NUMBER",
"java.lang.Double",
false,
true);

// Assert rows.
validateRow(response, 0, List.of("Elshadai Clinic", "2018-10-11 17:04:24.953", ""));
validateRow(response, 1, List.of("Tonko Maternity Clinic", "2018-08-07 15:47:29.301", ""));
validateRow(response, 2, List.of("Banka Makuloh MCHP", "2018-08-07 15:47:29.3", ""));
validateRow(response, 3, List.of("Yonibana MCHP", "2018-08-07 15:47:29.299", ""));
validateRow(response, 4, List.of("Kindoyal Hospital", "2018-08-07 15:47:29.298", ""));
validateRow(response, 5, List.of("Baoma-Peje CHP", "2018-08-07 15:47:29.297", ""));
validateRow(response, 6, List.of("Bontiwo MCHP", "2018-08-07 15:47:29.296", ""));
validateRow(response, 7, List.of("Konia MCHP", "2018-08-07 15:47:29.295", ""));
validateRow(response, 8, List.of("Kania MCHP", "2018-08-07 15:47:29.294", ""));
validateRow(response, 9, List.of("Taninahun (Malen) CHP", "2018-08-07 15:47:29.293", ""));
}

@Test
public void programIndicatorWomenWithLowHbVisitWithinOneYear() throws JSONException {
// Given
QueryParamsBuilder params =
new QueryParamsBuilder()
.add("includeMetadataDetails=true")
.add("headers=ouname,lastupdated,EDp0b79Rbx9,programstatus,enrollmentdate")
.add("lastUpdated=LAST_12_MONTHS")
.add("displayProperty=NAME")
.add("totalPages=false")
.add("rowContext=true")
.add("pageSize=100")
.add("outputType=ENROLLMENT")
.add("page=1")
.add("dimension=EDp0b79Rbx9,ou:USER_ORGUNIT")
.add("relativePeriodDate=2019-02-01")
.add("desc=lastupdated");

// When
ApiResponse response = actions.query().get("WSGAb5XwJ3Y", JSON, JSON, params);

// Then
response
.validate()
.statusCode(200)
.body("headers", hasSize(equalTo(5)))
.body("rows", hasSize(equalTo(2)))
.body("height", equalTo(2))
.body("width", equalTo(5))
.body("headerWidth", equalTo(5));

// Assert metaData.
String expectedMetaData =
"{\"pager\":{\"page\":1,\"pageSize\":100,\"isLastPage\":true},\"items\":{\"EDp0b79Rbx9\":{\"uid\":\"EDp0b79Rbx9\",\"name\":\"Number of women with at least one low hemoglobin visit within one year of the reporting period end\",\"description\":\"Counts the number of women enrolled in the reporting period, that has had at least one low-hemoglobin visit within the end of the reporting period.\",\"dimensionItemType\":\"PROGRAM_INDICATOR\",\"valueType\":\"NUMBER\",\"aggregationType\":\"COUNT\",\"totalAggregationType\":\"SUM\"},\"ImspTQPwCqd\":{\"uid\":\"ImspTQPwCqd\",\"code\":\"OU_525\",\"name\":\"Sierra Leone\",\"dimensionItemType\":\"ORGANISATION_UNIT\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\"},\"PFDfvmGpsR3\":{\"uid\":\"PFDfvmGpsR3\",\"name\":\"Care at birth\",\"description\":\"Intrapartum care / Childbirth / Labour and delivery\"},\"bbKtnxRZKEP\":{\"uid\":\"bbKtnxRZKEP\",\"name\":\"Postpartum care visit\",\"description\":\"Provision of care for the mother for some weeks after delivery\"},\"USER_ORGUNIT\":{\"organisationUnits\":[\"ImspTQPwCqd\"]},\"ou\":{\"uid\":\"ou\",\"name\":\"Organisation unit\",\"dimensionType\":\"ORGANISATION_UNIT\"},\"PUZaKR0Jh2k\":{\"uid\":\"PUZaKR0Jh2k\",\"name\":\"Previous deliveries\",\"description\":\"Table for recording earlier deliveries\"},\"edqlbukwRfQ\":{\"uid\":\"edqlbukwRfQ\",\"name\":\"Second antenatal care visit\",\"description\":\"Antenatal care visit\"},\"WZbXY0S00lP\":{\"uid\":\"WZbXY0S00lP\",\"name\":\"First antenatal care visit\",\"description\":\"First antenatal care visit\"},\"WSGAb5XwJ3Y\":{\"uid\":\"WSGAb5XwJ3Y\",\"name\":\"WHO RMNCH Tracker\"},\"LAST_12_MONTHS\":{\"name\":\"Last 12 months\"}},\"dimensions\":{\"EDp0b79Rbx9\":[],\"pe\":[],\"ou\":[\"ImspTQPwCqd\"]}}";
String actualMetaData = new JSONObject((Map) response.extract("metaData")).toString();
assertEquals(expectedMetaData, actualMetaData, false);

// Assert headers.
validateHeader(
response, 0, "ouname", "Organisation unit name", "TEXT", "java.lang.String", false, true);
validateHeader(
response,
1,
"lastupdated",
"Last updated on",
"DATETIME",
"java.time.LocalDateTime",
false,
true);
validateHeader(
response,
2,
"EDp0b79Rbx9",
"Number of women with at least one low hemoglobin visit within one year of the reporting period end",
"NUMBER",
"java.lang.Double",
false,
true);
validateHeader(
response, 3, "programstatus", "Program status", "TEXT", "java.lang.String", false, true);
validateHeader(
response,
4,
"enrollmentdate",
"Date of first visit",
"DATETIME",
"java.time.LocalDateTime",
false,
true);

// Assert rows.
validateRow(
response,
0,
List.of("Ngelehun CHC", "2018-05-22 22:34:09.668", "0", "ACTIVE", "2023-10-14 02:00:00.0"));
validateRow(
response,
1,
List.of("Ngelehun CHC", "2018-02-20 18:47:35.335", "0", "ACTIVE", "2023-10-15 02:00:00.0"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hisp.dhis.analytics.ValidationHelper.validateHeader;
import static org.hisp.dhis.analytics.ValidationHelper.validateRow;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;

import java.util.List;
import java.util.Map;
import org.hisp.dhis.AnalyticsApiTest;
import org.hisp.dhis.test.e2e.actions.analytics.AnalyticsEventActions;
Expand Down Expand Up @@ -104,4 +106,206 @@ public void financialYear2023Sep() throws JSONException {

// Assert rows.
}

@Test
public void programIndicatorMalariaCaseMicroscopyPv514YearsFemale() throws JSONException {
// Given
QueryParamsBuilder params =
new QueryParamsBuilder()
.add("includeMetadataDetails=true")
.add("headers=ouname,TEmaOXaSPe7")
.add("stage=hYyB7FUS5eR")
.add("displayProperty=NAME")
.add("totalPages=false")
.add("enrollmentDate=MONTHS_THIS_YEAR")
.add("pageSize=10")
.add("outputType=EVENT")
.add("page=1")
.add("dimension=TEmaOXaSPe7,ou:USER_ORGUNIT")
.add("relativePeriodDate=2022-07-01")
.add("desc=lastupdated");

// When
ApiResponse response = actions.query().get("qDkgAbB5Jlk", JSON, JSON, params);

// Then
response
.validate()
.statusCode(200)
.body("headers", hasSize(equalTo(2)))
.body("rows", hasSize(equalTo(10)))
.body("height", equalTo(10))
.body("width", equalTo(2))
.body("headerWidth", equalTo(2));

// Assert metaData.
String expectedMetaData =
"{\"pager\":{\"page\":1,\"pageSize\":10,\"isLastPage\":false},\"items\":{\"ImspTQPwCqd\":{\"uid\":\"ImspTQPwCqd\",\"code\":\"OU_525\",\"name\":\"Sierra Leone\",\"dimensionItemType\":\"ORGANISATION_UNIT\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\"},\"TEmaOXaSPe7\":{\"uid\":\"TEmaOXaSPe7\",\"name\":\"Malaria case - microscopy Pv. 5-14 years female\",\"dimensionItemType\":\"PROGRAM_INDICATOR\",\"valueType\":\"NUMBER\",\"aggregationType\":\"COUNT\",\"totalAggregationType\":\"SUM\"},\"qDkgAbB5Jlk\":{\"uid\":\"qDkgAbB5Jlk\",\"name\":\"Malaria case diagnosis, treatment and investigation\",\"description\":\"All cases in an elimination setting should be registered in this program. Includes relevant case identifiers/details including the ID, Name, Index, Age, Gender, Location,etc..\"},\"USER_ORGUNIT\":{\"organisationUnits\":[\"ImspTQPwCqd\"]},\"ou\":{\"uid\":\"ou\",\"name\":\"Organisation unit\",\"dimensionType\":\"ORGANISATION_UNIT\"},\"MONTHS_THIS_YEAR\":{\"name\":\"Months this year\"},\"hYyB7FUS5eR\":{\"uid\":\"hYyB7FUS5eR\",\"name\":\"Diagnosis & treatment\",\"description\":\"This stage is used to identify initial diagnosis and treatment. This includes the method of case detection, information about the case include travel history, method of diagnosis, malaria species type and treatment details. \"}},\"dimensions\":{\"TEmaOXaSPe7\":[],\"pe\":[],\"ou\":[\"ImspTQPwCqd\"]}}";
String actualMetaData = new JSONObject((Map) response.extract("metaData")).toString();
assertEquals(expectedMetaData, actualMetaData, false);

// Assert headers.
validateHeader(
response, 0, "ouname", "Organisation unit name", "TEXT", "java.lang.String", false, true);
validateHeader(
response,
1,
"TEmaOXaSPe7",
"Malaria case - microscopy Pv. 5-14 years female",
"NUMBER",
"java.lang.Double",
false,
true);

// Assert rows.
validateRow(response, 0, List.of("Ngelehun CHC", "1"));
validateRow(response, 1, List.of("Ngelehun CHC", "0"));
validateRow(response, 2, List.of("Ngelehun CHC", "0"));
validateRow(response, 3, List.of("Ngelehun CHC", "1"));
validateRow(response, 4, List.of("Ngelehun CHC", "0"));
validateRow(response, 5, List.of("Ngelehun CHC", "0"));
validateRow(response, 6, List.of("Ngelehun CHC", "0"));
validateRow(response, 7, List.of("Ngelehun CHC", "0"));
validateRow(response, 8, List.of("Ngelehun CHC", "0"));
validateRow(response, 9, List.of("Ngelehun CHC", "0"));
}

@Test
public void programIndicatorNumberOfOrgUnitsWithOngoingArv() throws JSONException {
// Given
QueryParamsBuilder params =
new QueryParamsBuilder()
.add("includeMetadataDetails=true")
.add("headers=ouname,rxNjqzJ7dkK,lastupdated")
.add("lastUpdated=LAST_YEAR")
.add("stage=PUZaKR0Jh2k")
.add("displayProperty=NAME")
.add("totalPages=false")
.add("outputType=EVENT")
.add("pageSize=10")
.add("page=1")
.add("dimension=ou:USER_ORGUNIT,rxNjqzJ7dkK:GE:0")
.add("relativePeriodDate=2019-07-01")
.add("desc=lastupdated");

// When
ApiResponse response = actions.query().get("WSGAb5XwJ3Y", JSON, JSON, params);

// Then
response
.validate()
.statusCode(200)
.body("headers", hasSize(equalTo(3)))
.body("rows", hasSize(equalTo(10)))
.body("height", equalTo(10))
.body("width", equalTo(3))
.body("headerWidth", equalTo(3));

// Assert metaData.
String expectedMetaData =
"{\"pager\":{\"page\":1,\"pageSize\":10,\"isLastPage\":false},\"items\":{\"ImspTQPwCqd\":{\"uid\":\"ImspTQPwCqd\",\"code\":\"OU_525\",\"name\":\"Sierra Leone\",\"dimensionItemType\":\"ORGANISATION_UNIT\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\"},\"USER_ORGUNIT\":{\"organisationUnits\":[\"ImspTQPwCqd\"]},\"ou\":{\"uid\":\"ou\",\"name\":\"Organisation unit\",\"dimensionType\":\"ORGANISATION_UNIT\"},\"PUZaKR0Jh2k\":{\"uid\":\"PUZaKR0Jh2k\",\"name\":\"Previous deliveries\",\"description\":\"Table for recording earlier deliveries\"},\"WSGAb5XwJ3Y\":{\"uid\":\"WSGAb5XwJ3Y\",\"name\":\"WHO RMNCH Tracker\"},\"rxNjqzJ7dkK\":{\"uid\":\"rxNjqzJ7dkK\",\"name\":\"Number of organisation units with ongoing arv treatment\",\"dimensionItemType\":\"PROGRAM_INDICATOR\",\"valueType\":\"NUMBER\",\"aggregationType\":\"COUNT\",\"totalAggregationType\":\"SUM\"},\"LAST_YEAR\":{\"name\":\"Last year\"}},\"dimensions\":{\"pe\":[],\"ou\":[\"ImspTQPwCqd\"],\"rxNjqzJ7dkK\":[]}}";
String actualMetaData = new JSONObject((Map) response.extract("metaData")).toString();
assertEquals(expectedMetaData, actualMetaData, false);

// Assert headers.
validateHeader(
response, 0, "ouname", "Organisation unit name", "TEXT", "java.lang.String", false, true);
validateHeader(
response,
1,
"rxNjqzJ7dkK",
"Number of organisation units with ongoing arv treatment",
"NUMBER",
"java.lang.Double",
false,
true);
validateHeader(
response,
2,
"lastupdated",
"Last updated on",
"DATETIME",
"java.time.LocalDateTime",
false,
true);

// Assert rows.
validateRow(response, 0, List.of("Ngelehun CHC", "0", "2018-10-14 14:14:36.922"));
validateRow(response, 1, List.of("Kondewakoro CHP", "0", "2018-01-26 13:48:13.368"));
validateRow(response, 2, List.of("Mathen MCHP", "0", "2018-01-26 13:48:13.366"));
validateRow(response, 3, List.of("Mbokie CHP", "0", "2018-01-26 13:48:13.363"));
validateRow(response, 4, List.of("Grey Bush CHC", "0", "2018-01-26 13:48:13.359"));
validateRow(response, 5, List.of("Bangoma MCHP", "0", "2018-01-26 13:48:13.353"));
validateRow(response, 6, List.of("Blessed Mokaka East Clinic", "0", "2018-01-26 13:48:13.351"));
validateRow(response, 7, List.of("MCH Static/U5", "0", "2018-01-26 13:48:13.349"));
validateRow(response, 8, List.of("Konjo MCHP", "0", "2018-01-26 13:48:13.345"));
validateRow(response, 9, List.of("Lakka/Ogoo Farm CHC", "0", "2018-01-26 13:48:13.341"));
}

@Test
public void programIndicatorBMIFemaleUnder5y() throws JSONException {
// Given
QueryParamsBuilder params =
new QueryParamsBuilder()
.add("includeMetadataDetails=true")
.add("headers=ouname,lastupdated,hlPt8H4bUOQ")
.add("lastUpdated=LAST_12_MONTHS")
.add("stage=Zj7UnCAulEk")
.add("displayProperty=NAME")
.add("totalPages=false")
.add("pageSize=5")
.add("outputType=EVENT")
.add("page=1")
.add("dimension=hlPt8H4bUOQ,ou:USER_ORGUNIT")
.add("relativePeriodDate=2019-02-01")
.add("desc=lastupdated");

// When
ApiResponse response = actions.query().get("eBAyeGv0exc", JSON, JSON, params);

// Then
response
.validate()
.statusCode(200)
.body("headers", hasSize(equalTo(3)))
.body("rows", hasSize(equalTo(5)))
.body("height", equalTo(5))
.body("width", equalTo(3))
.body("headerWidth", equalTo(3));

// Assert metaData.
String expectedMetaData =
"{\"pager\":{\"page\":1,\"pageSize\":5,\"isLastPage\":false},\"items\":{\"ImspTQPwCqd\":{\"uid\":\"ImspTQPwCqd\",\"code\":\"OU_525\",\"name\":\"Sierra Leone\",\"dimensionItemType\":\"ORGANISATION_UNIT\",\"valueType\":\"TEXT\",\"totalAggregationType\":\"SUM\"},\"hlPt8H4bUOQ\":{\"uid\":\"hlPt8H4bUOQ\",\"name\":\"BMI female under 5 y\",\"dimensionItemType\":\"PROGRAM_INDICATOR\",\"valueType\":\"NUMBER\",\"aggregationType\":\"AVERAGE\",\"totalAggregationType\":\"SUM\"},\"eBAyeGv0exc\":{\"uid\":\"eBAyeGv0exc\",\"name\":\"Inpatient morbidity and mortality\"},\"USER_ORGUNIT\":{\"organisationUnits\":[\"ImspTQPwCqd\"]},\"ou\":{\"uid\":\"ou\",\"name\":\"Organisation unit\",\"dimensionType\":\"ORGANISATION_UNIT\"},\"Zj7UnCAulEk\":{\"uid\":\"Zj7UnCAulEk\",\"name\":\"Inpatient morbidity and mortality\",\"description\":\"Anonymous and ICD-10 coded inpatient data\"},\"LAST_12_MONTHS\":{\"name\":\"Last 12 months\"}},\"dimensions\":{\"hlPt8H4bUOQ\":[],\"pe\":[],\"ou\":[\"ImspTQPwCqd\"]}}";
String actualMetaData = new JSONObject((Map) response.extract("metaData")).toString();
assertEquals(expectedMetaData, actualMetaData, false);

// Assert headers.
validateHeader(
response, 0, "ouname", "Organisation unit name", "TEXT", "java.lang.String", false, true);
validateHeader(
response,
1,
"lastupdated",
"Last updated on",
"DATETIME",
"java.time.LocalDateTime",
false,
true);
validateHeader(
response,
2,
"hlPt8H4bUOQ",
"BMI female under 5 y",
"NUMBER",
"java.lang.Double",
false,
true);

// Assert rows.
validateRow(response, 0, List.of("Ngelehun CHC", "2018-08-04 15:19:36.473", ""));
validateRow(response, 1, List.of("Ngelehun CHC", "2018-08-04 15:18:06.085", ""));
validateRow(response, 2, List.of("Ngelehun CHC", "2018-08-04 15:17:39.87", ""));
validateRow(response, 3, List.of("Ngelehun CHC", "2018-08-04 15:17:10.722", ""));
validateRow(response, 4, List.of("Ngelehun CHC", "2018-08-04 15:15:50.672", ""));
}
}
Loading
Loading