Skip to content

Commit

Permalink
[GITFLOW]merging 'hotfix-1.73.3' into 'master-1.73.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
MateStrysewske committed Jul 25, 2022
2 parents bfafc49 + 35f9f6b commit 2c637db
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 93 deletions.
2 changes: 1 addition & 1 deletion sormas-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<parent>
<groupId>de.symeda.sormas</groupId>
<artifactId>sormas-base</artifactId>
<version>1.73.2</version>
<version>1.73.3</version>
<relativePath>../sormas-base</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class EventParticipantExportDto implements Serializable {
private long personAddressId;

private String eventUuid;
private Date eventReportDateTime;

private final EventStatus eventStatus;
private final EventInvestigationStatus eventInvestigationStatus;
Expand Down Expand Up @@ -177,7 +178,7 @@ public class EventParticipantExportDto implements Serializable {
private long contactCount;

//@formatter:off
public EventParticipantExportDto(long id, long personId, String personUuid, String eventParticipantUuid, String nationalHealthId, long personAddressId, boolean isInJurisdiction, String eventUuid,
public EventParticipantExportDto(long id, long personId, String personUuid, String eventParticipantUuid, String nationalHealthId, long personAddressId, boolean isInJurisdiction, String eventUuid, Date eventReportDateTime,

EventStatus eventStatus, EventInvestigationStatus eventInvestigationStatus, Disease eventDisease, TypeOfPlace typeOfPlace, Date eventStartDate, Date eventEndDate, String eventTitle, String eventDesc,
String eventRegion, String eventDistrict, String eventCommunity, String eventCity, String eventStreet, String eventHouseNumber,
Expand All @@ -197,6 +198,7 @@ public EventParticipantExportDto(long id, long personId, String personUuid, Stri
this.nationalHealthId = nationalHealthId;
this.personAddressId = personAddressId;
this.eventUuid = eventUuid;
this.eventReportDateTime = eventReportDateTime;

this.eventStatus = eventStatus;
this.eventInvestigationStatus = eventInvestigationStatus;
Expand Down Expand Up @@ -978,4 +980,8 @@ public void setVaccineUniiCode(String vaccineUniiCode) {
public void setVaccineAtcCode(String vaccineAtcCode) {
this.vaccineAtcCode = vaccineAtcCode;
}

public Date getEventReportDateTime() {
return eventReportDateTime;
}
}
2 changes: 1 addition & 1 deletion sormas-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sormas-base</artifactId>
<groupId>de.symeda.sormas</groupId>
<version>1.73.2</version>
<version>1.73.3</version>
<relativePath>../sormas-base</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sormas-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sormas-base</artifactId>
<groupId>de.symeda.sormas</groupId>
<version>1.73.2</version>
<version>1.73.3</version>
<relativePath>../sormas-base</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,16 +885,13 @@ public List<CaseExportDto> getExportList(

List<Long> resultCaseIds = resultList.stream().map(CaseExportDto::getId).collect(Collectors.toList());
if (!resultList.isEmpty()) {
Map<Long, Symptoms> symptoms = null;
if (ExportHelper.shouldExportFields(exportConfiguration, CaseDataDto.SYMPTOMS)) {
List<Symptoms> symptomsList = null;
CriteriaQuery<Symptoms> symptomsCq = cb.createQuery(Symptoms.class);
Root<Symptoms> symptomsRoot = symptomsCq.from(Symptoms.class);
Expression<String> symptomsIdsExpr = symptomsRoot.get(Symptoms.ID);
symptomsCq.where(symptomsIdsExpr.in(resultList.stream().map(CaseExportDto::getSymptomsId).collect(Collectors.toList())));
symptomsList = em.createQuery(symptomsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
symptoms = symptomsList.stream().collect(Collectors.toMap(Symptoms::getId, Function.identity()));
}
List<Symptoms> symptomsList = null;
CriteriaQuery<Symptoms> symptomsCq = cb.createQuery(Symptoms.class);
Root<Symptoms> symptomsRoot = symptomsCq.from(Symptoms.class);
Expression<String> symptomsIdsExpr = symptomsRoot.get(Symptoms.ID);
symptomsCq.where(symptomsIdsExpr.in(resultList.stream().map(CaseExportDto::getSymptomsId).collect(Collectors.toList())));
symptomsList = em.createQuery(symptomsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
Map<Long, Symptoms> symptoms = symptomsList.stream().collect(Collectors.toMap(Symptoms::getId, Function.identity()));

Map<Long, HealthConditions> healthConditions = null;
if (exportType == null || exportType == CaseExportType.CASE_MANAGEMENT) {
Expand Down Expand Up @@ -1048,7 +1045,7 @@ public List<CaseExportDto> getExportList(
if (exportConfiguration == null || exportConfiguration.getProperties().contains(CaseExportDto.COUNTRY)) {
exportDto.setCountry(configFacade.getEpidPrefix());
}
if (symptoms != null) {
if (ExportHelper.shouldExportFields(exportConfiguration, CaseDataDto.SYMPTOMS)) {
Optional.ofNullable(symptoms.get(exportDto.getSymptomsId()))
.ifPresent(symptom -> exportDto.setSymptoms(SymptomsFacadeEjb.toDto(symptom)));
}
Expand Down Expand Up @@ -1135,10 +1132,12 @@ public List<CaseExportDto> getExportList(
filteredImmunizations.sort(Comparator.comparing(i -> ImmunizationEntityHelper.getDateForComparison(i, false)));
Immunization mostRecentImmunization = filteredImmunizations.get(filteredImmunizations.size() - 1);
Integer numberOfDoses = mostRecentImmunization.getNumberOfDoses();
Date onsetDate = Optional.ofNullable(symptoms.get(exportDto.getSymptomsId())).map(Symptoms::getOnsetDate).orElse(null);

List<Vaccination> relevantSortedVaccinations = getRelevantSortedVaccinations(
exportDto.getUuid(),
filteredImmunizations.stream().flatMap(i -> i.getVaccinations().stream()).collect(Collectors.toList()));
List<Vaccination> relevantSortedVaccinations = vaccinationService.getRelevantSortedVaccinations(
filteredImmunizations.stream().flatMap(i -> i.getVaccinations().stream()).collect(Collectors.toList()),
onsetDate,
exportDto.getReportDate());
Vaccination firstVaccination = null;
Vaccination lastVaccination = null;

Expand Down Expand Up @@ -1281,15 +1280,6 @@ private Map<Long, UserReference> getCaseUsersForExport(List<CaseExportDto> resul
return caseUsers;
}

private List<Vaccination> getRelevantSortedVaccinations(String caseUuid, List<Vaccination> vaccinations) {
Case caze = caseService.getByUuid(caseUuid);

return vaccinations.stream()
.filter(v -> vaccinationService.isVaccinationRelevant(caze, v))
.sorted(Comparator.comparing(ImmunizationEntityHelper::getVaccinationDateForComparison))
.collect(Collectors.toList());
}

private String getNumberOfDosesFromVaccinations(Vaccination vaccination) {
return vaccination != null ? vaccination.getVaccineDose() : "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,10 @@ public List<ContactExportDto> getExportList(
Immunization mostRecentImmunization = filteredImmunizations.get(filteredImmunizations.size() - 1);
Integer numberOfDoses = mostRecentImmunization.getNumberOfDoses();

List<Vaccination> relevantSortedVaccinations = getRelevantSortedVaccinations(
exportContact.getUuid(),
filteredImmunizations.stream().flatMap(i -> i.getVaccinations().stream()).collect(Collectors.toList()));
List<Vaccination> relevantSortedVaccinations = vaccinationService.getRelevantSortedVaccinations(
filteredImmunizations.stream().flatMap(i -> i.getVaccinations().stream()).collect(Collectors.toList()),
exportContact.getLastContactDate(),
exportContact.getReportDate());
Vaccination firstVaccination = null;
Vaccination lastVaccination = null;

Expand Down Expand Up @@ -2259,15 +2260,6 @@ private User getRandomDistrictContactResponsible(District district) {
return userService.getRandomDistrictUser(district, UserRight.CONTACT_RESPONSIBLE);
}

private List<Vaccination> getRelevantSortedVaccinations(String caseUuid, List<Vaccination> vaccinations) {
Contact contact = contactService.getByUuid(caseUuid);

return vaccinations.stream()
.filter(v -> vaccinationService.isVaccinationRelevant(contact, v))
.sorted(Comparator.comparing(ImmunizationEntityHelper::getVaccinationDateForComparison))
.collect(Collectors.toList());
}

private String getNumberOfDosesFromVaccinations(Vaccination vaccination) {
return vaccination != null ? vaccination.getVaccineDose() : "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,6 @@ private void archiveAllArchivableEventParticipants(int daysAfterEventParticipant
}
}

private List<Vaccination> getRelevantSortedVaccinations(String eventUuid, List<Vaccination> vaccinations) {
Event event = eventService.getByUuid(eventUuid);

return vaccinations.stream()
.filter(v -> vaccinationService.isVaccinationRelevant(event, v))
.sorted(Comparator.comparing(ImmunizationEntityHelper::getVaccinationDateForComparison))
.collect(Collectors.toList());
}

private String getNumberOfDosesFromVaccinations(Vaccination vaccination) {
return vaccination != null ? vaccination.getVaccineDose() : "";
}
Expand Down Expand Up @@ -657,6 +648,7 @@ public List<EventParticipantExportDto> getExportList(
JurisdictionHelper.booleanSelector(cb, service.inJurisdictionOrOwned(eventParticipantQueryContext)),

event.get(Event.UUID),
event.get(Event.REPORT_DATE_TIME),

event.get(Event.EVENT_STATUS),
event.get(Event.EVENT_INVESTIGATION_STATUS),
Expand Down Expand Up @@ -804,9 +796,11 @@ public List<EventParticipantExportDto> getExportList(
Immunization mostRecentImmunization = filteredImmunizations.get(filteredImmunizations.size() - 1);
Integer numberOfDoses = mostRecentImmunization.getNumberOfDoses();

List<Vaccination> relevantSortedVaccinations = getRelevantSortedVaccinations(
exportDto.getEventUuid(),
filteredImmunizations.stream().flatMap(i -> i.getVaccinations().stream()).collect(Collectors.toList()));
List<Vaccination> relevantSortedVaccinations = vaccinationService.getRelevantSortedVaccinations(
filteredImmunizations.stream().flatMap(i -> i.getVaccinations().stream()).collect(Collectors.toList()),
exportDto.getEventStartDate(),
exportDto.getEventEndDate(),
exportDto.getEventReportDateTime());
Vaccination firstVaccination = null;
Vaccination lastVaccination = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import de.symeda.sormas.api.sormastosormas.validation.ValidationErrorGroup;
import de.symeda.sormas.api.sormastosormas.validation.ValidationErrorMessage;
import de.symeda.sormas.api.sormastosormas.validation.ValidationErrors;
import de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal;
import de.symeda.sormas.backend.common.BaseAdoService;
import de.symeda.sormas.backend.contact.Contact;
import de.symeda.sormas.backend.contact.ContactService;
Expand Down Expand Up @@ -83,6 +84,8 @@ public class SormasToSormasContactFacadeEjb extends AbstractSormasToSormasInterf
private ImmunizationService immunizationService;
@EJB
private SormasToSormasShareRequestService shareRequestService;
@EJB
private CaseFacadeEjbLocal caseFacade;

public SormasToSormasContactFacadeEjb() {
super(
Expand Down Expand Up @@ -206,7 +209,7 @@ protected void validateShareRequestBeforeAccept(SormasToSormasShareRequestDto sh
ValidationErrors.create(
new ValidationErrorGroup(Captions.Contact),
new ValidationErrorMessage(Validations.sormasToSormasAcceptContactHasNoCase))));
} else {
} else if (!caseFacade.exists(c.getCaze().getUuid())) {
List<SormasToSormasShareRequest> caseRequests = shareRequestService.getShareRequestsForCase(c.getCaze());
if (caseRequests.isEmpty()
|| caseRequests.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package de.symeda.sormas.backend.vaccination;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -45,13 +47,16 @@
import de.symeda.sormas.backend.common.CriteriaBuilderHelper;
import de.symeda.sormas.backend.contact.Contact;
import de.symeda.sormas.backend.event.Event;
import de.symeda.sormas.backend.immunization.ImmunizationEntityHelper;
import de.symeda.sormas.backend.immunization.entity.Immunization;
import de.symeda.sormas.backend.person.Person;

@Stateless
@LocalBean
public class VaccinationService extends BaseAdoService<Vaccination> {

public static final int REPORT_DATE_RELEVANT_DAYS = 14;

public VaccinationService() {
super(Vaccination.class);
}
Expand Down Expand Up @@ -118,28 +123,65 @@ public List<Vaccination> getVaccinationsByCriteria(
}

public boolean isVaccinationRelevant(Case caze, Vaccination vaccination) {
return vaccination.getVaccinationDate() != null
&& (caze.getSymptoms().getOnsetDate() != null
? DateHelper.getEndOfDay(vaccination.getVaccinationDate()).before(caze.getSymptoms().getOnsetDate())
: DateHelper.getEndOfDay(vaccination.getVaccinationDate()).before(caze.getReportDate()));
return isVaccinationRelevant(vaccination, caze.getSymptoms().getOnsetDate(), caze.getReportDate());
}

public boolean isVaccinationRelevant(Contact contact, Vaccination vaccination) {
return vaccination.getVaccinationDate() != null
&& (contact.getLastContactDate() != null
? DateHelper.getEndOfDay(vaccination.getVaccinationDate()).before(contact.getLastContactDate())
: DateHelper.getEndOfDay(vaccination.getVaccinationDate()).before(contact.getReportDateTime()));
return isVaccinationRelevant(vaccination, contact.getLastContactDate(), contact.getReportDateTime());

}

/**
* HEADS UP! When this method gets changed, most probably the database logic in
* {@link de.symeda.sormas.backend.event.EventParticipantService#updateVaccinationStatuses(Long, Disease, Date)}
* will also need an update.
*
* @param event
* to decide whether the vaccination is relevant for
* @param vaccination
* to be decided about
* @return true when the vaccination is relevant, false otherwise
*/
public boolean isVaccinationRelevant(Event event, Vaccination vaccination) {
if (vaccination.getVaccinationDate() == null) {
return false;
}
if (event.getStartDate() != null) {
return DateHelper.getEndOfDay(vaccination.getVaccinationDate()).before(event.getStartDate());
return isVaccinationRelevant(vaccination, event.getStartDate(), event.getEndDate(), event.getReportDateTime());
}

/*
* HEADS UP! If you make changes here, you most probably also need to update the database queries in
* ContactService.updateVaccinationStatuses(...) and
* EventParticipantService.updateVaccinationStatuses(...).
*/
private boolean isVaccinationRelevant(Vaccination vaccination, Date... relevanceFilterDates) {

Date relevantVaccineDate = getRelevantVaccineDate(vaccination);
for (Date comparisonDate : relevanceFilterDates) {
if (comparisonDate != null) {
return DateHelper.getEndOfDay(relevantVaccineDate).before(comparisonDate);
}
}
return event.getEndDate() != null
? DateHelper.getEndOfDay(vaccination.getVaccinationDate()).before(event.getEndDate())
: DateHelper.getEndOfDay(vaccination.getVaccinationDate()).before(event.getReportDateTime());
return false;
}

public List<Vaccination> getRelevantSortedVaccinations(List<Vaccination> vaccinations, Date... relevanceFilterDates) {

return vaccinations.stream()
.filter(v -> isVaccinationRelevant(v, relevanceFilterDates))
.sorted(Comparator.comparing(ImmunizationEntityHelper::getVaccinationDateForComparison))
.collect(Collectors.toList());
}

/**
* * Obtains the date used for calculating the relevance of a vaccination for a case/contact/event participant.
* * There is a 14-day buffer when the report date needs to be used.
* * There is an identical method for VaccinationDtos below!
*
* @param vaccination
* to obtain the relevant date from
* @return relevant date
*/
public Date getRelevantVaccineDate(Vaccination vaccination) {
return vaccination.getVaccinationDate() != null
? vaccination.getVaccinationDate()
: DateHelper.subtractDays(vaccination.getReportDate(), REPORT_DATE_RELEVANT_DAYS);
}
}
2 changes: 1 addition & 1 deletion sormas-base/dependencies/serverlibs.pom
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>sormas-base</artifactId>
<groupId>de.symeda.sormas</groupId>
<version>1.73.2</version>
<version>1.73.3</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion sormas-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>de.symeda.sormas</groupId>
<artifactId>sormas-base</artifactId>
<packaging>pom</packaging>
<version>1.73.2</version>
<version>1.73.3</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion sormas-cargoserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>de.symeda.sormas</groupId>
<artifactId>sormas-base</artifactId>
<version>1.73.2</version>
<version>1.73.3</version>
<relativePath>../sormas-base</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion sormas-ear/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>de.symeda.sormas</groupId>
<artifactId>sormas-base</artifactId>
<version>1.73.2</version>
<version>1.73.3</version>
<relativePath>../sormas-base</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion sormas-keycloak-service-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sormas-base</artifactId>
<groupId>de.symeda.sormas</groupId>
<version>1.73.2</version>
<version>1.73.3</version>
<relativePath>../sormas-base</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sormas-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>de.symeda.sormas</groupId>
<artifactId>sormas-base</artifactId>
<version>1.73.2</version>
<version>1.73.3</version>
<relativePath>../sormas-base</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion sormas-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sormas-base</artifactId>
<groupId>de.symeda.sormas</groupId>
<version>1.73.2</version>
<version>1.73.3</version>
<relativePath>../sormas-base</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Loading

0 comments on commit 2c637db

Please sign in to comment.