Search in sources :

Example 1 with FieldVisibilityCheckers

use of de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjb method onCaseChanged.

public void onCaseChanged(CaseDataDto existingCase, Case newCase, boolean syncShares) {
    // If its a new case and the case is new and the geo coordinates of the case's
    // health facility are null, set its coordinates to the case's report
    // coordinates, if available. Else if case report coordinates are null set them
    // to the facility's coordinates
    Facility facility = newCase.getHealthFacility();
    if (existingCase == null && facility != null && !FacilityHelper.isOtherOrNoneHealthFacility(facility.getUuid())) {
        if ((facility.getLatitude() == null || facility.getLongitude() == null) && newCase.getReportLat() != null && newCase.getReportLon() != null) {
            facility.setLatitude(newCase.getReportLat());
            facility.setLongitude(newCase.getReportLon());
            facilityService.ensurePersisted(facility);
        } else if (newCase.getReportLat() == null && newCase.getReportLon() == null && newCase.getReportLatLonAccuracy() == null) {
            newCase.setReportLat(facility.getLatitude());
            newCase.setReportLon(facility.getLongitude());
        }
    }
    // Clear facility type if no facility or home was selected
    if (newCase.getHealthFacility() == null || FacilityDto.NONE_FACILITY_UUID.equals(newCase.getHealthFacility().getUuid())) {
        newCase.setFacilityType(null);
    }
    // Generate epid number if missing or incomplete
    FieldVisibilityCheckers fieldVisibilityCheckers = FieldVisibilityCheckers.withCountry(configFacade.getCountryLocale());
    if (fieldVisibilityCheckers.isVisible(CaseDataDto.class, CaseDataDto.EPID_NUMBER) && !CaseLogic.isCompleteEpidNumber(newCase.getEpidNumber())) {
        newCase.setEpidNumber(generateEpidNumber(newCase.getEpidNumber(), newCase.getUuid(), newCase.getDisease(), newCase.getReportDate(), newCase.getResponsibleDistrict().getUuid()));
    }
    // update the plague type based on symptoms
    if (newCase.getDisease() == Disease.PLAGUE) {
        PlagueType plagueType = DiseaseHelper.getPlagueTypeForSymptoms(SymptomsFacadeEjb.toDto(newCase.getSymptoms()));
        if (plagueType != newCase.getPlagueType() && plagueType != null) {
            newCase.setPlagueType(plagueType);
        }
    }
    District survOffDistrict = newCase.getSurveillanceOfficer() != null ? newCase.getSurveillanceOfficer().getDistrict() : null;
    if (survOffDistrict == null || (!survOffDistrict.equals(newCase.getResponsibleDistrict()) && !survOffDistrict.equals(newCase.getDistrict()))) {
        setResponsibleSurveillanceOfficer(newCase);
    }
    updateInvestigationByStatus(existingCase, newCase);
    updatePersonAndCaseByOutcome(existingCase, newCase);
    updateCaseAge(existingCase, newCase);
    // Change the disease of all contacts if the case disease or disease details have changed
    if (existingCase != null && (newCase.getDisease() != existingCase.getDisease() || !StringUtils.equals(newCase.getDiseaseDetails(), existingCase.getDiseaseDetails()))) {
        for (Contact contact : contactService.findBy(new ContactCriteria().caze(newCase.toReference()), null)) {
            if (contact.getDisease() != newCase.getDisease() || !StringUtils.equals(contact.getDiseaseDetails(), newCase.getDiseaseDetails())) {
                // Only do the change if it hasn't been done in the mobile app before
                contact.setDisease(newCase.getDisease());
                contact.setDiseaseDetails(newCase.getDiseaseDetails());
                contactService.ensurePersisted(contact);
            }
        }
    }
    if (existingCase != null && (newCase.getDisease() != existingCase.getDisease() || !Objects.equals(newCase.getReportDate(), existingCase.getReportDate()) || !Objects.equals(newCase.getSymptoms().getOnsetDate(), existingCase.getSymptoms().getOnsetDate()))) {
        // Update follow-up until and status of all contacts
        for (Contact contact : contactService.findBy(new ContactCriteria().caze(newCase.toReference()), null)) {
            contactService.updateFollowUpDetails(contact, false);
            contactService.udpateContactStatus(contact);
        }
        for (Contact contact : contactService.getAllByResultingCase(newCase)) {
            contactService.updateFollowUpDetails(contact, false);
            contactService.udpateContactStatus(contact);
        }
    }
    updateTasksOnCaseChanged(newCase, existingCase);
    // Update case classification if the feature is enabled
    CaseClassification classification = null;
    if (configFacade.isFeatureAutomaticCaseClassification()) {
        if (newCase.getCaseClassification() != CaseClassification.NO_CASE) {
            // calculate classification
            CaseDataDto newCaseDto = toDto(newCase);
            classification = caseClassificationFacade.getClassification(newCaseDto);
            // only update when classification by system changes - user may overwrite this
            if (classification != newCase.getSystemCaseClassification()) {
                newCase.setSystemCaseClassification(classification);
                // really a change? (user may have already set it)
                if (classification != newCase.getCaseClassification()) {
                    newCase.setCaseClassification(classification);
                    newCase.setClassificationUser(null);
                    newCase.setClassificationDate(new Date());
                }
            }
        }
    }
    // calculate reference definition for cases
    if (configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) {
        boolean fulfilled = evaluateFulfilledCondition(toDto(newCase), classification);
        newCase.setCaseReferenceDefinition(fulfilled ? CaseReferenceDefinition.FULFILLED : CaseReferenceDefinition.NOT_FULFILLED);
    }
    // are not empty
    if (!newCase.getHospitalization().getPreviousHospitalizations().isEmpty() && YesNoUnknown.YES != newCase.getHospitalization().getHospitalizedPreviously()) {
        newCase.getHospitalization().setHospitalizedPreviously(YesNoUnknown.YES);
    }
    if (!newCase.getEpiData().getExposures().isEmpty() && !YesNoUnknown.YES.equals(newCase.getEpiData().getExposureDetailsKnown())) {
        newCase.getEpiData().setExposureDetailsKnown(YesNoUnknown.YES);
    }
    // Update completeness value
    newCase.setCompleteness(null);
    // changed
    if (existingCase != null && existingCase.getCaseClassification() != newCase.getCaseClassification()) {
        try {
            String message = String.format(I18nProperties.getString(MessageContents.CONTENT_CASE_CLASSIFICATION_CHANGED), DataHelper.getShortUuid(newCase.getUuid()), newCase.getCaseClassification().toString());
            notificationService.sendNotifications(NotificationType.CASE_CLASSIFICATION_CHANGED, JurisdictionHelper.getCaseRegions(newCase), null, MessageSubject.CASE_CLASSIFICATION_CHANGED, message);
        } catch (NotificationDeliveryFailedException e) {
            logger.error("NotificationDeliveryFailedException when trying to notify supervisors about the change of a case classification. ");
        }
    }
    // Unspecified VHF case has changed
    if (existingCase != null && existingCase.getDisease() == Disease.UNSPECIFIED_VHF && existingCase.getDisease() != newCase.getDisease()) {
        try {
            String message = String.format(I18nProperties.getString(MessageContents.CONTENT_DISEASE_CHANGED), DataHelper.getShortUuid(newCase.getUuid()), existingCase.getDisease().toString(), newCase.getDisease().toString());
            notificationService.sendNotifications(NotificationType.DISEASE_CHANGED, JurisdictionHelper.getCaseRegions(newCase), null, MessageSubject.DISEASE_CHANGED, message);
        } catch (NotificationDeliveryFailedException e) {
            logger.error("NotificationDeliveryFailedException when trying to notify supervisors about the change of a case disease.");
        }
    }
    // If the case is a newly created case or if it was not in a CONFIRMED status
    // and now the case is in a CONFIRMED status, notify related surveillance officers
    Set<CaseClassification> confirmedClassifications = CaseClassification.getConfirmedClassifications();
    if ((existingCase == null || !confirmedClassifications.contains(existingCase.getCaseClassification())) && confirmedClassifications.contains(newCase.getCaseClassification())) {
        sendConfirmedCaseNotificationsForEvents(newCase);
    }
    if (existingCase != null && syncShares && sormasToSormasFacade.isFeatureConfigured()) {
        syncSharesAsync(new ShareTreeCriteria(existingCase.getUuid()));
    }
    // This logic should be consistent with CaseDataForm.onQuarantineEndChange
    if (existingCase != null && existingCase.getQuarantineTo() != null && !existingCase.getQuarantineTo().equals(newCase.getQuarantineTo())) {
        newCase.setPreviousQuarantineTo(existingCase.getQuarantineTo());
    }
    if (existingCase == null) {
        vaccinationFacade.updateVaccinationStatuses(newCase);
    }
    // On German systems, correct and clean up reinfection data
    if (configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) {
        newCase.setReinfectionDetails(cleanUpReinfectionDetails(newCase.getReinfectionDetails()));
        newCase.setReinfectionStatus(CaseLogic.calculateReinfectionStatus(newCase.getReinfectionDetails()));
    }
}
Also used : ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) PlagueType(de.symeda.sormas.api.caze.PlagueType) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Date(java.util.Date) LocalDate(java.time.LocalDate) ExternalShareInfoCountAndLatestDate(de.symeda.sormas.backend.share.ExternalShareInfoCountAndLatestDate) Contact(de.symeda.sormas.backend.contact.Contact) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) District(de.symeda.sormas.backend.infrastructure.district.District) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException)

Example 2 with FieldVisibilityCheckers

use of de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers in project SORMAS-Project by hzi-braunschweig.

the class EpidemiologicalDataReadFragment method setUpControlListeners.

private void setUpControlListeners() {
    onExposureItemClickListener = (v, item) -> {
        InfoDialog infoDialog = new InfoDialog(getContext(), R.layout.dialog_exposure_read_layout, item, boundView -> FieldVisibilityAndAccessHelper.setFieldVisibilitiesAndAccesses(ExposureDto.class, (ViewGroup) boundView, new FieldVisibilityCheckers(), getFieldAccessCheckers()));
        final DialogExposureReadLayoutBinding exposureBinding = (DialogExposureReadLayoutBinding) infoDialog.getBinding();
        if (((Exposure) item).getMeansOfTransport() == MeansOfTransport.PLANE) {
            exposureBinding.exposureConnectionNumber.setCaption(I18nProperties.getCaption(Captions.exposureFlightNumber));
        }
        final FacilityType facilityType = ((Exposure) item).getLocation().getFacilityType();
        exposureBinding.exposureWorkEnvironment.setVisibility(facilityType == null || FacilityTypeGroup.WORKING_PLACE != facilityType.getFacilityTypeGroup() ? View.GONE : View.VISIBLE);
        FieldVisibilityAndAccessHelper.setFieldVisibilitiesAndAccesses(ExposureDto.class, (ViewGroup) infoDialog.getBinding().getRoot(), FieldVisibilityCheckers.withDisease(getDiseaseOfCaseOrContact(getActivityRootData())), UiFieldAccessCheckers.forSensitiveData(((PseudonymizableAdo) getActivityRootData()).isPseudonymized()));
        infoDialog.show();
    };
    onActivityAsCaseItemClickListener = (v, item) -> {
        InfoDialog infoDialog = new InfoDialog(getContext(), R.layout.dialog_activity_as_case_read_layout, item, boundView -> FieldVisibilityAndAccessHelper.setFieldVisibilitiesAndAccesses(ActivityAsCaseDto.class, (ViewGroup) boundView, getFieldVisibilityCheckers(), getFieldAccessCheckers()));
        final DialogActivityAsCaseReadLayoutBinding activityAsCaseBinding = (DialogActivityAsCaseReadLayoutBinding) infoDialog.getBinding();
        if (((ActivityAsCase) item).getMeansOfTransport() == MeansOfTransport.PLANE) {
            activityAsCaseBinding.activityAsCaseConnectionNumber.setCaption(I18nProperties.getCaption(Captions.activityAsCaseFlightNumber));
        }
        if (CountryHelper.isCountry(ConfigProvider.getServerCountryCode(), CountryHelper.COUNTRY_CODE_GERMANY)) {
            activityAsCaseBinding.activityAsCaseTypeOfPlace.setCaption(I18nProperties.getCaption(Captions.ActivityAsCase_typeOfPlaceIfSG));
        }
        final FacilityType facilityType = ((ActivityAsCase) item).getLocation().getFacilityType();
        activityAsCaseBinding.activityAsCaseWorkEnvironment.setVisibility(facilityType == null || FacilityTypeGroup.WORKING_PLACE != facilityType.getFacilityTypeGroup() ? View.GONE : View.VISIBLE);
        FieldVisibilityAndAccessHelper.setFieldVisibilitiesAndAccesses(ActivityAsCaseDto.class, (ViewGroup) infoDialog.getBinding().getRoot(), FieldVisibilityCheckers.withDisease(getDiseaseOfCaseOrContact(getActivityRootData())).andWithCountry(ConfigProvider.getServerCountryCode()), UiFieldAccessCheckers.forSensitiveData(((PseudonymizableAdo) getActivityRootData()).isPseudonymized()));
        infoDialog.show();
    };
}
Also used : DialogExposureReadLayoutBinding(de.symeda.sormas.app.databinding.DialogExposureReadLayoutBinding) InfoDialog(de.symeda.sormas.app.component.dialog.InfoDialog) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) ViewGroup(android.view.ViewGroup) ActivityAsCaseDto(de.symeda.sormas.api.activityascase.ActivityAsCaseDto) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) PseudonymizableAdo(de.symeda.sormas.app.backend.common.PseudonymizableAdo) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) DialogActivityAsCaseReadLayoutBinding(de.symeda.sormas.app.databinding.DialogActivityAsCaseReadLayoutBinding)

Example 3 with FieldVisibilityCheckers

use of de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers in project SORMAS-Project by hzi-braunschweig.

the class CampaignFormBuilder method createField.

@SuppressWarnings("unchecked")
private <T extends Field<?>> T createField(String fieldId, String caption, CampaignFormElementType type, List<CampaignFormElementStyle> styles) {
    SormasFieldGroupFieldFactory fieldFactory = new SormasFieldGroupFieldFactory(new FieldVisibilityCheckers(), UiFieldAccessCheckers.getNoop());
    T field;
    if (type == CampaignFormElementType.YES_NO) {
        field = fieldFactory.createField(Boolean.class, (Class<T>) NullableOptionGroup.class);
    } else if (type == CampaignFormElementType.TEXT || type == CampaignFormElementType.NUMBER) {
        field = fieldFactory.createField(String.class, (Class<T>) TextField.class);
    } else {
        field = null;
    }
    prepareComponent((AbstractComponent) field, fieldId, caption, type, styles);
    return field;
}
Also used : SormasFieldGroupFieldFactory(de.symeda.sormas.ui.utils.SormasFieldGroupFieldFactory) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) TextField(com.vaadin.v7.ui.TextField)

Example 4 with FieldVisibilityCheckers

use of de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers in project SORMAS-Project by hzi-braunschweig.

the class PersonContactDetailsField method editEntry.

@Override
protected void editEntry(PersonContactDetailDto entry, boolean create, Consumer<PersonContactDetailDto> commitCallback) {
    if (create && entry.getUuid() == null) {
        entry.setUuid(DataHelper.createUuid());
    }
    PersonContactDetailEditForm editForm = new PersonContactDetailEditForm(fieldVisibilityCheckers, fieldAccessCheckers);
    editForm.setValue(entry);
    final CommitDiscardWrapperComponent<PersonContactDetailEditForm> editView = new CommitDiscardWrapperComponent<>(editForm, true, editForm.getFieldGroup());
    editView.getCommitButton().setCaption(I18nProperties.getString(Strings.done));
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.entityPersonContactDetail));
    editView.addCommitListener(() -> {
        if (!editForm.getFieldGroup().isModified()) {
            final Predicate<PersonContactDetailDto> sameTypePrimaryPredicate = pcd -> pcd.getPersonContactDetailType() == entry.getPersonContactDetailType() && !entry.getUuid().equals(pcd.getUuid()) && pcd.isPrimaryContact();
            if (entry.isPrimaryContact()) {
                Optional<PersonContactDetailDto> existingPrimaryContactDetails = getContainer().getItemIds().stream().filter(sameTypePrimaryPredicate).findFirst();
                if (existingPrimaryContactDetails.isPresent()) {
                    VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingUpdatePersonContactDetails), new Label(I18nProperties.getString(Strings.messagePersonContactDetailsPrimaryDuplicate)), questionWindow -> {
                        ConfirmationComponent confirmationComponent = new ConfirmationComponent(false) {

                            private static final long serialVersionUID = 1L;

                            @Override
                            protected void onConfirm() {
                                existingPrimaryContactDetails.get().setPrimaryContact(false);
                                commitCallback.accept(editForm.getValue());
                                questionWindow.close();
                            }

                            @Override
                            protected void onCancel() {
                                entry.setPrimaryContact(false);
                                commitCallback.accept(editForm.getValue());
                                questionWindow.close();
                            }
                        };
                        confirmationComponent.getConfirmButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
                        confirmationComponent.getCancelButton().setCaption(I18nProperties.getCaption(Captions.actionCancel));
                        return confirmationComponent;
                    }, null);
                } else {
                    commitCallback.accept(editForm.getValue());
                }
            } else {
                commitCallback.accept(editForm.getValue());
            }
        }
    });
    if (!isEmpty(entry)) {
        editView.addDeleteListener(() -> {
            popupWindow.close();
            PersonContactDetailsField.this.removeEntry(entry);
        }, I18nProperties.getCaption(PersonContactDetailDto.I18N_PREFIX));
    }
}
Also used : Window(com.vaadin.ui.Window) ConfirmationComponent(de.symeda.sormas.ui.utils.ConfirmationComponent) ContentMode(com.vaadin.shared.ui.ContentMode) AbstractTableField(de.symeda.sormas.ui.caze.AbstractTableField) Table(com.vaadin.v7.ui.Table) DataHelper(de.symeda.sormas.api.utils.DataHelper) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) Predicate(java.util.function.Predicate) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) Window(com.vaadin.ui.Window) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) Captions(de.symeda.sormas.api.i18n.Captions) PersonDto(de.symeda.sormas.api.person.PersonDto) Consumer(java.util.function.Consumer) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) FieldAccessCellStyleGenerator(de.symeda.sormas.ui.utils.FieldAccessCellStyleGenerator) Label(com.vaadin.ui.Label) Optional(java.util.Optional) VaadinIcons(com.vaadin.icons.VaadinIcons) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) Label(com.vaadin.ui.Label) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) ConfirmationComponent(de.symeda.sormas.ui.utils.ConfirmationComponent)

Example 5 with FieldVisibilityCheckers

use of de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers in project SORMAS-Project by hzi-braunschweig.

the class CustomizableGrid method setColumns.

public void setColumns(List<CustomizableGridColumn> columns) {
    FieldVisibilityCheckers fieldVisibilityCheckers = FieldVisibilityCheckers.withCountry(FacadeProvider.getConfigFacade().getCountryLocale());
    super.setColumns(columns.stream().filter(column -> fieldVisibilityCheckers.isVisible(column.getClazz(), column.getPropertyId())).collect(Collectors.toList()).toArray());
}
Also used : List(java.util.List) FacadeProvider(de.symeda.sormas.api.FacadeProvider) Grid(com.vaadin.v7.ui.Grid) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Collectors(java.util.stream.Collectors) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)

Aggregations

FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)9 TextField (com.vaadin.v7.ui.TextField)3 FacadeProvider (de.symeda.sormas.api.FacadeProvider)3 Label (com.vaadin.ui.Label)2 Grid (com.vaadin.v7.ui.Grid)2 Captions (de.symeda.sormas.api.i18n.Captions)2 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)2 Strings (de.symeda.sormas.api.i18n.Strings)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ViewGroup (android.view.ViewGroup)1 VaadinIcons (com.vaadin.icons.VaadinIcons)1 ContentMode (com.vaadin.shared.ui.ContentMode)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Window (com.vaadin.ui.Window)1 FieldGroup (com.vaadin.v7.data.fieldgroup.FieldGroup)1 Converter (com.vaadin.v7.data.util.converter.Converter)1 CheckBox (com.vaadin.v7.ui.CheckBox)1 ComboBox (com.vaadin.v7.ui.ComboBox)1 DateField (com.vaadin.v7.ui.DateField)1