Skip to content

Commit

Permalink
Merge pull request #12893 from SORMAS-Foundation/#12794-Link_event_to…
Browse files Browse the repository at this point in the history
…_case_with_existent_event_participant

#12794 - Link event to case with existent event participant
  • Loading branch information
MateStrysewske authored Jan 17, 2024
2 parents 0fddd67 + 60f604a commit 166b58a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.j256.ormlite.dao.Dao;

import android.util.Log;

import de.symeda.sormas.app.backend.caze.Case;
import de.symeda.sormas.app.backend.common.AbstractAdoDao;
import de.symeda.sormas.app.backend.common.AbstractDomainObject;
Expand Down Expand Up @@ -67,27 +66,34 @@ public List<EventParticipant> getByEvent(Event event) {
}
}

public boolean eventParticipantAlreadyExists(Event event, Person person) {
public List<EventParticipant> getByEventAndPerson(Event event, Person person) {

if (event.isSnapshot()) {
throw new IllegalArgumentException("Does not support snapshot entities");
}

try {
List<EventParticipant> eventParticipants = queryBuilder().where()
return queryBuilder().where()
.eq(EventParticipant.EVENT + "_id", event)
.and()
.eq(AbstractDomainObject.SNAPSHOT, false)
.and()
.eq(EventParticipant.PERSON + "_id", person)
.query();
return eventParticipants.size() > 0;
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform getByEvent on EventParticipant");
Log.e(getTableName(), "Could not perform getByEventAndPerson on EventParticipant");
throw new RuntimeException(e);
}
}

public boolean eventParticipantAlreadyExists(Event event, Person person) {
if (event.isSnapshot()) {
throw new IllegalArgumentException("Does not support snapshot entities");
}

return getByEventAndPerson(event, person).size() > 0;
}

public Long countByEvent(Event event) {
if (event.isSnapshot()) {
throw new IllegalArgumentException("Does not support snapshot entities");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.content.Context;
import android.os.AsyncTask;
import android.view.Menu;

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.caze.CaseClassification;
import de.symeda.sormas.api.caze.CaseOrigin;
Expand Down Expand Up @@ -347,21 +346,23 @@ private void linkEventToCase() {

EventPickOrCreateDialog.pickOrCreateEvent(caze, null, event -> {
if (event != null) {
//link existing event to case
EventParticipant eventParticipantToSave = DatabaseHelper.getEventParticipantDao().build();
eventParticipantToSave.setPerson(caze.getPerson());
eventParticipantToSave.setEvent(event);
eventParticipantToSave.setResultingCaseUuid(caze.getUuid());
EventParticipantSaver eventParticipantSaver = new EventParticipantSaver(this);

//link existing event to case
if (!isEventLinkedToCase(caze, event)) {
boolean eventParticipantAlreadyExists =
DatabaseHelper.getEventParticipantDao().eventParticipantAlreadyExists(event, caze.getPerson());
eventParticipantSaver.saveEventParticipantLinkedToCase(eventParticipantToSave, eventParticipantAlreadyExists);

EventParticipant eventParticipant;
if (eventParticipantAlreadyExists) {
eventParticipant = DatabaseHelper.getEventParticipantDao().getByEventAndPerson(event, caze.getPerson()).get(0);
NotificationHelper.showNotification(this, WARNING, I18nProperties.getString(Strings.messagePersonAlreadyEventParticipant));
} else {
eventParticipant = DatabaseHelper.getEventParticipantDao().build();
eventParticipant.setPerson(caze.getPerson());
eventParticipant.setEvent(event);
}
eventParticipant.setResultingCaseUuid(caze.getUuid());
eventParticipantSaver.saveEventParticipantLinkedToCase(eventParticipant, eventParticipantAlreadyExists);

} else {
NotificationHelper
Expand Down

0 comments on commit 166b58a

Please sign in to comment.