use of de.symeda.sormas.api.sample.SampleAssociationType in project SORMAS-Project by hzi-braunschweig.
the class SampleService method createUserFilter.
@SuppressWarnings("rawtypes")
public Predicate createUserFilter(CriteriaQuery cq, CriteriaBuilder cb, SampleJoins joins, SampleCriteria criteria) {
Predicate filter = createUserFilterWithoutAssociations(cb, joins);
User currentUser = getCurrentUser();
final JurisdictionLevel jurisdictionLevel = currentUser.getCalculatedJurisdictionLevel();
if (jurisdictionLevel == JurisdictionLevel.LABORATORY || jurisdictionLevel == JurisdictionLevel.EXTERNAL_LABORATORY) {
return filter;
}
if (criteria != null && criteria.getSampleAssociationType() != null && criteria.getSampleAssociationType() != SampleAssociationType.ALL) {
final SampleAssociationType sampleAssociationType = criteria.getSampleAssociationType();
if (sampleAssociationType == SampleAssociationType.CASE) {
filter = CriteriaBuilderHelper.or(cb, filter, caseService.createUserFilter(cb, cq, joins.getCaze(), null));
} else if (sampleAssociationType == SampleAssociationType.CONTACT) {
filter = CriteriaBuilderHelper.or(cb, filter, contactService.createUserFilterForJoin(cb, cq, joins.getContact()));
} else if (sampleAssociationType == SampleAssociationType.EVENT_PARTICIPANT) {
filter = CriteriaBuilderHelper.or(cb, filter, eventParticipantService.createUserFilterForJoin(cb, cq, joins.getEventParticipant()));
}
} else if (currentUser.getLimitedDisease() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, CriteriaBuilderHelper.or(cb, caseService.createUserFilter(cb, cq, joins.getCaze(), null), contactService.createUserFilterForJoin(cb, cq, joins.getContact()), eventParticipantService.createUserFilterForJoin(cb, cq, joins.getEventParticipant())));
} else {
filter = CriteriaBuilderHelper.or(cb, filter, caseService.createUserFilter(cb, cq, joins.getCaze(), null), contactService.createUserFilterForJoin(cb, cq, joins.getContact()), eventParticipantService.createUserFilterForJoin(cb, cq, joins.getEventParticipant()));
}
return filter;
}
use of de.symeda.sormas.api.sample.SampleAssociationType in project SORMAS-Project by hzi-braunschweig.
the class SampleService method buildSampleListCriteriaFilter.
private Predicate buildSampleListCriteriaFilter(SampleCriteria criteria, CriteriaBuilder cb, SampleJoins joins) {
Predicate filter = null;
final SampleAssociationType sampleAssociationType = criteria.getSampleAssociationType();
if (sampleAssociationType == SampleAssociationType.CASE) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.isNotNull(joins.getCaze()));
} else if (sampleAssociationType == SampleAssociationType.CONTACT) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.isNotNull(joins.getContact()));
} else if (sampleAssociationType == SampleAssociationType.EVENT_PARTICIPANT) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.isNotNull(joins.getEventParticipant()));
}
if (criteria.getCaze() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getCaze().get(Case.UUID), criteria.getCaze().getUuid()));
}
if (criteria.getContact() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getContact().get(Contact.UUID), criteria.getContact().getUuid()));
}
if (criteria.getEventParticipant() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getEventParticipant().get(EventParticipant.UUID), criteria.getEventParticipant().getUuid()));
}
return filter;
}
use of de.symeda.sormas.api.sample.SampleAssociationType in project SORMAS-Project by hzi-braunschweig.
the class SampleGridComponent method createShipmentFilterBar.
public HorizontalLayout createShipmentFilterBar() {
HorizontalLayout shipmentFilterLayout = new HorizontalLayout();
shipmentFilterLayout.setMargin(false);
shipmentFilterLayout.setSpacing(true);
shipmentFilterLayout.setWidth(100, Unit.PERCENTAGE);
shipmentFilterLayout.addStyleName(CssStyles.VSPACE_3);
statusButtons = new HashMap<>();
HorizontalLayout buttonFilterLayout = new HorizontalLayout();
buttonFilterLayout.setSpacing(true);
{
Button statusAll = ButtonHelper.createButton(Captions.all, e -> processStatusChange(null), ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
statusAll.setCaptionAsHtml(true);
buttonFilterLayout.addComponent(statusAll);
statusButtons.put(statusAll, I18nProperties.getCaption(Captions.all));
activeStatusButton = statusAll;
createAndAddStatusButton(Captions.sampleNotShipped, NOT_SHIPPED, buttonFilterLayout);
createAndAddStatusButton(Captions.sampleShipped, SHIPPED, buttonFilterLayout);
createAndAddStatusButton(Captions.sampleReceived, RECEIVED, buttonFilterLayout);
createAndAddStatusButton(Captions.sampleReferred, REFERRED, buttonFilterLayout);
}
shipmentFilterLayout.addComponent(buttonFilterLayout);
HorizontalLayout actionButtonsLayout = new HorizontalLayout();
actionButtonsLayout.setSpacing(true);
{
// Show active/archived/all dropdown
if (UserProvider.getCurrent().hasUserRight(UserRight.SAMPLE_VIEW)) {
relevanceStatusFilter = ComboBoxHelper.createComboBoxV7();
relevanceStatusFilter.setId("relevanceStatusFilter");
relevanceStatusFilter.setWidth(140, Unit.PERCENTAGE);
relevanceStatusFilter.setNullSelectionAllowed(false);
relevanceStatusFilter.addItems((Object[]) EntityRelevanceStatus.values());
relevanceStatusFilter.setItemCaption(EntityRelevanceStatus.ACTIVE, I18nProperties.getCaption(Captions.sampleActiveSamples));
relevanceStatusFilter.setItemCaption(EntityRelevanceStatus.ARCHIVED, I18nProperties.getCaption(Captions.sampleArchivedSamples));
relevanceStatusFilter.setItemCaption(EntityRelevanceStatus.ALL, I18nProperties.getCaption(Captions.sampleAllSamples));
relevanceStatusFilter.addValueChangeListener(e -> {
criteria.relevanceStatus((EntityRelevanceStatus) e.getProperty().getValue());
samplesView.navigateTo(criteria);
});
actionButtonsLayout.addComponent(relevanceStatusFilter);
}
// Bulk operation dropdown
if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS_CASE_SAMPLES)) {
shipmentFilterLayout.setWidth(100, Unit.PERCENTAGE);
bulkOperationsDropdown = MenuBarHelper.createDropDown(Captions.bulkActions, new MenuBarHelper.MenuBarItem(I18nProperties.getCaption(Captions.bulkDelete), VaadinIcons.TRASH, selectedItem -> {
ControllerProvider.getSampleController().deleteAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {
public void run() {
samplesView.navigateTo(criteria);
}
});
}));
bulkOperationsDropdown.setVisible(samplesView.getViewConfiguration().isInEagerMode());
actionButtonsLayout.addComponent(bulkOperationsDropdown);
}
sampleTypeFilter = ComboBoxHelper.createComboBoxV7();
sampleTypeFilter.setWidth(140, Unit.PERCENTAGE);
sampleTypeFilter.setId("sampleTypeFilter");
sampleTypeFilter.setNullSelectionAllowed(false);
sampleTypeFilter.addItems((Object[]) SampleAssociationType.values());
sampleTypeFilter.setItemCaption(SampleAssociationType.ALL, I18nProperties.getEnumCaption(SampleAssociationType.ALL));
sampleTypeFilter.setItemCaption(SampleAssociationType.CASE, I18nProperties.getEnumCaption(SampleAssociationType.CASE));
sampleTypeFilter.setItemCaption(SampleAssociationType.CONTACT, I18nProperties.getEnumCaption(SampleAssociationType.CONTACT));
sampleTypeFilter.setItemCaption(SampleAssociationType.EVENT_PARTICIPANT, I18nProperties.getEnumCaption(SampleAssociationType.EVENT_PARTICIPANT));
sampleTypeFilter.addValueChangeListener(e -> {
criteria.sampleAssociationType(((SampleAssociationType) e.getProperty().getValue()));
samplesView.navigateTo(criteria);
});
actionButtonsLayout.addComponent(sampleTypeFilter);
}
shipmentFilterLayout.addComponent(actionButtonsLayout);
shipmentFilterLayout.setComponentAlignment(actionButtonsLayout, Alignment.TOP_RIGHT);
shipmentFilterLayout.setExpandRatio(actionButtonsLayout, 1);
return shipmentFilterLayout;
}
use of de.symeda.sormas.api.sample.SampleAssociationType in project SORMAS-Project by hzi-braunschweig.
the class SampleService method buildCriteriaFilter.
public Predicate buildCriteriaFilter(SampleCriteria criteria, SampleQueryContext sampleQueryContext) {
SampleJoins joins = sampleQueryContext.getJoins();
CriteriaBuilder cb = sampleQueryContext.getCriteriaBuilder();
final From<?, ?> sample = joins.getRoot();
Predicate filter = null;
final SampleAssociationType sampleAssociationType = criteria.getSampleAssociationType();
if (sampleAssociationType == SampleAssociationType.CASE) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.isNotNull(joins.getCaze()));
} else if (sampleAssociationType == SampleAssociationType.CONTACT) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.isNotNull(joins.getContact()));
} else if (sampleAssociationType == SampleAssociationType.EVENT_PARTICIPANT) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.isNotNull(joins.getEventParticipant()));
}
if (criteria.getRegion() != null) {
final String regionUuid = criteria.getRegion().getUuid();
filter = CriteriaBuilderHelper.and(cb, filter, CriteriaBuilderHelper.or(cb, cb.equal(joins.getCaseRegion().get(Region.UUID), regionUuid), cb.equal(joins.getCaseResponsibleRegion().get(Region.UUID), regionUuid), cb.equal(joins.getContactRegion().get(Region.UUID), regionUuid), cb.equal(joins.getContactCaseRegion().get(Region.UUID), regionUuid), cb.equal(joins.getContactCaseResponsibleRegion().get(Region.UUID), regionUuid), cb.equal(joins.getEventRegion().get(Region.UUID), regionUuid), cb.equal(joins.getEventParticipantJoins().getEventParticipantResponsibleRegion().get(Region.UUID), regionUuid)));
}
if (criteria.getDistrict() != null) {
final String districtUuid = criteria.getDistrict().getUuid();
filter = CriteriaBuilderHelper.and(cb, filter, CriteriaBuilderHelper.or(cb, cb.equal(joins.getCaseDistrict().get(District.UUID), districtUuid), cb.equal(joins.getCaseResponsibleDistrict().get(District.UUID), districtUuid), cb.equal(joins.getContactDistrict().get(District.UUID), districtUuid), cb.equal(joins.getContactCaseDistrict().get(District.UUID), districtUuid), cb.equal(joins.getContactCaseResponsibleDistrict().get(District.UUID), districtUuid), cb.equal(joins.getEventDistrict().get(District.UUID), districtUuid), cb.equal(joins.getEventParticipantJoins().getEventParticipantResponsibleDistrict().get(District.UUID), districtUuid)));
}
if (criteria.getLaboratory() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getLab().get(AbstractDomainObject.UUID), criteria.getLaboratory().getUuid()));
}
if (criteria.getShipped() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(sample.get(Sample.SHIPPED), criteria.getShipped()));
}
if (criteria.getReceived() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(sample.get(Sample.RECEIVED), criteria.getReceived()));
}
if (criteria.getReferred() != null) {
if (criteria.getReferred().equals(Boolean.TRUE)) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.isNotNull(sample.get(Sample.REFERRED_TO)));
} else {
filter = CriteriaBuilderHelper.and(cb, filter, cb.isNull(sample.get(Sample.REFERRED_TO)));
}
}
if (criteria.getPathogenTestResult() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(sample.get(Sample.PATHOGEN_TEST_RESULT), criteria.getPathogenTestResult()));
}
if (criteria.getCaseClassification() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getCaze().get(Case.CASE_CLASSIFICATION), criteria.getCaseClassification()));
}
if (criteria.getDisease() != null) {
Expression<Object> diseaseExpression = cb.selectCase().when(cb.isNotNull(joins.getCaze()), joins.getCaze().get(Case.DISEASE)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getContact()), joins.getContact().get(Contact.DISEASE)).otherwise(joins.getEvent().get(Event.DISEASE)));
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(diseaseExpression, criteria.getDisease()));
}
if (criteria.getCaze() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getCaze().get(Case.UUID), criteria.getCaze().getUuid()));
}
if (criteria.getContact() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getContact().get(Contact.UUID), criteria.getContact().getUuid()));
}
if (criteria.getEventParticipant() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getEventParticipant().get(EventParticipant.UUID), criteria.getEventParticipant().getUuid()));
}
if (criteria.getSampleReportDateFrom() != null && criteria.getSampleReportDateTo() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.between(sample.get(Sample.SAMPLE_DATE_TIME), criteria.getSampleReportDateFrom(), criteria.getSampleReportDateTo()));
} else if (criteria.getSampleReportDateFrom() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.greaterThanOrEqualTo(sample.get(Sample.SAMPLE_DATE_TIME), criteria.getSampleReportDateFrom()));
} else if (criteria.getSampleReportDateTo() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.lessThanOrEqualTo(sample.get(Sample.SAMPLE_DATE_TIME), criteria.getSampleReportDateTo()));
}
if (criteria.getSpecimenCondition() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(sample.get(Sample.SPECIMEN_CONDITION), criteria.getSpecimenCondition()));
}
if (criteria.getRelevanceStatus() != null) {
if (criteria.getRelevanceStatus() == EntityRelevanceStatus.ACTIVE) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.or(cb.equal(joins.getCaze().get(Case.ARCHIVED), false), cb.isNull(joins.getCaze().get(Case.ARCHIVED))));
} else if (criteria.getRelevanceStatus() == EntityRelevanceStatus.ARCHIVED) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(joins.getCaze().get(Case.ARCHIVED), true));
}
}
if (criteria.getDeleted() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(sample.get(Sample.DELETED), criteria.getDeleted()));
}
if (criteria.getCaseCodeIdLike() != null) {
String[] textFilters = criteria.getCaseCodeIdLike().split("\\s+");
for (String textFilter : textFilters) {
if (DataHelper.isNullOrEmpty(textFilter)) {
continue;
}
Predicate likeFilters = cb.or(CriteriaBuilderHelper.ilike(cb, joins.getCaze().get(Case.UUID), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, joins.getCasePerson().get(Person.FIRST_NAME), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, joins.getCasePerson().get(Person.LAST_NAME), textFilter), CriteriaBuilderHelper.ilike(cb, joins.getCaze().get(Case.EPID_NUMBER), textFilter), CriteriaBuilderHelper.ilike(cb, sample.get(Sample.UUID), textFilter), CriteriaBuilderHelper.ilike(cb, sample.get(Sample.LAB_SAMPLE_ID), textFilter), CriteriaBuilderHelper.ilike(cb, sample.get(Sample.FIELD_SAMPLE_ID), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, joins.getLab().get(Facility.NAME), textFilter));
filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}
}
if (criteria.getCaseUuids() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, sample.get(Sample.ASSOCIATED_CASE).get(Case.UUID).in(criteria.getCaseUuids()));
}
if (criteria.getContactUuids() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, sample.get(Sample.ASSOCIATED_CONTACT).get(Contact.UUID).in(criteria.getContactUuids()));
}
if (criteria.getEventParticipantUuids() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, sample.get(Sample.ASSOCIATED_EVENT_PARTICIPANT).get(EventParticipant.UUID).in(criteria.getEventParticipantUuids()));
}
return filter;
}
use of de.symeda.sormas.api.sample.SampleAssociationType in project SORMAS-Project by hzi-braunschweig.
the class SampleService method createUserFilter.
@SuppressWarnings("rawtypes")
public Predicate createUserFilter(SampleQueryContext sampleQueryContext, SampleCriteria criteria) {
final CriteriaQuery cq = sampleQueryContext.getQuery();
final CriteriaBuilder cb = sampleQueryContext.getCriteriaBuilder();
final SampleJoins joins = sampleQueryContext.getJoins();
User currentUser = getCurrentUser();
if (currentUser == null) {
return null;
}
Predicate filter = createUserFilterWithoutAssociations(cb, joins);
final JurisdictionLevel jurisdictionLevel = currentUser.getJurisdictionLevel();
if (jurisdictionLevel == JurisdictionLevel.LABORATORY || jurisdictionLevel == JurisdictionLevel.EXTERNAL_LABORATORY) {
return filter;
}
if (criteria != null && criteria.getSampleAssociationType() != null && criteria.getSampleAssociationType() != SampleAssociationType.ALL) {
final SampleAssociationType sampleAssociationType = criteria.getSampleAssociationType();
if (sampleAssociationType == SampleAssociationType.CASE) {
filter = CriteriaBuilderHelper.or(cb, filter, caseService.createUserFilter(new CaseQueryContext(cb, cq, joins.getCaseJoins()), null));
} else if (sampleAssociationType == SampleAssociationType.CONTACT) {
filter = CriteriaBuilderHelper.or(cb, filter, contactService.createUserFilter(new ContactQueryContext(cb, cq, joins.getContactJoins()), null));
} else if (sampleAssociationType == SampleAssociationType.EVENT_PARTICIPANT) {
filter = CriteriaBuilderHelper.or(cb, filter, eventParticipantService.createUserFilter(new EventParticipantQueryContext(cb, cq, joins.getEventParticipantJoins())));
}
} else if (currentUser.getLimitedDisease() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, CriteriaBuilderHelper.or(cb, caseService.createUserFilter(new CaseQueryContext(cb, cq, joins.getCaseJoins()), null), contactService.createUserFilter(new ContactQueryContext(cb, cq, joins.getContactJoins()), null), eventParticipantService.createUserFilter(new EventParticipantQueryContext(cb, cq, joins.getEventParticipantJoins()))));
} else {
filter = CriteriaBuilderHelper.or(cb, filter, caseService.createUserFilter(new CaseQueryContext(cb, cq, joins.getCaseJoins()), null), contactService.createUserFilter(new ContactQueryContext(cb, cq, joins.getContactJoins()), null), eventParticipantService.createUserFilter(new EventParticipantQueryContext(cb, cq, joins.getEventParticipantJoins())));
}
return filter;
}
Aggregations