diff --git a/src/main/java/org/avniproject/etl/dto/ImageData.java b/src/main/java/org/avniproject/etl/dto/ImageData.java index 8adc208..54b0baf 100644 --- a/src/main/java/org/avniproject/etl/dto/ImageData.java +++ b/src/main/java/org/avniproject/etl/dto/ImageData.java @@ -4,6 +4,7 @@ public record ImageData( String uuid, String subjectFirstName, String subjectLastName, + String subjectMiddleName, String url, String conceptName, String subjectTypeName, diff --git a/src/main/java/org/avniproject/etl/dto/MediaDTO.java b/src/main/java/org/avniproject/etl/dto/MediaDTO.java index c45e237..460afb1 100644 --- a/src/main/java/org/avniproject/etl/dto/MediaDTO.java +++ b/src/main/java/org/avniproject/etl/dto/MediaDTO.java @@ -3,5 +3,5 @@ import java.net.URL; -public record MediaDTO(String uuid, String subjectFirstName, String subjectLastName, String url, String conceptName, URL signedUrl, String thumbnailUrl, URL signedThumbnailUrl, String subjectTypeName, String programEnrolment, String encounterTypeName, String lastModifiedDateTime, String createdDateTime, String syncConcept1Name, String syncConcept2Name, String syncParameterValue1, String syncParameterValue2, Object address, long entityId){ +public record MediaDTO(String uuid, String subjectFirstName, String subjectLastName, String subjectMiddleName, String url, String conceptName, URL signedUrl, String thumbnailUrl, URL signedThumbnailUrl, String subjectTypeName, String programEnrolment, String encounterTypeName, String lastModifiedDateTime, String createdDateTime, String syncConcept1Name, String syncConcept2Name, String syncParameterValue1, String syncParameterValue2, Object address, long entityId){ } diff --git a/src/main/java/org/avniproject/etl/dto/MediaSearchRequest.java b/src/main/java/org/avniproject/etl/dto/MediaSearchRequest.java index 22bcda5..49ecd05 100644 --- a/src/main/java/org/avniproject/etl/dto/MediaSearchRequest.java +++ b/src/main/java/org/avniproject/etl/dto/MediaSearchRequest.java @@ -1,9 +1,6 @@ package org.avniproject.etl.dto; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; public final class MediaSearchRequest { @@ -16,6 +13,8 @@ public final class MediaSearchRequest { private List conceptFilters = new ArrayList<>(); private Date fromDate; private Date toDate; + private String subjectName; + private List subjectNameTokens = new ArrayList<>(); public MediaSearchRequest() { } @@ -96,6 +95,23 @@ public void setToDate(Date toDate) { this.toDate = toDate; } + public String getSubjectName() { + return subjectName; + } + + public void setSubjectName(String subjectName) { + this.subjectName = subjectName; + this.setSubjectNameTokens(subjectName == null ? null : Arrays.stream(subjectName.split(" ")).toList()); + } + + public List getSubjectNameTokens() { + return subjectNameTokens; + } + + private void setSubjectNameTokens(List subjectNameTokens) { + this.subjectNameTokens = subjectNameTokens; + } + @Override public boolean equals(Object obj) { if (obj == this) return true; @@ -108,12 +124,13 @@ public boolean equals(Object obj) { Objects.equals(this.syncValues, that.syncValues) && Objects.equals(this.fromDate, that.fromDate) && Objects.equals(this.toDate, that.toDate) && - Objects.equals(this.conceptFilters, that.conceptFilters); + Objects.equals(this.conceptFilters, that.conceptFilters) && + Objects.equals(this.subjectName, that.subjectName); } @Override public int hashCode() { - return Objects.hash(subjectTypeNames, programNames, encounterTypeNames, imageConcepts, syncValues, fromDate, toDate, conceptFilters); + return Objects.hash(subjectTypeNames, programNames, encounterTypeNames, imageConcepts, syncValues, fromDate, toDate, conceptFilters, subjectName); } @Override @@ -126,7 +143,8 @@ public String toString() { "syncValues=" + syncValues + ", " + "conceptFilters=" + conceptFilters + ", " + "fromDate=" + fromDate + ", " + - "toDate=" + toDate + ']'; + "toDate=" + toDate + ", " + + "subjectName=" + subjectName + ']'; } } diff --git a/src/main/java/org/avniproject/etl/repository/rowMappers/tableMappers/MediaTable.java b/src/main/java/org/avniproject/etl/repository/rowMappers/tableMappers/MediaTable.java index 578157d..3cc522d 100644 --- a/src/main/java/org/avniproject/etl/repository/rowMappers/tableMappers/MediaTable.java +++ b/src/main/java/org/avniproject/etl/repository/rowMappers/tableMappers/MediaTable.java @@ -30,6 +30,7 @@ public List columns() { .withColumn(new Column("entity_id", Column.Type.integer)) .withColumn(new Column("subject_first_name", Column.Type.text)) .withColumn(new Column("subject_last_name", Column.Type.text)) + .withColumn(new Column("subject_middle_name", Column.Type.text)) .build(); } } diff --git a/src/main/java/org/avniproject/etl/repository/service/MediaTableRepositoryService.java b/src/main/java/org/avniproject/etl/repository/service/MediaTableRepositoryService.java index ca87878..4b9daf0 100644 --- a/src/main/java/org/avniproject/etl/repository/service/MediaTableRepositoryService.java +++ b/src/main/java/org/avniproject/etl/repository/service/MediaTableRepositoryService.java @@ -42,6 +42,7 @@ public MediaDTO setMediaDto(ResultSet rs) { compositeUUID, rs.getString("subject_first_name"), rs.getString("subject_last_name"), + rs.getString("subject_middle_name"), imageUrl, rs.getString("concept_name"), signedImageUrl, @@ -72,6 +73,7 @@ public ImageData setImageData(ResultSet rs) { return new ImageData(compositeImageUUID, rs.getString("subject_first_name"), rs.getString("subject_last_name"), + rs.getString("subject_middle_name"), imageUrl, rs.getString("concept_name"), rs.getString("subject_type_name"), diff --git a/src/main/java/org/avniproject/etl/repository/sql/MediaSearchQueryBuilder.java b/src/main/java/org/avniproject/etl/repository/sql/MediaSearchQueryBuilder.java index 8c0b067..092820d 100644 --- a/src/main/java/org/avniproject/etl/repository/sql/MediaSearchQueryBuilder.java +++ b/src/main/java/org/avniproject/etl/repository/sql/MediaSearchQueryBuilder.java @@ -6,10 +6,7 @@ import org.springframework.util.CollectionUtils; import org.stringtemplate.v4.ST; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import static org.avniproject.etl.repository.sql.SqlFile.readFile; @@ -46,6 +43,8 @@ private void addParameters(MediaSearchRequest request) { addParameter("imageConcepts", getConceptNames(request.getImageConcepts())); addParameter("fromDate", request.getFromDate()); addParameter("toDate", request.getToDate()); + addParameter("subjectName", request.getSubjectName()); + addParameter("subjectNameTokens", request.getSubjectNameTokens()); List addressRequests = request.getAddresses(); for (int index = 0; index < addressRequests.size(); index++) { diff --git a/src/main/java/org/avniproject/etl/repository/sync/MediaTableSyncAction.java b/src/main/java/org/avniproject/etl/repository/sync/MediaTableSyncAction.java index 53b2e8a..d5b2f78 100644 --- a/src/main/java/org/avniproject/etl/repository/sync/MediaTableSyncAction.java +++ b/src/main/java/org/avniproject/etl/repository/sync/MediaTableSyncAction.java @@ -103,6 +103,10 @@ private void syncNewerRows(TableMetadata mediaTableMetadata, TableMetadata table .add("syncRegistrationConcept2Name", wrapStringValue(syncRegistrationConcepts[1].getName())) .add("syncRegistrationConcept2ColumnName", wrapInQuotes(syncRegistrationConcepts[1].getColumnName())); } + if (tableMetadata.getType().equals(TableMetadata.Type.Person) && tableMetadata.hasColumn("middle_name")) { + template = template + .add("hasMiddleName", true); + } String sql = template.render(); diff --git a/src/main/resources/sql/api/searchMedia.sql.st b/src/main/resources/sql/api/searchMedia.sql.st index bd50a0c..374f175 100644 --- a/src/main/resources/sql/api/searchMedia.sql.st +++ b/src/main/resources/sql/api/searchMedia.sql.st @@ -2,6 +2,7 @@ SELECT media.id as id, media.uuid as uuid, media.subject_first_name as subject_first_name, media.subject_last_name as subject_last_name, + media.subject_middle_name as subject_middle_name, media.is_voided as is_voided, media.created_by_id as created_by_id, media.last_modified_by_id as last_modified_by_id, @@ -38,6 +39,10 @@ where media.image_url is not null and media.is_voided is false and media.created_date_time >= :fromDate and media.created_date_time \<= :toDate + and (%' or media.subject_middle_name ilike '%%' or media.subject_last_name ilike '%%') + }; separator="\n OR ">) + and media.subject_type_name in (:subjectTypeNames) and media.program_name in (:programNames) and media.encounter_type_name in (:encounterTypeNames) diff --git a/src/main/resources/sql/etl/media.sql.st b/src/main/resources/sql/etl/media.sql.st index d0d3d43..199bec6 100644 --- a/src/main/resources/sql/etl/media.sql.st +++ b/src/main/resources/sql/etl/media.sql.st @@ -3,7 +3,7 @@ insert into . (entity_id, uuid, is_voided, created_by_id, address_id, image_url, sync_parameter_key1, sync_parameter_value1, sync_parameter_key2, sync_parameter_value2, subject_type_name, encounter_type_name, program_name, - concept_name, subject_first_name, subject_last_name) + concept_name, subject_first_name, subject_last_name, subject_middle_name) select entity.id, entity.uuid, entity.is_voided, @@ -31,7 +31,12 @@ select entity.id, , , subject.first_name, - subject.last_name + subject.last_name, + + subject.middle_name + + null + from . entity inner join . subject on entity. = subject.id where entity.last_modified_date_time > ''