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

Commit c5a5255

Browse files
Merge pull request SORMAS-Foundation#3648 from hzi-braunschweig/feature-3294-Inform-External-Journal-about-canceled-or-completed-follow-ups
Feature 3294 inform external journal about canceled or completed follow ups
2 parents 0f1455b + 836b237 commit c5a5255

8 files changed

Lines changed: 308 additions & 86 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package de.symeda.sormas.api.contact;
2+
3+
import java.io.Serializable;
4+
5+
public class FollowUpStatusDto implements Serializable {
6+
7+
private static final long serialVersionUID = 6075542609471404489L;
8+
9+
private String uuid;
10+
private FollowUpStatus followUpStatus;
11+
12+
public FollowUpStatusDto(String uuid, FollowUpStatus followUpStatus) {
13+
14+
this.uuid = uuid;
15+
this.followUpStatus = followUpStatus;
16+
17+
}
18+
19+
public String getUuid() {
20+
return uuid;
21+
}
22+
23+
public void setUuid(String uuid) {
24+
this.uuid = uuid;
25+
}
26+
27+
public FollowUpStatus getFollowUpStatus() {
28+
return followUpStatus;
29+
}
30+
31+
public void setFollowUpStatus(FollowUpStatus followUpStatus) {
32+
this.followUpStatus = followUpStatus;
33+
}
34+
}

sormas-api/src/main/java/de/symeda/sormas/api/person/JournalPersonDto.java

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package de.symeda.sormas.api.person;
22

3+
import de.symeda.sormas.api.contact.FollowUpStatus;
34
import de.symeda.sormas.api.utils.PersonalData;
45
import de.symeda.sormas.api.utils.SensitiveData;
56

67
import java.io.Serializable;
78
import java.util.Date;
9+
import java.util.Objects;
810

911
import de.symeda.sormas.api.utils.PersonalData;
1012
import de.symeda.sormas.api.utils.SensitiveData;
@@ -31,8 +33,8 @@ public class JournalPersonDto implements Serializable {
3133
private Integer birthdateYYYY;
3234

3335
private Sex sex;
34-
@SensitiveData
3536
private Date latestFollowUpEndDate;
37+
private FollowUpStatus followUpStatus;
3638

3739
public String getUuid() {
3840
return uuid;
@@ -122,4 +124,54 @@ public void setLatestFollowUpEndDate(Date latestFollowUpEndDate) {
122124
this.latestFollowUpEndDate = latestFollowUpEndDate;
123125
}
124126

127+
public FollowUpStatus getFollowUpStatus() {
128+
return followUpStatus;
129+
}
130+
131+
public void setFollowUpStatus(FollowUpStatus followUpStatus) {
132+
this.followUpStatus = followUpStatus;
133+
}
134+
135+
@Override
136+
public String toString() {
137+
return uuid + ' ' + firstName + ' ' + lastName;
138+
}
139+
140+
@Override
141+
public boolean equals(Object o) {
142+
if (this == o)
143+
return true;
144+
if (o == null || getClass() != o.getClass())
145+
return false;
146+
JournalPersonDto that = (JournalPersonDto) o;
147+
return pseudonymized == that.pseudonymized
148+
&& Objects.equals(uuid, that.uuid)
149+
&& Objects.equals(firstName, that.firstName)
150+
&& Objects.equals(lastName, that.lastName)
151+
&& Objects.equals(emailAddress, that.emailAddress)
152+
&& Objects.equals(phone, that.phone)
153+
&& Objects.equals(birthdateDD, that.birthdateDD)
154+
&& Objects.equals(birthdateMM, that.birthdateMM)
155+
&& Objects.equals(birthdateYYYY, that.birthdateYYYY)
156+
&& sex == that.sex
157+
&& Objects.equals(latestFollowUpEndDate, that.latestFollowUpEndDate)
158+
&& followUpStatus == that.followUpStatus;
159+
}
160+
161+
@Override
162+
public int hashCode() {
163+
return Objects.hash(
164+
uuid,
165+
pseudonymized,
166+
firstName,
167+
lastName,
168+
emailAddress,
169+
phone,
170+
birthdateDD,
171+
birthdateMM,
172+
birthdateYYYY,
173+
sex,
174+
latestFollowUpEndDate,
175+
followUpStatus);
176+
}
125177
}

sormas-api/src/main/java/de/symeda/sormas/api/person/PersonFacade.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import de.symeda.sormas.api.Disease;
2727
import de.symeda.sormas.api.caze.CaseCriteria;
28+
import de.symeda.sormas.api.contact.FollowUpStatus;
2829
import de.symeda.sormas.api.region.DistrictReferenceDto;
2930
import de.symeda.sormas.api.user.UserReferenceDto;
3031

@@ -67,6 +68,8 @@ public interface PersonFacade {
6768

6869
Date getLatestFollowUpEndDateByUuid(String uuid);
6970

71+
FollowUpStatus getMostRelevantFollowUpStatusByUuid(String uuid);
72+
7073
boolean setSymptomJournalStatus(String personUuid, SymptomJournalStatus status);
7174

7275
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import javax.persistence.criteria.Subquery;
6060
import javax.validation.constraints.NotNull;
6161

62+
import de.symeda.sormas.api.person.JournalPersonDto;
6263
import org.apache.commons.collections.CollectionUtils;
6364
import org.slf4j.Logger;
6465
import org.slf4j.LoggerFactory;
@@ -210,6 +211,8 @@ public class ContactFacadeEjb implements ContactFacade {
210211
private FeatureConfigurationFacadeEjbLocal featureConfigurationFacade;
211212
@EJB
212213
private EventService eventService;
214+
@EJB
215+
private PersonFacadeEjb.PersonFacadeEjbLocal personFacade;
213216

214217
@Override
215218
public List<String> getAllActiveUuids() {
@@ -297,7 +300,7 @@ public ContactDto saveContact(ContactDto dto, boolean handleChanges) {
297300

298301
}
299302
if (existingContact != null) {
300-
handleExternalJournalPerson(existingContactDto, dto);
303+
handleExternalJournalPerson(dto);
301304
}
302305

303306
if (handleChanges) {
@@ -315,9 +318,14 @@ public ContactDto saveContact(ContactDto dto, boolean handleChanges) {
315318
}
316319

317320
// 5 second delay added before notifying of update so that current transaction can complete and new data can be retrieved from DB
318-
private void handleExternalJournalPerson(ContactDto existingContact, ContactDto updatedContact) {
321+
private void handleExternalJournalPerson(ContactDto updatedContact) {
319322
final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
320-
Runnable notify = () -> externalJournalService.notifyExternalJournalFollowUpUntilUpdate(updatedContact, existingContact.getFollowUpUntil());
323+
/**
324+
* The .getPersonForJournal(...) here gets the person in the state it is (most likely) known to an external journal.
325+
* Changes of related data is assumed to be not yet persisted in the database.
326+
*/
327+
JournalPersonDto existingPerson = personFacade.getPersonForJournal(updatedContact.getPerson().getUuid());
328+
Runnable notify = () -> externalJournalService.notifyExternalJournalPersonUpdate(existingPerson);
321329
executorService.schedule(notify, 5, TimeUnit.SECONDS);
322330
}
323331

sormas-backend/src/main/java/de/symeda/sormas/backend/externaljournal/ExternalJournalService.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import javax.ws.rs.core.MediaType;
3030
import javax.ws.rs.core.Response;
3131

32+
import de.symeda.sormas.api.person.JournalPersonDto;
3233
import org.apache.commons.lang3.ObjectUtils;
3334
import org.apache.commons.lang3.StringUtils;
3435
import org.apache.commons.validator.routines.EmailValidator;
@@ -201,21 +202,19 @@ public void notifyExternalJournalFollowUpUntilUpdate(ContactDto contact, Date pr
201202
/**
202203
* Notify external journals that a person has been updated
203204
*
204-
* @param existingPerson
205+
* @param existingJournalPerson
205206
* the person already available in the external journal
206-
* @param updatedPerson
207-
* the updated person in SORMAS
208207
* @return true if the person data change was considered relevant for external journals, false otherwise.
209208
*
210209
*/
211-
public boolean notifyExternalJournalPersonUpdate(PersonDto existingPerson, PersonDto updatedPerson) {
212-
boolean shouldNotify = shouldNotify(existingPerson, updatedPerson);
213-
if (shouldNotify) {
210+
public boolean notifyExternalJournalPersonUpdate(JournalPersonDto existingJournalPerson) {
211+
boolean shouldNotify = shouldNotify(existingJournalPerson);
212+
if (shouldNotify(existingJournalPerson)) {
214213
if (configFacade.getSymptomJournalConfig().getUrl() != null) {
215-
notifySymptomJournal(existingPerson.getUuid());
214+
notifySymptomJournal(existingJournalPerson.getUuid());
216215
}
217216
if (configFacade.getPatientDiaryConfig().getUrl() != null) {
218-
notifyPatientDiary(existingPerson.getUuid());
217+
notifyPatientDiary(existingJournalPerson.getUuid());
219218
}
220219
}
221220
return shouldNotify;
@@ -225,19 +224,12 @@ public boolean notifyExternalJournalPersonUpdate(PersonDto existingPerson, Perso
225224
* Note: This method just checks for changes in the Person data.
226225
* It can not check for Contact related data such as FollowUpUntil dates.
227226
*/
228-
private boolean shouldNotify(PersonDto existingPerson, PersonDto updatedPerson) {
229-
boolean relevantPerson = SymptomJournalStatus.ACCEPTED.equals(existingPerson.getSymptomJournalStatus())
230-
|| SymptomJournalStatus.REGISTERED.equals(existingPerson.getSymptomJournalStatus());
231-
boolean relevantFieldsUpdated = Comparator.comparing(PersonDto::getFirstName, Comparator.nullsLast(Comparator.naturalOrder()))
232-
.thenComparing(PersonDto::getLastName, Comparator.nullsLast(Comparator.naturalOrder()))
233-
.thenComparing(PersonDto::getEmailAddress, Comparator.nullsLast(Comparator.naturalOrder()))
234-
.thenComparing(PersonDto::getPhone, Comparator.nullsLast(Comparator.naturalOrder()))
235-
.thenComparing(PersonDto::getBirthdateDD, Comparator.nullsLast(Comparator.naturalOrder()))
236-
.thenComparing(PersonDto::getBirthdateMM, Comparator.nullsLast(Comparator.naturalOrder()))
237-
.thenComparing(PersonDto::getBirthdateYYYY, Comparator.nullsLast(Comparator.naturalOrder()))
238-
.thenComparing(PersonDto::getSex, Comparator.nullsLast(Comparator.naturalOrder()))
239-
.compare(existingPerson, updatedPerson)
240-
!= 0;
227+
private boolean shouldNotify(JournalPersonDto existingJournalPerson) {
228+
PersonDto detailedExistingPerson = personFacade.getPersonByUuid(existingJournalPerson.getUuid());
229+
boolean relevantPerson = SymptomJournalStatus.ACCEPTED.equals(detailedExistingPerson.getSymptomJournalStatus())
230+
|| SymptomJournalStatus.REGISTERED.equals(detailedExistingPerson.getSymptomJournalStatus());
231+
JournalPersonDto updatedJournalPerson = personFacade.getPersonForJournal(existingJournalPerson.getUuid());
232+
boolean relevantFieldsUpdated = !existingJournalPerson.equals(updatedJournalPerson);
241233
return relevantPerson && relevantFieldsUpdated;
242234
}
243235

@@ -296,7 +288,7 @@ public Optional<PatientDiaryPersonDto> getPatientDiaryPerson(String personUuid)
296288
/**
297289
* Attempts to register a new patient in the CLIMEDO patient diary.
298290
* Sets the person symptom journal status to REGISTERED if successful.
299-
*
291+
*
300292
* @param person
301293
* the person to register as a patient in CLIMEDO
302294
* @return true if the registration was successful, false otherwise
@@ -413,7 +405,7 @@ private boolean isPhoneAvailable(PersonDto person, String phone) {
413405

414406
/**
415407
* Queries the CLIMEDO patients for ones matching the given property
416-
*
408+
*
417409
* @param key
418410
* the name of the property to match
419411
* @param value

0 commit comments

Comments
 (0)