Skip to content

Commit

Permalink
#95 | cancelDateTime updated in ETL tables
Browse files Browse the repository at this point in the history
  • Loading branch information
BEULAHEVANJALIN committed Apr 12, 2024
1 parent 4c23f97 commit f7debf1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/main/resources/sql/etl/generalEncounter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ FROM public.encounter entity
${cross_join_concept_maps}
WHERE st.uuid = '${subject_type_uuid}'
AND et.uuid = '${encounter_type_uuid}'
AND entity.cancel_date_time isnull
and entity.last_modified_date_time > '${start_time}'
and entity.last_modified_date_time <= '${end_time}'
);
1 change: 0 additions & 1 deletion src/main/resources/sql/etl/programEncounter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,5 @@ FROM public.program_encounter entity
WHERE p.uuid = '${program_uuid}'
AND et.uuid = '${encounter_type_uuid}'
AND st.uuid = '${subject_type_uuid}'
AND entity.cancel_date_time isnull
and entity.last_modified_date_time > '${start_time}'
and entity.last_modified_date_time <= '${end_time}');
49 changes: 46 additions & 3 deletions src/test/java/org/avniproject/etl/DataSyncIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void repeatedQGObservationsArePopulatedInTheirOwnTable() {
runDataSync();
List<Map<String, Object>> list = jdbcTemplate.queryForList(format("select * from orgc.person_general_encounter_asset_info where encounter_id = %d", 2001));
assertEquals(2, list.size());
assertEquals(100, ((BigDecimal)(list.get(0).get("Asset Info Bitcoin"))).intValue());
assertEquals(100, ((BigDecimal) (list.get(0).get("Asset Info Bitcoin"))).intValue());
assertEquals("FTX", list.get(0).get("Asset Info Exchange"));

jdbcTemplate.execute("update encounter set last_modified_date_time = current_timestamp where id = 2001");
Expand Down Expand Up @@ -278,11 +278,11 @@ public void allTablesHaveAddressIdAndIndividualIdColumns() {
List<Map<String, Object>> exits = jdbcTemplate.queryForList("select * from orgc.person_nutrition_exit;");
assertThat(exits.size() == 1, is(true));
List<Map<String, Object>> programEncounters = jdbcTemplate.queryForList("select * from orgc.person_nutrition_growth_monitoring;");
assertThat(programEncounters.size() == 1, is(true));
assertThat(programEncounters.size() == 3, is(true));
List<Map<String, Object>> programEncounterCancels = jdbcTemplate.queryForList("select * from orgc.person_nutrition_growth_monitoring_cancel;");
assertThat(programEncounterCancels.size() == 1, is(true));
List<Map<String, Object>> encounters = jdbcTemplate.queryForList("select * from orgc.person_general_encounter;");
assertThat(encounters.size() == 1, is(true));
assertThat(encounters.size() == 3, is(true));
List<Map<String, Object>> encounterCancels = jdbcTemplate.queryForList("select * from orgc.person_general_encounter_cancel;");
assertThat(encounterCancels.size() == 1, is(true));
Arrays.asList(enrolments, programEncounters, encounters, exits, programEncounterCancels, encounterCancels).forEach(entity -> {
Expand Down Expand Up @@ -351,4 +351,47 @@ public void userTableShouldUpdateWithOldUserData() throws InterruptedException {
Long numberOfRowsAfterSecondRun = countOfRowsIn("orgc.users");
assertThat(numberOfRowsAfterSecondRun, is(equalTo(numberOfRowsAfterFirstRun)));
}

@Test
@Sql({"/test-data-teardown.sql", "/test-data.sql"})
@Sql(scripts = "/test-data-teardown.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void cancelDateTimeShouldBeUpdatedWhenProgramEncounterIsCancelled() throws InterruptedException {
runDataSync();

List<Map<String, Object>> programEncounterToBeCancelled = jdbcTemplate.queryForList("select * from orgc.person_nutrition_growth_monitoring where id = 877069;");
assertThat(programEncounterToBeCancelled.size() == 1, is(true));
assertThat(programEncounterToBeCancelled.get(0).get("cancel_date_time") == null, is(true));

jdbcTemplate.execute(format("update program_encounter set last_modified_date_time = '%s', cancel_date_time = now() where id = 877069;", getCurrentTime()));

runDataSync();

List<Map<String, Object>> cancelledProgramEncounter = jdbcTemplate.queryForList("select * from orgc.person_nutrition_growth_monitoring where id = 877069;");
assertThat(cancelledProgramEncounter.get(0).get("cancel_date_time") == null, is(false));

List<Map<String, Object>> valueInCancelTable = jdbcTemplate.queryForList("select * from orgc.person_nutrition_growth_monitoring_cancel where id = 877069;");
assertThat(programEncounterToBeCancelled.size() == 1, is(true));
}

@Test
@Sql({"/test-data-teardown.sql", "/test-data.sql"})
@Sql(scripts = "/test-data-teardown.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void cancelDateTimeShouldBeUpdatedWhenGeneralEncounterIsCancelled() throws InterruptedException {
runDataSync();

List<Map<String, Object>> programEncounterToBeCancelled = jdbcTemplate.queryForList("select * from orgc.person_general_encounter where id = 1902;");
assertThat(programEncounterToBeCancelled.size() == 1, is(true));
assertThat(programEncounterToBeCancelled.get(0).get("cancel_date_time") == null, is(true));

jdbcTemplate.execute(format("update encounter set last_modified_date_time = '%s', cancel_date_time = now() where id = 1902;", getCurrentTime()));

runDataSync();

List<Map<String, Object>> cancelledProgramEncounter = jdbcTemplate.queryForList("select * from orgc.person_general_encounter where id = 1902;");
assertThat(cancelledProgramEncounter.get(0).get("cancel_date_time") == null, is(false));

List<Map<String, Object>> valueInCancelTable = jdbcTemplate.queryForList("select * from orgc.person_general_encounter_cancel where id = 1902;");
assertThat(programEncounterToBeCancelled.size() == 1, is(true));
}
}

2 changes: 2 additions & 0 deletions src/test/resources/test-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ INSERT INTO program_enrolment (id, program_id, individual_id, program_outcome_id

INSERT INTO program_encounter (id, observations, earliest_visit_date_time, encounter_date_time, program_enrolment_id, uuid, version, encounter_type_id, name, max_visit_date_time, organisation_id, cancel_date_time, cancel_observations, audit_id, is_voided, encounter_location, cancel_location, legacy_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, address_id, individual_id, sync_concept_1_value, sync_concept_2_value) VALUES (877067, '{"79deda49-7e16-4980-a784-c54054da8931": "a5f8335c-0be1-46a1-b12a-bd3e5ccad60e"}', null, '2022-04-06 07:15:07.000 +00:00', 150708, 'd73e0f79-4876-42e3-b9e6-f9fb131fb8a3', 0, 1053, 'Growth Monitoring', null, 12, null, '{}', create_audit(), false, null, null, null, 1, 1, '2022-04-06 07:15:10.982 +00:00', '2022-04-06 07:15:10.982 +00:00', 107786, 574170, null, null);
INSERT INTO program_encounter (id, observations, earliest_visit_date_time, encounter_date_time, program_enrolment_id, uuid, version, encounter_type_id, name, max_visit_date_time, organisation_id, cancel_date_time, cancel_observations, audit_id, is_voided, encounter_location, cancel_location, legacy_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, address_id, individual_id, sync_concept_1_value, sync_concept_2_value) VALUES (877068, '{}', null, null, 150708, 'c4a36bba-0091-4c0d-bc64-aade04f56896', 0, 1053, 'Growth Monitoring cancel', null, 12, '2022-04-06 07:15:07.000 +00:00', '{}', create_audit(), false, null, null, null, 1, 1, '2022-04-06 07:15:10.982 +00:00', '2022-04-06 07:15:10.982 +00:00', 107786, 574170, null, null);
INSERT INTO program_encounter (id, observations, earliest_visit_date_time, encounter_date_time, program_enrolment_id, uuid, version, encounter_type_id, name, max_visit_date_time, organisation_id, cancel_date_time, cancel_observations, audit_id, is_voided, encounter_location, cancel_location, legacy_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, address_id, individual_id, sync_concept_1_value, sync_concept_2_value) VALUES (877069, '{}', '2022-04-06 07:15:07.000 +00:00', null, 150708, 'c4edb084-41cf-46f5-a62a-b8fbddfb35b9', 0, 1053, 'Growth Monitoring', null, 12, null, '{}', create_audit(), false, null, null, null, 1, 1, '2022-04-06 07:15:10.982 +00:00', '2022-04-06 07:15:10.982 +00:00', 107786, 574170, null, null);

insert into encounter (id, observations, encounter_date_time, encounter_type_id, individual_id, uuid, version, organisation_id, is_voided, audit_id, encounter_location, earliest_visit_date_time, max_visit_date_time, cancel_date_time, cancel_observations, cancel_location, name, legacy_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, address_id, sync_concept_1_value, sync_concept_2_value) values ( 1900,'{}','2022-04-06 07:15:07.000 +00:00',1054,574170,'cd8b597c-9a00-48b5-9763-7d41404a2844',0,12, false, create_audit(), null, null, null, null, '{}', null, null, null, 1,1, '2022-04-06 07:15:07.000 +00:00', '2022-04-06 07:15:07.000 +00:00',107786, null,null);
insert into encounter (id, observations, encounter_date_time, encounter_type_id, individual_id, uuid, version, organisation_id, is_voided, audit_id, encounter_location, earliest_visit_date_time, max_visit_date_time, cancel_date_time, cancel_observations, cancel_location, name, legacy_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, address_id, sync_concept_1_value, sync_concept_2_value) values ( 1901,'{}',null,1054,574170,'b65f2cd1-fa8c-4c7a-86bb-e004cf85d7ca',0,12, false, create_audit(), null, null, null, '2022-04-06 07:15:07.000 +00:00', '{}', null, null, null, 1,1, '2022-04-06 07:15:07.000 +00:00', '2022-04-06 07:15:07.000 +00:00',107786, null,null);
INSERT INTO encounter (id, observations, encounter_date_time, encounter_type_id, individual_id, uuid, version, organisation_id, is_voided, audit_id, encounter_location, earliest_visit_date_time, max_visit_date_time, cancel_date_time, cancel_observations, cancel_location, name, legacy_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, address_id, sync_concept_1_value, sync_concept_2_value) VALUES (1902,'{}',null,1054,574170,'c99600ef-bf50-4b12-b448-ba61b0fabd1a',0,12, false, create_audit(), null, null, null, null, '{}', null, null, null, 1,1, '2022-04-06 07:15:07.000 +00:00', '2022-04-06 07:15:07.000 +00:00',107786, null,null);

INSERT INTO sync_telemetry (id, uuid, user_id, organisation_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, sync_status, sync_start_time, sync_end_time, device_name, android_version, app_version, device_info, sync_source)
VALUES (10001, 'efcac25a-2a9f-11ee-b753-efc7f4551cff', 3453, 12, 3453, 3453, '2023-07-24 16:58:54.272 +05:30', '2023-07-24 16:58:54.272 +05:30', 'incomplete', '2023-07-24 16:54:54.272 +05:30', '2023-07-24 16:58:54.272 +05:30', 'Oneplus Nord 2', '17', 'v3.56', '{}','kota');

0 comments on commit f7debf1

Please sign in to comment.