Search in sources :

Example 1 with SampleMaterial

use of de.symeda.sormas.api.sample.SampleMaterial in project SORMAS-Project by hzi-braunschweig.

the class SampleFacadeEjb method getSimilarSamples.

@Override
public List<SampleDto> getSimilarSamples(SampleSimilarityCriteria criteria) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<Sample> cq = cb.createQuery(Sample.class);
    final Root<Sample> root = cq.from(Sample.class);
    cq.distinct(true);
    SampleJoins<Sample> joins = new SampleJoins<>(root);
    SampleCriteria sampleCriteria = new SampleCriteria();
    sampleCriteria.caze(criteria.getCaze()).contact(criteria.getContact()).eventParticipant(criteria.getEventParticipant());
    Predicate filter = sampleService.createUserFilter(cq, cb, joins, sampleCriteria);
    filter = CriteriaBuilderHelper.and(cb, filter, sampleService.buildCriteriaFilter(sampleCriteria, cb, joins));
    Predicate similarityFilter = null;
    if (criteria.getLabSampleId() != null) {
        similarityFilter = cb.equal(root.get(Sample.LAB_SAMPLE_ID), criteria.getLabSampleId());
    }
    Date sampleDateTime = criteria.getSampleDateTime();
    SampleMaterial sampleMaterial = criteria.getSampleMaterial();
    if (sampleDateTime != null && sampleMaterial != null) {
        Predicate dateAndMaterialFilter = cb.and(cb.between(root.get(Sample.SAMPLE_DATE_TIME), DateHelper.getStartOfDay(DateHelper.subtractDays(sampleDateTime, SIMILARITY_DATE_TIME_THRESHOLD)), DateHelper.getEndOfDay(DateHelper.addDays(sampleDateTime, SIMILARITY_DATE_TIME_THRESHOLD))), cb.equal(root.get(Sample.SAMPLE_MATERIAL), sampleMaterial));
        similarityFilter = CriteriaBuilderHelper.or(cb, similarityFilter, dateAndMaterialFilter);
    }
    filter = CriteriaBuilderHelper.and(cb, filter, similarityFilter);
    if (filter != null) {
        cq.where(filter);
    }
    List<Sample> samples = em.createQuery(cq).getResultList();
    if (samples.size() == 0 && (sampleDateTime == null || sampleMaterial == null)) {
        return getByCriteria(sampleCriteria);
    }
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
    return samples.stream().map(s -> convertToDto(s, pseudonymizer)).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) StringUtils(org.apache.commons.lang3.StringUtils) Valid(javax.validation.Valid) Page(de.symeda.sormas.api.common.Page) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SormasToSormasOriginInfoFacadeEjb(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) DiseaseHelper(de.symeda.sormas.api.DiseaseHelper) FacilityHelper(de.symeda.sormas.api.infrastructure.facility.FacilityHelper) NotNull(javax.validation.constraints.NotNull) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) EventFacadeEjb(de.symeda.sormas.backend.event.EventFacadeEjb) UserRoleConfigFacadeEjbLocal(de.symeda.sormas.backend.user.UserRoleConfigFacadeEjb.UserRoleConfigFacadeEjbLocal) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) Selection(javax.persistence.criteria.Selection) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) SampleFacade(de.symeda.sormas.api.sample.SampleFacade) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) Case(de.symeda.sormas.backend.caze.Case) SampleReferenceDto(de.symeda.sormas.api.sample.SampleReferenceDto) SampleListEntryDto(de.symeda.sormas.api.sample.SampleListEntryDto) LocalBean(javax.ejb.LocalBean) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto) SampleJurisdictionFlagsDto(de.symeda.sormas.api.sample.SampleJurisdictionFlagsDto) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) DataHelper(de.symeda.sormas.api.utils.DataHelper) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) SortProperty(de.symeda.sormas.api.utils.SortProperty) Captions(de.symeda.sormas.api.i18n.Captions) EventParticipantFacadeEjb(de.symeda.sormas.backend.event.EventParticipantFacadeEjb) ContactService(de.symeda.sormas.backend.contact.ContactService) SampleDto(de.symeda.sormas.api.sample.SampleDto) ContactFacadeEjb(de.symeda.sormas.backend.contact.ContactFacadeEjb) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LoggerFactory(org.slf4j.LoggerFactory) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) NotificationService(de.symeda.sormas.backend.common.NotificationService) UserRole(de.symeda.sormas.api.user.UserRole) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CaseService(de.symeda.sormas.backend.caze.CaseService) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) Person(de.symeda.sormas.backend.person.Person) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) Collection(java.util.Collection) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) List(java.util.List) MessageContents(de.symeda.sormas.backend.common.messaging.MessageContents) CoreAdo(de.symeda.sormas.backend.common.CoreAdo) Location(de.symeda.sormas.backend.location.Location) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) ContactFacadeEjbLocal(de.symeda.sormas.backend.contact.ContactFacadeEjb.ContactFacadeEjbLocal) DateHelper(de.symeda.sormas.api.utils.DateHelper) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) Function(java.util.function.Function) PathogenTestFacadeEjbLocal(de.symeda.sormas.backend.sample.PathogenTestFacadeEjb.PathogenTestFacadeEjbLocal) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) AdditionalTestFacadeEjbLocal(de.symeda.sormas.backend.sample.AdditionalTestFacadeEjb.AdditionalTestFacadeEjbLocal) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) SormasToSormasOriginInfoFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb.SormasToSormasOriginInfoFacadeEjbLocal) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) Logger(org.slf4j.Logger) Validations(de.symeda.sormas.api.i18n.Validations) MessageSubject(de.symeda.sormas.backend.common.messaging.MessageSubject) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) Event(de.symeda.sormas.backend.event.Event) UserRight(de.symeda.sormas.api.user.UserRight) SampleExportDto(de.symeda.sormas.api.sample.SampleExportDto) NotificationType(de.symeda.sormas.api.user.NotificationType) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) SampleSimilarityCriteria(de.symeda.sormas.api.sample.SampleSimilarityCriteria) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial)

Example 2 with SampleMaterial

use of de.symeda.sormas.api.sample.SampleMaterial in project SORMAS-Project by hzi-braunschweig.

the class DevModeView method createSamplesGeneratorLayout.

private VerticalLayout createSamplesGeneratorLayout() {
    VerticalLayout sampleGeneratorLayout = new VerticalLayout();
    sampleGeneratorLayout.setMargin(false);
    sampleGeneratorLayout.setSpacing(false);
    Label heading = new Label(I18nProperties.getCaption(Captions.devModeGenerateSamples));
    CssStyles.style(heading, CssStyles.H2);
    sampleGeneratorLayout.addComponent(heading);
    HorizontalLayout sampleOptionsFirstLineLayout = new HorizontalLayout();
    TextField sampleCountField = new TextField();
    sampleCountField.setCaption(I18nProperties.getCaption(Captions.devModeSampleCount));
    sampleGeneratorConfigBinder.forField(sampleCountField).withConverter(new StringToIntegerConverter("Must be a number")).bind(SampleGenerationConfig::getSampleCount, SampleGenerationConfig::setSampleCount);
    sampleOptionsFirstLineLayout.addComponent(sampleCountField);
    DateField startDateField = new DateField();
    startDateField.setCaption(I18nProperties.getCaption(Captions.devModeSampleStartDate));
    startDateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
    startDateField.setLenient(true);
    sampleGeneratorConfigBinder.bind(startDateField, SampleGenerationConfig::getStartDate, SampleGenerationConfig::setStartDate);
    sampleOptionsFirstLineLayout.addComponent(startDateField);
    DateField endDateField = new DateField();
    endDateField.setCaption(I18nProperties.getCaption(Captions.devModeSampleEndDate));
    endDateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
    endDateField.setLenient(true);
    sampleGeneratorConfigBinder.bind(endDateField, SampleGenerationConfig::getEndDate, SampleGenerationConfig::setEndDate);
    sampleOptionsFirstLineLayout.addComponent(endDateField);
    ComboBox<Disease> diseaseField = new ComboBox<>(null, FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true));
    diseaseField.setCaption(I18nProperties.getCaption(Captions.devModeSampleDisease));
    sampleGeneratorConfigBinder.bind(diseaseField, SampleGenerationConfig::getDisease, SampleGenerationConfig::setDisease);
    diseaseField.setRequiredIndicatorVisible(true);
    sampleOptionsFirstLineLayout.addComponent(diseaseField);
    List<RegionReferenceDto> regions = FacadeProvider.getRegionFacade().getAllActiveByServerCountry();
    ComboBox<RegionReferenceDto> regionField = new ComboBox<>(null, regions);
    regionField.setCaption(I18nProperties.getCaption(Captions.devModeSampleRegion));
    sampleGeneratorConfigBinder.bind(regionField, SampleGenerationConfig::getRegion, SampleGenerationConfig::setRegion);
    sampleOptionsFirstLineLayout.addComponent(regionField);
    ComboBox<DistrictReferenceDto> districtField = new ComboBox<>();
    districtField.setCaption(I18nProperties.getCaption(Captions.devModeSampleDistrict));
    sampleGeneratorConfigBinder.bind(districtField, SampleGenerationConfig::getDistrict, SampleGenerationConfig::setDistrict);
    sampleOptionsFirstLineLayout.addComponent(districtField);
    regionField.addValueChangeListener(event -> {
        RegionReferenceDto region = event.getValue();
        if (region != null) {
            districtField.setItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
        } else {
            districtField.setItems(new ArrayList<DistrictReferenceDto>());
        }
    });
    Button generateButton = ButtonHelper.createButton(I18nProperties.getCaption(Captions.devModeGenerateSamples), e -> generateSamples(), CssStyles.FORCE_CAPTION);
    sampleOptionsFirstLineLayout.addComponent(generateButton);
    sampleGeneratorLayout.addComponent(sampleOptionsFirstLineLayout);
    HorizontalLayout sampleOptionsSecondLineLayout = new HorizontalLayout();
    ComboBox<SampleMaterial> sampleMaterial = new ComboBox(null, Arrays.asList(SampleMaterial.values()));
    sampleMaterial.setCaption(I18nProperties.getCaption(Captions.devModeSampleMaterial));
    sampleGeneratorConfigBinder.bind(sampleMaterial, SampleGenerationConfig::getSampleMaterial, SampleGenerationConfig::setSampleMaterial);
    sampleMaterial.setRequiredIndicatorVisible(true);
    sampleOptionsSecondLineLayout.addComponent(sampleMaterial);
    ComboBox<FacilityReferenceDto> laboratory = new ComboBox(null, FacadeProvider.getFacilityFacade().getAllActiveLaboratories(true));
    laboratory.setCaption(I18nProperties.getCaption(Captions.devModeSampleLaboratory));
    sampleGeneratorConfigBinder.bind(laboratory, SampleGenerationConfig::getLaboratory, SampleGenerationConfig::setLaboratory);
    laboratory.setRequiredIndicatorVisible(true);
    sampleOptionsSecondLineLayout.addComponent(laboratory);
    sampleGeneratorLayout.addComponent(sampleOptionsSecondLineLayout);
    HorizontalLayout sampleOptionsThirdLineLayout = new HorizontalLayout();
    CheckBox externalLabTesting = new CheckBox(I18nProperties.getCaption(Captions.devModeSampleExternalLabTesting));
    sampleGeneratorConfigBinder.bind(externalLabTesting, SampleGenerationConfig::isExternalLabOrInternalInHouseTesting, SampleGenerationConfig::setExternalLabOrInternalInHouseTesting);
    externalLabTesting.setValue(true);
    sampleOptionsThirdLineLayout.addComponent(externalLabTesting);
    CheckBox requestPathogenTestsToBePerformed = new CheckBox(I18nProperties.getCaption(Captions.devModeSamplePathogenTestsToBePerformed));
    sampleGeneratorConfigBinder.bind(requestPathogenTestsToBePerformed, SampleGenerationConfig::isRequestPathogenTestsToBePerformed, SampleGenerationConfig::setRequestPathogenTestsToBePerformed);
    sampleOptionsThirdLineLayout.addComponent(requestPathogenTestsToBePerformed);
    CheckBox requestAdditionalTestsToBePerformed = new CheckBox(I18nProperties.getCaption(Captions.devModeSampleAdditionalTestsToBePerformed));
    sampleGeneratorConfigBinder.bind(requestAdditionalTestsToBePerformed, SampleGenerationConfig::isRequestAdditionalTestsToBePerformed, SampleGenerationConfig::setRequestAdditionalTestsToBePerformed);
    sampleOptionsThirdLineLayout.addComponent(requestAdditionalTestsToBePerformed);
    CheckBox sendDispatch = new CheckBox(I18nProperties.getCaption(Captions.devModeSampleSendDispatch));
    sampleGeneratorConfigBinder.bind(sendDispatch, SampleGenerationConfig::isSendDispatch, SampleGenerationConfig::setSendDispatch);
    sampleOptionsThirdLineLayout.addComponent(sendDispatch);
    CheckBox received = new CheckBox(I18nProperties.getCaption(Captions.devModeSampleReceived));
    sampleGeneratorConfigBinder.bind(received, SampleGenerationConfig::isReceived, SampleGenerationConfig::setReceived);
    sampleOptionsThirdLineLayout.addComponent(received);
    externalLabTesting.addValueChangeListener(event -> {
        if (externalLabTesting.getValue()) {
            requestPathogenTestsToBePerformed.setVisible(true);
            sendDispatch.setVisible(true);
            received.setVisible(true);
            laboratory.setVisible(true);
            sampleGenerationConfig.setSamplePurpose(SamplePurpose.EXTERNAL);
        } else {
            requestPathogenTestsToBePerformed.setVisible(false);
            sendDispatch.setVisible(false);
            received.setVisible(false);
            laboratory.setVisible(false);
            sampleGenerationConfig.setSamplePurpose(SamplePurpose.INTERNAL);
        }
    });
    sampleGeneratorLayout.addComponent(sampleOptionsThirdLineLayout);
    sampleGenerationConfig.setRegion(regions.get(0));
    sampleGenerationConfig.setDistrict(FacadeProvider.getDistrictFacade().getAllActiveByRegion(sampleGenerationConfig.getRegion().getUuid()).get(0));
    sampleGeneratorConfigBinder.setBean(sampleGenerationConfig);
    return sampleGeneratorLayout;
}
Also used : Disease(de.symeda.sormas.api.Disease) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ComboBox(com.vaadin.ui.ComboBox) Label(com.vaadin.ui.Label) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) StringToIntegerConverter(com.vaadin.data.converter.StringToIntegerConverter) DateField(com.vaadin.ui.DateField)

Example 3 with SampleMaterial

use of de.symeda.sormas.api.sample.SampleMaterial in project SORMAS-Project by hzi-braunschweig.

the class TestEntityCreator method createSample.

public static Sample createSample(Case caze) {
    if (caze == null) {
        caze = createCase();
    }
    Date sampleDateTime = DateHelper.subtractDays(new Date(), 1);
    Facility lab = DatabaseHelper.getFacilityDao().queryForAll().get(0);
    SampleMaterial material = SampleMaterial.BLOOD;
    Sample sample = DatabaseHelper.getSampleDao().build(caze);
    sample.setSampleDateTime(sampleDateTime);
    sample.setLab(lab);
    sample.setSampleMaterial(material);
    try {
        DatabaseHelper.getSampleDao().saveAndSnapshot(sample);
        DatabaseHelper.getSampleDao().accept(sample);
    } catch (DaoException e) {
        throw new RuntimeException(e);
    }
    return DatabaseHelper.getSampleDao().queryForIdWithEmbedded(sample.getId());
}
Also used : Sample(de.symeda.sormas.app.backend.sample.Sample) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) Facility(de.symeda.sormas.app.backend.facility.Facility) DaoException(de.symeda.sormas.app.backend.common.DaoException) Date(java.util.Date)

Aggregations

SampleMaterial (de.symeda.sormas.api.sample.SampleMaterial)3 Date (java.util.Date)2 StringToIntegerConverter (com.vaadin.data.converter.StringToIntegerConverter)1 Button (com.vaadin.ui.Button)1 CheckBox (com.vaadin.ui.CheckBox)1 ComboBox (com.vaadin.ui.ComboBox)1 DateField (com.vaadin.ui.DateField)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 TextField (com.vaadin.ui.TextField)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Disease (de.symeda.sormas.api.Disease)1 DiseaseHelper (de.symeda.sormas.api.DiseaseHelper)1 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 Page (de.symeda.sormas.api.common.Page)1 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)1 EventParticipantReferenceDto (de.symeda.sormas.api.event.EventParticipantReferenceDto)1 Captions (de.symeda.sormas.api.i18n.Captions)1 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)1