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());
}
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;
}
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());
}
Aggregations