Skip to content

Commit

Permalink
Merge pull request #12768 from SORMAS-Foundation/feature-12604_add_li…
Browse files Browse the repository at this point in the history
…ne_listing_to_event_participant

#12604 - Add a line-listing feature to event participants
  • Loading branch information
sergiupacurariu authored Nov 24, 2023
2 parents 37e2d69 + 1ce29f7 commit c1983df
Show file tree
Hide file tree
Showing 13 changed files with 504 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ public interface Captions {
String lineListingInfrastructureData = "lineListingInfrastructureData";
String lineListingNewCasesList = "lineListingNewCasesList";
String lineListingNewContactsList = "lineListingNewContactsList";
String lineListingNewEventParticipantsList = "lineListingNewEventParticipantsList";
String lineListingSetEndDateForAll = "lineListingSetEndDateForAll";
String lineListingSharedInformation = "lineListingSharedInformation";
String linkEvent = "linkEvent";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,7 @@ public interface Strings {
String messagePersonAlreadyEventParticipant = "messagePersonAlreadyEventParticipant";
String messagePersonContactDetailsPrimaryDuplicate = "messagePersonContactDetailsPrimaryDuplicate";
String messagePersonExternalTokenWarning = "messagePersonExternalTokenWarning";
String messagePersonListAddedAsEventPerticipants = "messagePersonListAddedAsEventPerticipants";
String messagePersonMergedAddressDescription = "messagePersonMergedAddressDescription";
String messagePersonMergeNoEventParticipantRights = "messagePersonMergeNoEventParticipantRights";
String messagePersonSaved = "messagePersonSaved";
Expand Down
1 change: 1 addition & 0 deletions sormas-api/src/main/resources/captions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,7 @@ lineListingDiseaseOfSourceCase=Disease of source case
lineListingInfrastructureData=Take over infrastructure data from last line
lineListingNewCasesList=List of new cases
lineListingNewContactsList=List of new contacts
lineListingNewEventParticipantsList = List of new event participants
lineListingSharedInformation=Shared information
lineListingEdit=Edit line listing
lineListingDisableAll=Disable all line listing
Expand Down
1 change: 1 addition & 0 deletions sormas-api/src/main/resources/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,7 @@ messageSelectedPeriodTooLong = You have selected a time period that exceeds the
messagePersonAlreadyEventParticipant = The case person already is an event participant in the selected event. This case has been linked to the selected event.
messageThisPersonAlreadyEventParticipant = This person already is an event participant in the selected event.
messagePersonAddedAsEventParticipant = The new event participant was created.
messagePersonListAddedAsEventPerticipants = New event participants were created from person list submitted
messagePersonAlreadyCaseInEvent = This case is already linked to the selected event.
messagePersonContactDetailsPrimaryDuplicate = There already are primary contact details of this type recorded for this person. Do you want to set these contact details as the primary contact details instead?
messageUserSyncCanceled = <b>Sync canceled!</b><br/>The sync has been canceled. All already processed users have been successfully synced. You can now close this window.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void goToNewView() {

switch (section) {
case EVENT_PARTICIPANTS:
EventParticipantNewActivity.startActivity(getContext(), getRootUuid());
EventParticipantNewActivity.startActivity(getContext(), getRootUuid(), false);
break;
case TASKS:
TaskNewActivity.startActivityFromEvent(getContext(), getRootUuid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,22 @@ public class EventParticipantNewActivity extends BaseEditActivity<EventParticipa

private String eventUuid = null;

public static void startActivity(Context context, String eventUuid) {
BaseEditActivity.startActivity(context, EventParticipantNewActivity.class, buildBundle(eventUuid));
private boolean rapidEntry;

public static void startActivity(Context context, String eventUuid, boolean rapidEntry) {
BaseEditActivity.startActivity(context, EventParticipantNewActivity.class, buildBundle(eventUuid, rapidEntry));
}

public static Bundler buildBundle(String eventUuid) {
return buildBundle(null, 0).setEventUuid(eventUuid);
public static Bundler buildBundle(String eventUuid, boolean rapidEntry) {
return buildBundle(null, 0).setEventUuid(eventUuid).setRapidEntry(rapidEntry);
}

@Override
protected void onCreateInner(Bundle savedInstanceState) {
super.onCreateInner(savedInstanceState);
eventUuid = new Bundler(savedInstanceState).getEventUuid();
Bundler bundler = new Bundler(savedInstanceState);
eventUuid = bundler.getEventUuid();
rapidEntry = bundler.isRapidEntry();
}

@Override
Expand Down Expand Up @@ -96,7 +100,7 @@ public boolean onCreateOptionsMenu(Menu menu) {

@Override
protected BaseEditFragment buildEditFragment(PageMenuItem menuItem, EventParticipant activityRootData) {
BaseEditFragment fragment = EventParticipantNewFragment.newInstance(activityRootData);
BaseEditFragment fragment = EventParticipantNewFragment.newInstance(activityRootData, rapidEntry);
fragment.setLiveValidationDisabled(true);
return fragment;
}
Expand Down Expand Up @@ -157,8 +161,13 @@ protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
EventParticipantEditActivity
.startActivity(getContext(), getRootUuid(), eventUuid, EventParticipantSection.EVENT_PARTICIPANT_INFO);
if (((EventParticipantNewFragment) getActiveFragment()).isRapidEntry()) {
rapidEntry = true;
startActivity(getContext(), EventParticipantNewActivity.class, buildBundle(eventUuid, true));
} else {
EventParticipantEditActivity
.startActivity(getContext(), getRootUuid(), eventUuid, EventParticipantSection.EVENT_PARTICIPANT_INFO);
}
}
saveTask = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import de.symeda.sormas.api.person.Sex;
import de.symeda.sormas.app.BaseEditFragment;
import de.symeda.sormas.app.R;
import de.symeda.sormas.app.backend.common.DatabaseHelper;
import de.symeda.sormas.app.backend.event.Event;
import de.symeda.sormas.app.backend.event.EventParticipant;
import de.symeda.sormas.app.backend.location.Location;
import de.symeda.sormas.app.component.Item;
Expand All @@ -38,8 +36,12 @@ public class EventParticipantNewFragment extends BaseEditFragment<FragmentEventP
private List<Item> initialRegions;
private List<Item> initialDistricts;

public static EventParticipantNewFragment newInstance(EventParticipant activityRootData) {
return newInstance(EventParticipantNewFragment.class, null, activityRootData);
private boolean rapidEntry;

public static EventParticipantNewFragment newInstance(EventParticipant activityRootData, boolean rapidEntry) {
EventParticipantNewFragment eventParticipantNewFragment = newInstance(EventParticipantNewFragment.class, null, activityRootData);
eventParticipantNewFragment.rapidEntry = rapidEntry;
return eventParticipantNewFragment;
}

// Overrides
Expand Down Expand Up @@ -79,6 +81,11 @@ public void onLayoutBinding(FragmentEventParticipantNewLayoutBinding contentBind
Location eventLocation = record.getEvent().getEventLocation();
contentBinding.eventParticipantResponsibleRegion.setRequired(eventLocation.getRegion() == null || eventLocation.getDistrict() == null);
contentBinding.eventParticipantResponsibleDistrict.setRequired(eventLocation.getRegion() == null || eventLocation.getDistrict() == null);

contentBinding.eventParticipantRapidEntry.setValue(rapidEntry);
contentBinding.eventParticipantRapidEntry.addValueChangedListener(field -> {
rapidEntry = (Boolean) contentBinding.eventParticipantRapidEntry.getValue();
});
}

@Override
Expand All @@ -101,4 +108,8 @@ public boolean isShowSaveAction() {
public boolean isShowNewAction() {
return false;
}

public boolean isRapidEntry() {
return rapidEntry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Bundler {
private static final String EPI_WEEK = "epiWeek";
private static final String EMPTY_REPORT_DATE = "emptyReportDate";
private static final String PRESCRIPTION_UUID = "prescriptionUuid";
private static final String RAPID_ENTRY = "rapidEntry";

private final Bundle bundle;

Expand Down Expand Up @@ -250,4 +251,16 @@ public boolean isFinishInsteadOfUpNav() {
}
return false;
}

public Bundler setRapidEntry(boolean rapidEntry) {
bundle.putBoolean(RAPID_ENTRY, rapidEntry);
return this;
}

public boolean isRapidEntry() {
if (bundle.containsKey(RAPID_ENTRY)) {
return bundle.getBoolean(RAPID_ENTRY);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@

<requestFocus/>

<de.symeda.sormas.app.component.controls.ControlCheckBoxField
android:id="@+id/eventParticipant_rapidEntry"
app:caption="@string/rapidEntry"
style="@style/ControlSingleColumnStyle" />

<de.symeda.sormas.app.component.controls.ControlTextEditField
android:id="@+id/eventParticipant_involvementDescription"
android:nextFocusForward="@id/eventParticipant_firstName"
Expand Down
1 change: 1 addition & 0 deletions sormas-app/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -720,5 +720,6 @@
<string name="value_vaccine_name_unknown">Vaccine N/A</string>
<string name="value_vaccine_manufacturer_unknown">Manufacturer N/A</string>
<string name="value_environment_name_unknown">Environment Name N/A</string>
<string name="rapidEntry">Use rapid event participant entry</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;

Expand All @@ -31,6 +32,7 @@
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
import com.vaadin.v7.data.Validator;

Expand All @@ -52,16 +54,19 @@
import de.symeda.sormas.api.user.UserDto;
import de.symeda.sormas.api.user.UserRight;
import de.symeda.sormas.api.utils.DataHelper;
import de.symeda.sormas.api.utils.ValidationRuntimeException;
import de.symeda.sormas.ui.ControllerProvider;
import de.symeda.sormas.ui.SormasUI;
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.events.eventParticipantsLineListing.layout.LineListingLayout;
import de.symeda.sormas.ui.utils.ArchiveHandlers;
import de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent;
import de.symeda.sormas.ui.utils.DateFormatHelper;
import de.symeda.sormas.ui.utils.DeletableUtils;
import de.symeda.sormas.ui.utils.DeleteRestoreHandlers;
import de.symeda.sormas.ui.utils.VaadinUiUtil;
import de.symeda.sormas.ui.utils.components.automaticdeletion.DeletionLabel;
import de.symeda.sormas.ui.utils.components.linelisting.model.LineDto;
import de.symeda.sormas.ui.utils.components.page.title.TitleLayout;
import de.symeda.sormas.ui.utils.components.page.title.TitleLayoutHelper;

Expand Down Expand Up @@ -175,6 +180,11 @@ public void navigateToData(String eventParticipantUuid) {
SormasUI.get().getNavigator().navigateTo(navigationState);
}

public void navigateToIndex(String eventUuid) {
String navigationState = EventParticipantsView.VIEW_NAME + "/" + eventUuid;
SormasUI.get().getNavigator().navigateTo(navigationState);
}

public void deleteAllSelectedItems(
Collection<EventParticipantIndexDto> selectedRows,
EventParticipantsGrid eventParticipantGrid,
Expand Down Expand Up @@ -392,4 +402,76 @@ private Consumer<List<EventParticipantIndexDto>> bulkOperationCallback(
}
};
}

public void openLineListingWindow(EventReferenceDto eventReferenceDto) {

Window window = new Window(I18nProperties.getString(Strings.headingLineListing));

EventDto eventDto = FacadeProvider.getEventFacade().getByUuid(eventReferenceDto.getUuid());

LineListingLayout lineListingForm = new LineListingLayout(window, eventDto);

lineListingForm.setWidth(LineListingLayout.DEFAULT_WIDTH, Unit.PIXELS);

lineListingForm.setSaveCallback(eventParticipants -> saveEventParticipantsFromLineListing(lineListingForm, eventParticipants));

window.setContent(lineListingForm);
window.setModal(true);
window.setPositionX((int) Math.max(0, (Page.getCurrent().getBrowserWindowWidth() - lineListingForm.getWidth())) / 2);
window.setPositionY(70);
window.setResizable(false);

UI.getCurrent().addWindow(window);

}

private void saveEventParticipantsFromLineListing(LineListingLayout lineListingForm, LinkedList<LineDto<EventParticipantDto>> eventParticipants) {
try {
lineListingForm.validate();
} catch (ValidationRuntimeException e) {
Notification.show(I18nProperties.getString(Strings.errorFieldValidationFailed), "", Type.ERROR_MESSAGE);
return;
}

RegionReferenceDto region = lineListingForm.getRegion();
DistrictReferenceDto district = lineListingForm.getDistrict();
String eventUuid = lineListingForm.getEventDto().getUuid();

saveEventParticipantsList(eventUuid, eventParticipants, region, district);
lineListingForm.closeWindow();
}

private void saveEventParticipantsList(
String eventUuid,
List<LineDto<EventParticipantDto>> eventParticipants,
RegionReferenceDto region,
DistrictReferenceDto district) {

if (!eventParticipants.isEmpty()) {
LineDto<EventParticipantDto> eventParticipantLineDto = eventParticipants.get(0);
EventParticipantDto newEventParticipant = eventParticipantLineDto.getEntity();
PersonDto newPerson = eventParticipantLineDto.getPerson();

newEventParticipant.setRegion(region);
newEventParticipant.setDistrict(district);

ControllerProvider.getPersonController()
.selectOrCreatePerson(newPerson, I18nProperties.getString(Strings.infoSelectOrCreatePersonForEventParticipant), selectedPerson -> {
if (selectedPerson != null) {
if (FacadeProvider.getEventParticipantFacade().exists(selectedPerson.getUuid(), eventUuid)) {
throw new Validator.InvalidValueException(I18nProperties.getString(Strings.messageAlreadyEventParticipant));
}
newEventParticipant.setPerson(FacadeProvider.getPersonFacade().getByUuid(selectedPerson.getUuid()));
eventParticipantFacade.save(newEventParticipant);
}
saveEventParticipantsList(eventUuid, eventParticipants.subList(1, eventParticipants.size()), region, district);
}, true);
} else {
Notification notification =
new Notification(I18nProperties.getString(Strings.messagePersonListAddedAsEventPerticipants), "", Type.HUMANIZED_MESSAGE);
notification.setDelayMsec(1000);
notification.show(Page.getCurrent());
ControllerProvider.getEventParticipantController().navigateToIndex(eventUuid);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import de.symeda.sormas.ui.utils.LayoutUtil;
import de.symeda.sormas.ui.utils.MenuBarHelper;
import de.symeda.sormas.ui.utils.VaadinUiUtil;
import de.symeda.sormas.ui.utils.components.expandablebutton.ExpandableButton;

public class EventParticipantsView extends AbstractEventView implements HasName {

Expand Down Expand Up @@ -300,6 +301,12 @@ public HorizontalLayout createTopBar() {

}

if (UserProvider.getCurrent().hasUserRight(UserRight.EVENTPARTICIPANT_CREATE)) {
final ExpandableButton lineListingButton = new ExpandableButton(Captions.lineListing)
.expand(e -> ControllerProvider.getEventParticipantController().openLineListingWindow(getEventRef()));
addHeaderComponent(lineListingButton);
}

topLayout.addStyleName(CssStyles.VSPACE_3);
return topLayout;
}
Expand Down
Loading

0 comments on commit c1983df

Please sign in to comment.