use of de.symeda.sormas.api.sample.PathogenTestType in project SORMAS-Project by hzi-braunschweig.
the class TestEntityCreator method createSampleTest.
public static PathogenTest createSampleTest(Sample sample) {
PathogenTestType pathogenTestType = PathogenTestType.RAPID_TEST;
PathogenTestResultType pathogenTestResultType = PathogenTestResultType.NEGATIVE;
Date sampleTestDateTime = new Date();
PathogenTest pathogenTest = DatabaseHelper.getSampleTestDao().build(sample);
pathogenTest.setTestType(pathogenTestType);
pathogenTest.setTestResult(pathogenTestResultType);
pathogenTest.setTestDateTime(sampleTestDateTime);
try {
DatabaseHelper.getSampleTestDao().saveAndSnapshot(pathogenTest);
DatabaseHelper.getSampleTestDao().accept(pathogenTest);
} catch (DaoException e) {
throw new RuntimeException(e);
}
return DatabaseHelper.getSampleTestDao().queryForIdWithEmbedded(pathogenTest.getId());
}
use of de.symeda.sormas.api.sample.PathogenTestType in project SORMAS-Project by hzi-braunschweig.
the class SampleEditFragment method prepareFragmentData.
@Override
protected void prepareFragmentData() {
record = getActivityRootData();
if (record.getId() != null) {
mostRecentTest = DatabaseHelper.getSampleTestDao().queryMostRecentBySample(record);
if (ConfigProvider.hasUserRight(UserRight.ADDITIONAL_TEST_VIEW) && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.ADDITIONAL_TESTS)) {
mostRecentAdditionalTests = DatabaseHelper.getAdditionalTestDao().queryMostRecentBySample(record);
}
}
if (!StringUtils.isEmpty(record.getReferredToUuid())) {
referredSample = DatabaseHelper.getSampleDao().queryUuid(record.getReferredToUuid());
} else {
referredSample = null;
}
sampleMaterialList = DataUtils.getEnumItems(SampleMaterial.class, true, getFieldVisibilityCheckers());
sampleSourceList = DataUtils.getEnumItems(SampleSource.class, true);
labList = DatabaseHelper.getFacilityDao().getActiveLaboratories(true);
samplePurposeList = DataUtils.getEnumItems(SamplePurpose.class, true);
samplingReasonList = DataUtils.getEnumItems(SamplingReason.class, true, getFieldVisibilityCheckers());
for (PathogenTestType pathogenTest : record.getRequestedPathogenTests()) {
requestedPathogenTests.clear();
if (pathogenTest != PathogenTestType.OTHER) {
requestedPathogenTests.add(pathogenTest.toString());
}
}
if (ConfigProvider.hasUserRight(UserRight.ADDITIONAL_TEST_VIEW) && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.ADDITIONAL_TESTS)) {
requestedAdditionalTests.clear();
for (AdditionalTestType additionalTest : record.getRequestedAdditionalTests()) {
requestedAdditionalTests.add(additionalTest.toString());
}
}
if (record.getId() != null) {
if (DatabaseHelper.getSampleTestDao().queryBySample(record).stream().allMatch(pathogenTest -> pathogenTest.getTestResult() == PathogenTestResultType.PENDING)) {
finalTestResults = DataUtils.toItems(Arrays.asList(PathogenTestResultType.values()));
} else {
finalTestResults = DataUtils.toItems(Arrays.stream(PathogenTestResultType.values()).filter(type -> type != PathogenTestResultType.NOT_DONE).collect(Collectors.toList()));
}
}
}
use of de.symeda.sormas.api.sample.PathogenTestType in project SORMAS-Project by hzi-braunschweig.
the class SampleReadFragment method prepareFragmentData.
// Overrides
@Override
protected void prepareFragmentData(Bundle savedInstanceState) {
record = getActivityRootData();
mostRecentTest = DatabaseHelper.getSampleTestDao().queryMostRecentBySample(record);
if (ConfigProvider.hasUserRight(UserRight.ADDITIONAL_TEST_VIEW) && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.ADDITIONAL_TESTS)) {
mostRecentAdditionalTests = DatabaseHelper.getAdditionalTestDao().queryMostRecentBySample(record);
}
if (!StringUtils.isEmpty(record.getReferredToUuid())) {
referredSample = DatabaseHelper.getSampleDao().queryUuid(record.getReferredToUuid());
} else {
referredSample = null;
}
for (PathogenTestType pathogenTest : record.getRequestedPathogenTests()) {
if (pathogenTest != PathogenTestType.OTHER) {
requestedPathogenTests.add(pathogenTest.toString());
}
}
if (ConfigProvider.hasUserRight(UserRight.ADDITIONAL_TEST_VIEW) && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.ADDITIONAL_TESTS)) {
for (AdditionalTestType additionalTest : record.getRequestedAdditionalTests()) {
requestedAdditionalTests.add(additionalTest.toString());
}
}
}
use of de.symeda.sormas.api.sample.PathogenTestType in project SORMAS-Project by hzi-braunschweig.
the class PathogenTestEditFragment method onAfterLayoutBinding.
@Override
public void onAfterLayoutBinding(FragmentPathogenTestEditLayoutBinding contentBinding) {
setFieldVisibilitiesAndAccesses(PathogenTestDto.class, contentBinding.mainContent);
// Initialize ControlSpinnerFields
contentBinding.pathogenTestTestType.initializeSpinner(testTypeList, new ValueChangeListener() {
@Override
public void onChange(ControlPropertyField field) {
PathogenTestType currentTestType = (PathogenTestType) field.getValue();
if ((PathogenTestType.PCR_RT_PCR == currentTestType && PathogenTestResultType.POSITIVE == contentBinding.pathogenTestTestResult.getValue()) || PathogenTestType.CQ_VALUE_DETECTION == currentTestType) {
contentBinding.pathogenTestCqValue.setVisibility(View.VISIBLE);
} else {
contentBinding.pathogenTestCqValue.hideField(true);
}
if (PathogenTestType.PCR_RT_PCR == currentTestType && Disease.CORONAVIRUS == record.getTestedDisease()) {
getContentBinding().pathogenTestPcrTestSpecification.setVisibility(View.VISIBLE);
} else {
getContentBinding().pathogenTestPcrTestSpecification.hideField(false);
}
}
});
contentBinding.pathogenTestPcrTestSpecification.initializeSpinner(pcrTestSpecificationList);
contentBinding.pathogenTestTestedDiseaseVariant.initializeSpinner(diseaseVariantList);
contentBinding.pathogenTestTestedDisease.initializeSpinner(diseaseList, new ValueChangeListener() {
final Disease currentDisease = record.getTestedDisease();
@Override
public void onChange(ControlPropertyField field) {
if (PathogenTestType.PCR_RT_PCR == record.getTestType() && Disease.CORONAVIRUS == field.getValue()) {
getContentBinding().pathogenTestPcrTestSpecification.setVisibility(View.VISIBLE);
} else {
getContentBinding().pathogenTestPcrTestSpecification.hideField(false);
}
if (this.currentDisease == null || contentBinding.pathogenTestTestedDisease.getValue() != currentDisease) {
updateDiseaseVariantsField(contentBinding);
}
testTypeList = DataUtils.toItems(Arrays.asList(PathogenTestType.values()), true, FieldVisibilityCheckers.withDisease((Disease) field.getValue()), PathogenTestType.class);
contentBinding.pathogenTestTestType.setSpinnerData(testTypeList);
}
});
contentBinding.pathogenTestTestResult.initializeSpinner(testResultList, new ValueChangeListener() {
@Override
public void onChange(ControlPropertyField field) {
PathogenTestResultType currentPathogenTestResult = (PathogenTestResultType) field.getValue();
if ((PathogenTestType.PCR_RT_PCR == contentBinding.pathogenTestTestType.getValue() && PathogenTestResultType.POSITIVE == currentPathogenTestResult) || PathogenTestType.CQ_VALUE_DETECTION == contentBinding.pathogenTestTestType.getValue()) {
contentBinding.pathogenTestCqValue.setVisibility(View.VISIBLE);
} else {
contentBinding.pathogenTestCqValue.hideField(true);
}
}
});
contentBinding.pathogenTestLab.initializeSpinner(DataUtils.toItems(labList), new ValueChangeListener() {
@Override
public void onChange(ControlPropertyField field) {
Facility laboratory = (Facility) field.getValue();
if (laboratory != null && laboratory.getUuid().equals(FacilityDto.OTHER_FACILITY_UUID)) {
contentBinding.pathogenTestLabDetails.setVisibility(View.VISIBLE);
} else {
contentBinding.pathogenTestLabDetails.hideField(true);
}
}
});
// // Initialize ControlDateFields
contentBinding.pathogenTestReportDate.initializeDateField(getFragmentManager());
contentBinding.pathogenTestTestDateTime.initializeDateTimeField(getFragmentManager());
if (sample.getSamplePurpose() == SamplePurpose.INTERNAL) {
contentBinding.pathogenTestLab.setRequired(false);
}
}
use of de.symeda.sormas.api.sample.PathogenTestType in project SORMAS-Project by hzi-braunschweig.
the class SampleService method getIndexList.
public List<SampleIndexDto> getIndexList(SampleCriteria sampleCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery<SampleIndexDto> cq = cb.createQuery(SampleIndexDto.class);
final Root<Sample> sample = cq.from(Sample.class);
SampleQueryContext sampleQueryContext = new SampleQueryContext(cb, cq, sample);
SampleJoins<Sample> joins = (SampleJoins<Sample>) sampleQueryContext.getJoins();
final Join<Sample, Case> caze = joins.getCaze();
final Join<Case, District> caseDistrict = joins.getCaseDistrict();
final Join<Sample, Contact> contact = joins.getContact();
final Join<Contact, District> contactDistrict = joins.getContactDistrict();
final Join<Case, District> contactCaseDistrict = joins.getContactCaseDistrict();
final Join<EventParticipant, Event> event = joins.getEvent();
final Join<Location, District> eventDistrict = joins.getEventDistrict();
Expression<Object> diseaseSelect = cb.selectCase().when(cb.isNotNull(caze), caze.get(Case.DISEASE)).otherwise(cb.selectCase().when(cb.isNotNull(contact), contact.get(Contact.DISEASE)).otherwise(event.get(Event.DISEASE)));
Expression<Object> diseaseDetailsSelect = cb.selectCase().when(cb.isNotNull(caze), caze.get(Case.DISEASE_DETAILS)).otherwise(cb.selectCase().when(cb.isNotNull(contact), contact.get(Contact.DISEASE_DETAILS)).otherwise(event.get(Event.DISEASE_DETAILS)));
Expression<Object> districtSelect = cb.selectCase().when(cb.isNotNull(caseDistrict), caseDistrict.get(District.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(contactDistrict), contactDistrict.get(District.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(contactCaseDistrict), contactCaseDistrict.get(District.NAME)).otherwise(eventDistrict.get(District.NAME))));
cq.distinct(true);
List<Selection<?>> selections = new ArrayList<>(Arrays.asList(sample.get(Sample.UUID), caze.get(Case.EPID_NUMBER), sample.get(Sample.LAB_SAMPLE_ID), sample.get(Sample.SAMPLE_DATE_TIME), sample.get(Sample.SHIPPED), sample.get(Sample.SHIPMENT_DATE), sample.get(Sample.RECEIVED), sample.get(Sample.RECEIVED_DATE), sample.get(Sample.SAMPLE_MATERIAL), sample.get(Sample.SAMPLE_PURPOSE), sample.get(Sample.SPECIMEN_CONDITION), joins.getLab().get(Facility.NAME), joins.getReferredSample().get(Sample.UUID), sample.get(Sample.SAMPLING_REASON), sample.get(Sample.SAMPLING_REASON_DETAILS), caze.get(Case.UUID), joins.getCasePerson().get(Person.FIRST_NAME), joins.getCasePerson().get(Person.LAST_NAME), joins.getContact().get(Contact.UUID), joins.getContactPerson().get(Person.FIRST_NAME), joins.getContactPerson().get(Person.LAST_NAME), joins.getEventParticipant().get(EventParticipant.UUID), joins.getEventParticipantPerson().get(Person.FIRST_NAME), joins.getEventParticipantPerson().get(Person.LAST_NAME), diseaseSelect, diseaseDetailsSelect, sample.get(Sample.PATHOGEN_TEST_RESULT), sample.get(Sample.ADDITIONAL_TESTING_REQUESTED), cb.isNotEmpty(sample.get(Sample.ADDITIONAL_TESTS)), districtSelect, joins.getLab().get(Facility.UUID)));
// Tests count subquery
Subquery<Long> testCountSq = cq.subquery(Long.class);
Root<PathogenTest> testCountRoot = testCountSq.from(PathogenTest.class);
testCountSq.where(cb.equal(testCountRoot.get(PathogenTest.SAMPLE), sample), cb.isFalse(testCountRoot.get(PathogenTest.DELETED)));
testCountSq.select(cb.countDistinct(testCountRoot.get(PathogenTest.ID)));
selections.add(testCountSq.getSelection());
selections.addAll(getJurisdictionSelections(sampleQueryContext));
cq.multiselect(selections);
Predicate filter = createUserFilter(cq, cb, joins, sampleCriteria);
if (sampleCriteria != null) {
Predicate criteriaFilter = buildCriteriaFilter(sampleCriteria, cb, joins);
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
}
if (filter != null) {
cq.where(filter);
}
if (sortProperties != null && sortProperties.size() > 0) {
List<Order> order = new ArrayList<>(sortProperties.size());
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case SampleIndexDto.UUID:
case SampleIndexDto.LAB_SAMPLE_ID:
case SampleIndexDto.SHIPPED:
case SampleIndexDto.RECEIVED:
case SampleIndexDto.REFERRED:
case SampleIndexDto.SAMPLE_DATE_TIME:
case SampleIndexDto.SHIPMENT_DATE:
case SampleIndexDto.RECEIVED_DATE:
case SampleIndexDto.SAMPLE_MATERIAL:
case SampleIndexDto.SAMPLE_PURPOSE:
case SampleIndexDto.PATHOGEN_TEST_RESULT:
case SampleIndexDto.ADDITIONAL_TESTING_STATUS:
expression = sample.get(sortProperty.propertyName);
break;
case SampleIndexDto.DISEASE:
expression = diseaseSelect;
break;
case SampleIndexDto.EPID_NUMBER:
expression = caze.get(Case.EPID_NUMBER);
break;
case SampleIndexDto.ASSOCIATED_CASE:
expression = joins.getCasePerson().get(Person.LAST_NAME);
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
expression = joins.getCasePerson().get(Person.FIRST_NAME);
break;
case SampleIndexDto.ASSOCIATED_CONTACT:
expression = joins.getContactPerson().get(Person.LAST_NAME);
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
expression = joins.getContactPerson().get(Person.FIRST_NAME);
break;
case SampleIndexDto.ASSOCIATED_EVENT_PARTICIPANT:
expression = joins.getEventParticipantPerson().get(Person.LAST_NAME);
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
expression = joins.getEventParticipantPerson().get(Person.FIRST_NAME);
break;
case SampleIndexDto.DISTRICT:
expression = districtSelect;
break;
case SampleIndexDto.LAB:
expression = joins.getLab().get(Facility.NAME);
break;
default:
throw new IllegalArgumentException(sortProperty.propertyName);
}
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
}
cq.orderBy(order);
} else {
cq.orderBy(cb.desc(sample.get(Sample.SAMPLE_DATE_TIME)));
}
List<SampleIndexDto> samples = QueryHelper.getResultList(em, cq, first, max);
if (!samples.isEmpty()) {
CriteriaQuery<Object[]> testCq = cb.createQuery(Object[].class);
Root<PathogenTest> testRoot = testCq.from(PathogenTest.class);
Expression<String> sampleIdExpr = testRoot.get(PathogenTest.SAMPLE).get(Sample.UUID);
Path<Long> testType = testRoot.get(PathogenTest.TEST_TYPE);
Path<Date> cqValue = testRoot.get(PathogenTest.CQ_VALUE);
testCq.select(cb.array(testType, cqValue, sampleIdExpr));
testCq.where(cb.isFalse(testRoot.get(PathogenTest.DELETED)), sampleIdExpr.in(samples.stream().map(SampleIndexDto::getUuid).collect(Collectors.toList())));
testCq.orderBy(cb.desc(testRoot.get(PathogenTest.CHANGE_DATE)));
List<Object[]> testList = em.createQuery(testCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
Map<String, Object[]> tests = testList.stream().filter(distinctByKey(pathogenTest -> pathogenTest[2])).collect(Collectors.toMap(pathogenTest -> pathogenTest[2].toString(), Function.identity()));
for (SampleIndexDto indexDto : samples) {
Optional.ofNullable(tests.get(indexDto.getUuid())).ifPresent(test -> {
indexDto.setTypeOfLastTest((PathogenTestType) test[0]);
indexDto.setLastTestCqValue((Float) test[1]);
});
}
}
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
Pseudonymizer emptyValuePseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
pseudonymizer.pseudonymizeDtoCollection(SampleIndexDto.class, samples, s -> s.getSampleJurisdictionFlagsDto().getInJurisdiction(), (s, ignored) -> {
final SampleJurisdictionFlagsDto sampleJurisdictionFlagsDto = s.getSampleJurisdictionFlagsDto();
if (s.getAssociatedCase() != null) {
emptyValuePseudonymizer.pseudonymizeDto(CaseReferenceDto.class, s.getAssociatedCase(), sampleJurisdictionFlagsDto.getCaseInJurisdiction(), null);
}
ContactReferenceDto associatedContact = s.getAssociatedContact();
if (associatedContact != null) {
emptyValuePseudonymizer.pseudonymizeDto(ContactReferenceDto.PersonName.class, associatedContact.getContactName(), sampleJurisdictionFlagsDto.getContactInJurisdiction(), null);
if (associatedContact.getCaseName() != null) {
pseudonymizer.pseudonymizeDto(ContactReferenceDto.PersonName.class, associatedContact.getCaseName(), sampleJurisdictionFlagsDto.getContactCaseInJurisdiction(), null);
}
}
if (s.getAssociatedEventParticipant() != null) {
emptyValuePseudonymizer.pseudonymizeDto(EventParticipantReferenceDto.class, s.getAssociatedEventParticipant(), sampleJurisdictionFlagsDto.getEvenParticipantInJurisdiction(), null);
}
}, true);
return samples;
}
Aggregations