Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 8b409c0

Browse files
lgallgal
authored andcommitted
Merge remote-tracking branch 'origin/development' into 3411_person-salutation
# Conflicts: # sormas-backend/src/main/resources/sql/sormas_schema.sql
2 parents 2e4116e + a09d370 commit 8b409c0

5 files changed

Lines changed: 76 additions & 37 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/i18n/Strings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ public interface Strings {
736736
String messageSymptomsHint = "messageSymptomsHint";
737737
String messageSymptomsVisitHint = "messageSymptomsVisitHint";
738738
String messageSystemFollowUpCanceled = "messageSystemFollowUpCanceled";
739+
String messageSystemFollowUpCanceledByDropping = "messageSystemFollowUpCanceledByDropping";
739740
String messageTasksDeleted = "messageTasksDeleted";
740741
String messageTemplateNotAvailable = "messageTemplateNotAvailable";
741742
String messageTreatmentCreated = "messageTreatmentCreated";

sormas-api/src/main/resources/strings.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ messageContactCaseRemoved = The source case has been removed from this contact
785785
messageContactCaseChanged = The source case of the contact has been changed
786786
messageSampleOpened = Opened sample found for search string
787787
messageSystemFollowUpCanceled = [System] Follow-up automatically canceled because contact was converted to a case
788+
messageSystemFollowUpCanceledByDropping = [System] Follow-up automatically canceled because contact was dropped
788789
messageSetContactRegionAndDistrict = Please choose a responsible region and responsible district and save the contact before removing the source case.
789790
messageAllCampaignFormsValid = All campaign forms have been successfully validated
790791
messageEnterSms = Please enter your SMS message here:

sormas-backend/src/main/java/de/symeda/sormas/backend/contact/ContactFacadeEjb.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Collections;
2929
import java.util.Comparator;
3030
import java.util.Date;
31+
import java.util.LinkedList;
3132
import java.util.List;
3233
import java.util.Map;
3334
import java.util.Optional;
@@ -90,6 +91,7 @@
9091
import de.symeda.sormas.api.followup.FollowUpDto;
9192
import de.symeda.sormas.api.i18n.Captions;
9293
import de.symeda.sormas.api.i18n.I18nProperties;
94+
import de.symeda.sormas.api.i18n.Strings;
9395
import de.symeda.sormas.api.i18n.Validations;
9496
import de.symeda.sormas.api.location.LocationDto;
9597
import de.symeda.sormas.api.person.JournalPersonDto;
@@ -156,9 +158,9 @@
156158
import de.symeda.sormas.backend.user.UserService;
157159
import de.symeda.sormas.backend.util.DateHelper8;
158160
import de.symeda.sormas.backend.util.DtoHelper;
161+
import de.symeda.sormas.backend.util.IterableHelper;
159162
import de.symeda.sormas.backend.util.ModelConstants;
160163
import de.symeda.sormas.backend.util.Pseudonymizer;
161-
import de.symeda.sormas.backend.util.QueryHelper;
162164
import de.symeda.sormas.backend.visit.Visit;
163165
import de.symeda.sormas.backend.visit.VisitService;
164166

@@ -308,6 +310,9 @@ public ContactDto saveContact(ContactDto dto, boolean handleChanges) {
308310
final boolean dropped = entity.getContactStatus() == ContactStatus.DROPPED;
309311
if (dropped || convertedToCase) {
310312
entity.setFollowUpStatus(FollowUpStatus.CANCELED);
313+
entity.setFollowUpComment(
314+
I18nProperties
315+
.getString(convertedToCase ? Strings.messageSystemFollowUpCanceled : Strings.messageSystemFollowUpCanceledByDropping));
311316
} else {
312317
contactService.updateFollowUpUntilAndStatus(entity);
313318
}
@@ -909,8 +914,7 @@ public List<ContactIndexDetailedDto> getIndexDetailedList(
909914

910915
// Load event count and latest events info per contact
911916
Map<String, List<ContactEventSummaryDetails>> eventSummaries =
912-
eventService.getEventSummaryDetailsByContacts(
913-
dtos.stream().map(ContactIndexDetailedDto::getUuid).collect(Collectors.toList()))
917+
eventService.getEventSummaryDetailsByContacts(dtos.stream().map(ContactIndexDetailedDto::getUuid).collect(Collectors.toList()))
914918
.stream()
915919
.collect(Collectors.groupingBy(ContactEventSummaryDetails::getContactUuid, Collectors.toList()));
916920
for (ContactIndexDetailedDto contact : dtos) {
@@ -979,23 +983,36 @@ public int[] getContactCountsByCasesForDashboard(List<Long> contactIds) {
979983
}
980984
}
981985

986+
@SuppressWarnings("JpaQueryApiInspection")
982987
@Override
983988
public int getNonSourceCaseCountForDashboard(List<String> caseUuids) {
984989

985990
if (CollectionUtils.isEmpty(caseUuids)) {
986991
// Avoid empty IN clause
987992
return 0;
993+
} else if (caseUuids.size() > ModelConstants.PARAMETER_LIMIT) {
994+
List<BigInteger> countResults = new LinkedList<>();
995+
IterableHelper.executeBatched(caseUuids, ModelConstants.PARAMETER_LIMIT, batchedCaseUuids -> {
996+
Query query = em.createNativeQuery(
997+
String.format(
998+
"SELECT DISTINCT count(case1_.id) FROM contact AS contact0_ LEFT OUTER JOIN cases AS case1_ ON (contact0_.%s_id = case1_.id) WHERE case1_.%s IN (:uuidList)",
999+
Contact.RESULTING_CASE.toLowerCase(),
1000+
Case.UUID));
1001+
query.setParameter("uuidList", batchedCaseUuids);
1002+
countResults.add((BigInteger) query.getSingleResult());
1003+
});
1004+
return countResults.stream().collect(Collectors.summingInt(BigInteger::intValue));
1005+
} else {
1006+
Query query = em.createNativeQuery(
1007+
String.format(
1008+
"SELECT DISTINCT count(case1_.id) FROM contact AS contact0_ LEFT OUTER JOIN cases AS case1_ ON (contact0_.%s_id = case1_.id) WHERE case1_.%s IN (:uuidList)",
1009+
Contact.RESULTING_CASE.toLowerCase(),
1010+
Case.UUID));
1011+
query.setParameter("uuidList", caseUuids);
1012+
BigInteger count = (BigInteger) query.getSingleResult();
1013+
return count.intValue();
9881014
}
9891015

990-
Query query = em.createNativeQuery(
991-
String.format(
992-
"SELECT DISTINCT count(case1_.id) FROM contact AS contact0_ LEFT OUTER JOIN cases AS case1_ ON (contact0_.%s_id = case1_.id) WHERE case1_.%s IN (%s)",
993-
Contact.RESULTING_CASE.toLowerCase(),
994-
Case.UUID,
995-
QueryHelper.concatStrings(caseUuids)));
996-
997-
BigInteger count = (BigInteger) query.getSingleResult();
998-
return count.intValue();
9991016
}
10001017

10011018
public Contact fromDto(@NotNull ContactDto source) {
@@ -1025,10 +1042,9 @@ public Contact fromDto(@NotNull ContactDto source) {
10251042

10261043
// use only date, not time
10271044
target.setMultiDayContact(source.isMultiDayContact());
1028-
if(source.isMultiDayContact()) {
1029-
target.setFirstContactDate(source.getFirstContactDate() != null ?
1030-
DateHelper8.toDate(DateHelper8.toLocalDate(source.getFirstContactDate())) :
1031-
null);
1045+
if (source.isMultiDayContact()) {
1046+
target.setFirstContactDate(
1047+
source.getFirstContactDate() != null ? DateHelper8.toDate(DateHelper8.toLocalDate(source.getFirstContactDate())) : null);
10321048
} else {
10331049
target.setFirstContactDate(null);
10341050
}

sormas-backend/src/main/java/de/symeda/sormas/backend/sample/SampleService.java

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.math.BigInteger;
2121
import java.util.Date;
2222
import java.util.HashMap;
23+
import java.util.LinkedList;
2324
import java.util.List;
2425
import java.util.Map;
2526
import java.util.stream.Collectors;
@@ -38,6 +39,8 @@
3839
import javax.persistence.criteria.Predicate;
3940
import javax.persistence.criteria.Root;
4041

42+
import de.symeda.sormas.backend.util.IterableHelper;
43+
import de.symeda.sormas.backend.util.ModelConstants;
4144
import org.apache.commons.collections.CollectionUtils;
4245

4346
import de.symeda.sormas.api.EntityRelevanceStatus;
@@ -243,26 +246,38 @@ public Map<PathogenTestResultType, Long> getNewTestResultCountByResultType(List<
243246
// Avoid parameter limit by joining caseIds to a String instead of n parameters
244247
StringBuilder queryBuilder = new StringBuilder();
245248
//@formatter:off
246-
queryBuilder.append("WITH sortedsamples AS (SELECT DISTINCT ON (").append(Sample.ASSOCIATED_CASE).append("_id) ")
247-
.append(Sample.ASSOCIATED_CASE).append("_id, ").append(Sample.PATHOGEN_TEST_RESULT).append(", ").append(Sample.SAMPLE_DATE_TIME)
248-
.append(" FROM ").append(Sample.TABLE_NAME).append(" WHERE (").append(Sample.SPECIMEN_CONDITION).append(" IS NULL OR ")
249-
.append(Sample.SPECIMEN_CONDITION).append(" = '").append(SpecimenCondition.ADEQUATE.name()).append("') AND ").append(Sample.TABLE_NAME)
250-
.append(".").append(Sample.DELETED).append(" = false ORDER BY ").append(Sample.ASSOCIATED_CASE).append("_id, ")
251-
.append(Sample.SAMPLE_DATE_TIME).append(" desc) SELECT sortedsamples.").append(Sample.PATHOGEN_TEST_RESULT).append(", COUNT(")
252-
.append(Sample.ASSOCIATED_CASE).append("_id) FROM sortedsamples JOIN ").append(Case.TABLE_NAME).append(" ON sortedsamples.")
253-
.append(Sample.ASSOCIATED_CASE).append("_id = ").append(Case.TABLE_NAME).append(".id ")
254-
.append(" WHERE sortedsamples.").append(Sample.ASSOCIATED_CASE).append("_id IN (").append(QueryHelper.concatLongs(caseIds)).append(") ")
255-
.append(" GROUP BY sortedsamples." + Sample.PATHOGEN_TEST_RESULT);
256-
//@formatter:on
257-
258-
Query query = em.createNativeQuery(queryBuilder.toString());
259-
260-
@SuppressWarnings("unchecked")
261-
List<Object[]> results = query.getResultList();
262-
263-
return results.stream()
264-
.filter(e -> e[0] != null)
265-
.collect(Collectors.toMap(e -> PathogenTestResultType.valueOf((String) e[0]), e -> ((BigInteger) e[1]).longValue()));
249+
queryBuilder.append("WITH sortedsamples AS (SELECT DISTINCT ON (").append(Sample.ASSOCIATED_CASE).append("_id) ")
250+
.append(Sample.ASSOCIATED_CASE).append("_id, ").append(Sample.PATHOGEN_TEST_RESULT).append(", ").append(Sample.SAMPLE_DATE_TIME)
251+
.append(" FROM ").append(Sample.TABLE_NAME).append(" WHERE (").append(Sample.SPECIMEN_CONDITION).append(" IS NULL OR ")
252+
.append(Sample.SPECIMEN_CONDITION).append(" = '").append(SpecimenCondition.ADEQUATE.name()).append("') AND ").append(Sample.TABLE_NAME)
253+
.append(".").append(Sample.DELETED).append(" = false ORDER BY ").append(Sample.ASSOCIATED_CASE).append("_id, ")
254+
.append(Sample.SAMPLE_DATE_TIME).append(" desc) SELECT sortedsamples.").append(Sample.PATHOGEN_TEST_RESULT).append(", COUNT(")
255+
.append(Sample.ASSOCIATED_CASE).append("_id) FROM sortedsamples JOIN ").append(Case.TABLE_NAME).append(" ON sortedsamples.")
256+
.append(Sample.ASSOCIATED_CASE).append("_id = ").append(Case.TABLE_NAME).append(".id ")
257+
.append(" WHERE sortedsamples.").append(Sample.ASSOCIATED_CASE).append("_id IN (:caseIds)")
258+
.append(" GROUP BY sortedsamples." + Sample.PATHOGEN_TEST_RESULT);
259+
//@formatter:on
260+
261+
if (caseIds.size() < ModelConstants.PARAMETER_LIMIT) {
262+
List<Object[]> results;
263+
Query query = em.createNativeQuery(queryBuilder.toString());
264+
query.setParameter("caseIds", caseIds);
265+
results = query.getResultList();
266+
267+
return results.stream()
268+
.filter(e -> e[0] != null)
269+
.collect(Collectors.toMap(e -> PathogenTestResultType.valueOf((String) e[0]), e -> ((BigInteger) e[1]).longValue()));
270+
} else {
271+
List<Object[]> results = new LinkedList<>();
272+
IterableHelper.executeBatched(caseIds, ModelConstants.PARAMETER_LIMIT, batchedCaseIds -> {
273+
Query query = em.createNativeQuery(queryBuilder.toString());
274+
query.setParameter("caseIds", batchedCaseIds);
275+
results.addAll(query.getResultList());
276+
});
277+
return results.stream()
278+
.filter(e -> e[0] != null)
279+
.collect(Collectors.toMap(e -> PathogenTestResultType.valueOf((String) e[0]), e -> ((BigInteger) e[1]).longValue()));
280+
}
266281
}
267282

268283
@Override

sormas-backend/src/main/resources/sql/sormas_schema.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6084,6 +6084,12 @@ CREATE TABLE labmessage (
60846084
CREATE TABLE labmessage_history (LIKE labmessage);
60856085

60866086
INSERT INTO schema_version (version_number, comment) VALUES (291, 'Add LabMessage #3486');
6087+
6088+
-- 2020-12-11 Create contacts-visits index #3673
6089+
CREATE INDEX IF NOT EXISTS idx_contacts_visits_contact_id ON contacts_visits USING HASH (contact_id);
6090+
6091+
INSERT INTO schema_version (version_number, comment) VALUES (292, 'Create contacts-visits index #3673');
6092+
60876093
-- SurvNet Adaptations - Create new field “Salutation” for persons #3411
60886094
ALTER TABLE person
60896095
ADD COLUMN salutation varchar(255),
@@ -6093,6 +6099,6 @@ ALTER TABLE person_history
60936099
ADD COLUMN salutation varchar(255),
60946100
ADD COLUMN othersalutation text;
60956101

6096-
INSERT INTO schema_version (version_number, comment) VALUES (292, 'SurvNet Adaptations - Create new field “Salutation” for persons #3411');
6102+
INSERT INTO schema_version (version_number, comment) VALUES (293, 'SurvNet Adaptations - Create new field “Salutation” for persons #3411');
60976103

60986104
-- *** Insert new sql commands BEFORE this line ***

0 commit comments

Comments
 (0)