|
28 | 28 | import java.util.Collections; |
29 | 29 | import java.util.Comparator; |
30 | 30 | import java.util.Date; |
| 31 | +import java.util.LinkedList; |
31 | 32 | import java.util.List; |
32 | 33 | import java.util.Map; |
33 | 34 | import java.util.Optional; |
|
90 | 91 | import de.symeda.sormas.api.followup.FollowUpDto; |
91 | 92 | import de.symeda.sormas.api.i18n.Captions; |
92 | 93 | import de.symeda.sormas.api.i18n.I18nProperties; |
| 94 | +import de.symeda.sormas.api.i18n.Strings; |
93 | 95 | import de.symeda.sormas.api.i18n.Validations; |
94 | 96 | import de.symeda.sormas.api.location.LocationDto; |
95 | 97 | import de.symeda.sormas.api.person.JournalPersonDto; |
|
156 | 158 | import de.symeda.sormas.backend.user.UserService; |
157 | 159 | import de.symeda.sormas.backend.util.DateHelper8; |
158 | 160 | import de.symeda.sormas.backend.util.DtoHelper; |
| 161 | +import de.symeda.sormas.backend.util.IterableHelper; |
159 | 162 | import de.symeda.sormas.backend.util.ModelConstants; |
160 | 163 | import de.symeda.sormas.backend.util.Pseudonymizer; |
161 | | -import de.symeda.sormas.backend.util.QueryHelper; |
162 | 164 | import de.symeda.sormas.backend.visit.Visit; |
163 | 165 | import de.symeda.sormas.backend.visit.VisitService; |
164 | 166 |
|
@@ -308,6 +310,9 @@ public ContactDto saveContact(ContactDto dto, boolean handleChanges) { |
308 | 310 | final boolean dropped = entity.getContactStatus() == ContactStatus.DROPPED; |
309 | 311 | if (dropped || convertedToCase) { |
310 | 312 | entity.setFollowUpStatus(FollowUpStatus.CANCELED); |
| 313 | + entity.setFollowUpComment( |
| 314 | + I18nProperties |
| 315 | + .getString(convertedToCase ? Strings.messageSystemFollowUpCanceled : Strings.messageSystemFollowUpCanceledByDropping)); |
311 | 316 | } else { |
312 | 317 | contactService.updateFollowUpUntilAndStatus(entity); |
313 | 318 | } |
@@ -909,8 +914,7 @@ public List<ContactIndexDetailedDto> getIndexDetailedList( |
909 | 914 |
|
910 | 915 | // Load event count and latest events info per contact |
911 | 916 | 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())) |
914 | 918 | .stream() |
915 | 919 | .collect(Collectors.groupingBy(ContactEventSummaryDetails::getContactUuid, Collectors.toList())); |
916 | 920 | for (ContactIndexDetailedDto contact : dtos) { |
@@ -979,23 +983,36 @@ public int[] getContactCountsByCasesForDashboard(List<Long> contactIds) { |
979 | 983 | } |
980 | 984 | } |
981 | 985 |
|
| 986 | + @SuppressWarnings("JpaQueryApiInspection") |
982 | 987 | @Override |
983 | 988 | public int getNonSourceCaseCountForDashboard(List<String> caseUuids) { |
984 | 989 |
|
985 | 990 | if (CollectionUtils.isEmpty(caseUuids)) { |
986 | 991 | // Avoid empty IN clause |
987 | 992 | 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(); |
988 | 1014 | } |
989 | 1015 |
|
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(); |
999 | 1016 | } |
1000 | 1017 |
|
1001 | 1018 | public Contact fromDto(@NotNull ContactDto source) { |
@@ -1025,10 +1042,9 @@ public Contact fromDto(@NotNull ContactDto source) { |
1025 | 1042 |
|
1026 | 1043 | // use only date, not time |
1027 | 1044 | 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); |
1032 | 1048 | } else { |
1033 | 1049 | target.setFirstContactDate(null); |
1034 | 1050 | } |
|
0 commit comments