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

FIxed single quote in media query #100

Merged
merged 1 commit into from
Apr 13, 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 @@ -137,7 +137,7 @@ private String wrapInQuotes(String parameter) {
}

private String wrapStringValue(String parameter) {
return parameter == null ? "null" : "'" + parameter + "'";
return parameter == null ? "null" : "'" + parameter.replace("'", "''") + "'";
}

public static boolean equalsButNotBothNull(Object a, Object b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public void allTablesHaveAddressIdAndIndividualIdColumns() {
public void shouldPopulateMediaTable() {
runDataSync();
List<Map<String, Object>> media = jdbcTemplate.queryForList("select * from orgc.media;");
assertThat(media.size(), is(2));
assertThat(media.size(), is(3));
}

@Test
Expand All @@ -306,14 +306,14 @@ public void shouldPopulateMediaTable() {
public void shouldPopulateMediaTableCorrectlyWhenTransactionalDataUpdates() throws InterruptedException {
runDataSync();
List<Map<String, Object>> media = jdbcTemplate.queryForList("select * from orgc.media;");
assertThat("Verifying current value of media table", media.size(), is(2));
assertThat("Verifying current value of media table", media.size(), is(3));

String newEncounterImage = "https://s3.amazon.com/newEncounterImage.jpg";
jdbcTemplate.execute("update encounter set observations = observations || jsonb_build_object('44163589-f76d-447d-9b6e-f5c32aa859eb', '" + newEncounterImage + "'), last_modified_date_time = now() where id = 1900;");
runDataSync();

media = jdbcTemplate.queryForList("select * from orgc.media;");
assertThat("Media table number of rows has not changed since last run", media.size(), is(2));
assertThat("Media table number of rows has not changed since last run", media.size(), is(3));

Optional<Map<String, Object>> encounterMedia = media.stream().filter(stringObjectMap -> (Integer.valueOf(1900)).equals(stringObjectMap.get("entity_id"))).findAny();
assertThat(encounterMedia.isPresent(), is(true));
Expand All @@ -331,7 +331,7 @@ public void arrayStyleMediaObservationsCreateMultipleRowsInMediaTable() throws I
runDataSync();

List<Map<String, Object>> media = jdbcTemplate.queryForList("select * from orgc.media;");
assertThat("Media table number of rows has not changed since last run", media.size(), is(3));
assertThat("Media table number of rows has not changed since last run", media.size(), is(4));
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/media-form-element.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
-- Person
insert into concept (id, data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) values (108001, 'Image', null, null, null, null, 'Image concept', '44163589-f76d-447d-9b6e-f5c32aa859eb', 0, null, 12, false, create_audit(), null, true, 1, 1, '2022-04-13 15:49:55.019 +00:00', '2022-04-13 15:49:55.019 +00:00');
insert into concept (id, data_type, high_absolute, high_normal, low_absolute, low_normal, name, uuid, version, unit, organisation_id, is_voided, audit_id, key_values, active, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time) values (108002, 'Image', null, null, null, null, 'Person''s Image','b1815016-40d6-4045-9ae0-2f659fc5db6d', 0, null, 12, false, create_audit(), null, true, 1, 1, '2022-04-13 15:49:55.019 +00:00', '2022-04-13 15:49:55.019 +00:00');
insert into form_element (id, name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule) values (50116, 'Media form element', 8, false, '[]', 108001, 5569, 'fd5ad16f-c18e-45db-841c-a2f994862957', 0, 12, 'SingleSelect', null, null, create_audit(), false, null, 1, 1, '2022-04-13 10:51:44.705 +00:00', '2022-04-13 10:51:44.705 +00:00', null);
insert into form_element (id, name, display_order, is_mandatory, key_values, concept_id, form_element_group_id, uuid, version, organisation_id, type, valid_format_regex, valid_format_description_key, audit_id, is_voided, rule, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time, declarative_rule) values (50117, 'Media form element', 15, false, '[]', 108002, 5569, 'ec952777-67b2-47c2-bd7c-8e277547cb6b', 0, 12, 'SingleSelect', null, null, create_audit(), false, null, 1, 1, '2022-04-13 10:51:44.705 +00:00', '2022-04-13 10:51:44.705 +00:00', null);
update individual set observations = observations || jsonb_build_object('44163589-f76d-447d-9b6e-f5c32aa859eb', 'https://s3.amazon.com/wonderfulImage.jpg'), last_modified_date_time = '2022-04-13 10:51:44.705 +00:00' where subject_type_id = 339;
update individual set observations = observations || jsonb_build_object('b1815016-40d6-4045-9ae0-2f659fc5db6d', 'https://s3.amazon.com/wonderfulImage.jpg'), last_modified_date_time = '2022-04-13 10:51:44.705 +00:00' where subject_type_id = 339;


-- Encounter
Expand Down