use of de.symeda.sormas.api.sample.SampleExportDto in project SORMAS-Project by hzi-braunschweig.
the class SampleFacadeEjb method getExportList.
private List<SampleExportDto> getExportList(SampleCriteria sampleCriteria, CaseCriteria caseCriteria, Collection<String> selectedRows, int first, int max) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SampleExportDto> cq = cb.createQuery(SampleExportDto.class);
Root<Sample> sampleRoot = cq.from(Sample.class);
SampleQueryContext sampleQueryContext = new SampleQueryContext(cb, cq, sampleRoot);
SampleJoins joins = sampleQueryContext.getJoins();
cq.distinct(true);
List<Selection<?>> selections = new ArrayList<>();
Selection<?>[] tmp = new Selection<?>[] { sampleRoot.get(AbstractDomainObject.ID), sampleRoot.get(AbstractDomainObject.UUID), sampleRoot.get(Sample.LAB_SAMPLE_ID), sampleRoot.get(Sample.REPORT_DATE_TIME), joins.getCaze().get(Case.EPID_NUMBER), joins.getCasePerson().get(Person.FIRST_NAME), joins.getCasePerson().get(Person.LAST_NAME), joins.getContactPerson().get(Person.FIRST_NAME), joins.getContactPerson().get(Person.LAST_NAME), joins.getEventParticipantPerson().get(Person.FIRST_NAME), joins.getEventParticipantPerson().get(Person.LAST_NAME), joins.getCaze().get(Case.DISEASE), joins.getCaze().get(Case.DISEASE_DETAILS), joins.getContact().get(Contact.DISEASE), joins.getContact().get(Contact.DISEASE_DETAILS), joins.getEvent().get(Event.DISEASE), joins.getEvent().get(Event.DISEASE_DETAILS), sampleRoot.get(Sample.SAMPLE_DATE_TIME), sampleRoot.get(Sample.SAMPLE_MATERIAL), sampleRoot.get(Sample.SAMPLE_MATERIAL_TEXT), sampleRoot.get(Sample.SAMPLE_PURPOSE), sampleRoot.get(Sample.SAMPLING_REASON), sampleRoot.get(Sample.SAMPLING_REASON_DETAILS), sampleRoot.get(Sample.SAMPLE_SOURCE), joins.getLab().get(Facility.NAME), sampleRoot.get(Sample.LAB_DETAILS), sampleRoot.get(Sample.PATHOGEN_TEST_RESULT), sampleRoot.get(Sample.PATHOGEN_TESTING_REQUESTED), sampleRoot.get(Sample.REQUESTED_PATHOGEN_TESTS_STRING), sampleRoot.get(Sample.REQUESTED_OTHER_PATHOGEN_TESTS), sampleRoot.get(Sample.ADDITIONAL_TESTING_REQUESTED), sampleRoot.get(Sample.REQUESTED_ADDITIONAL_TESTS_STRING), sampleRoot.get(Sample.REQUESTED_OTHER_ADDITIONAL_TESTS), sampleRoot.get(Sample.SHIPPED), sampleRoot.get(Sample.SHIPMENT_DATE), sampleRoot.get(Sample.SHIPMENT_DETAILS), sampleRoot.get(Sample.RECEIVED), sampleRoot.get(Sample.RECEIVED_DATE), sampleRoot.get(Sample.SPECIMEN_CONDITION), sampleRoot.get(Sample.NO_TEST_POSSIBLE_REASON), sampleRoot.get(Sample.COMMENT), joins.getReferredSample().get(AbstractDomainObject.UUID), joins.getCaze().get(AbstractDomainObject.UUID), joins.getContact().get(AbstractDomainObject.UUID), joins.getEventParticipant().get(AbstractDomainObject.UUID), joins.getCasePerson().get(Person.APPROXIMATE_AGE), joins.getCasePerson().get(Person.APPROXIMATE_AGE_TYPE), joins.getCasePerson().get(Person.SEX), joins.getContactPerson().get(Person.APPROXIMATE_AGE), joins.getContactPerson().get(Person.APPROXIMATE_AGE_TYPE), joins.getContactPerson().get(Person.SEX), joins.getEventParticipantPerson().get(Person.APPROXIMATE_AGE), joins.getEventParticipantPerson().get(Person.APPROXIMATE_AGE_TYPE), joins.getEventParticipantPerson().get(Person.SEX), joins.getCasePersonAddressRegion().get(Region.NAME), joins.getCasePersonAddressDistrict().get(District.NAME), joins.getCasePersonAddressCommunity().get(Community.NAME), joins.getCasePersonAddress().get(Location.CITY), joins.getCasePersonAddress().get(Location.STREET), joins.getCasePersonAddress().get(Location.HOUSE_NUMBER), joins.getCasePersonAddress().get(Location.ADDITIONAL_INFORMATION), joins.getContactPersonAddressRegion().get(Region.NAME), joins.getContactPersonAddressDistrict().get(District.NAME), joins.getContactPersonAddressCommunity().get(Community.NAME), joins.getContactPersonAddress().get(Location.CITY), joins.getContactPersonAddress().get(Location.STREET), joins.getContactPersonAddress().get(Location.HOUSE_NUMBER), joins.getContactPersonAddress().get(Location.ADDITIONAL_INFORMATION), joins.getEventRegion().get(Region.NAME), joins.getEventDistrict().get(District.NAME), joins.getEventCommunity().get(Community.NAME), joins.getEventLocation().get(Location.CITY), joins.getEventLocation().get(Location.STREET), joins.getEventLocation().get(Location.HOUSE_NUMBER), joins.getEventLocation().get(Location.ADDITIONAL_INFORMATION), joins.getCaze().get(Case.REPORT_DATE), joins.getCaze().get(Case.CASE_CLASSIFICATION), joins.getCaze().get(Case.OUTCOME), joins.getCaseRegion().get(Region.NAME), joins.getCaseDistrict().get(District.NAME), joins.getCaseCommunity().get(Community.NAME), joins.getCaseFacility().get(Facility.NAME), joins.getCaze().get(Case.HEALTH_FACILITY_DETAILS), joins.getContactRegion().get(Region.NAME), joins.getContactDistrict().get(District.NAME), joins.getContactCommunity().get(Community.NAME), joins.getContact().get(Contact.REPORT_DATE_TIME), joins.getContact().get(Contact.LAST_CONTACT_DATE), joins.getContact().get(Contact.CONTACT_CLASSIFICATION), joins.getContact().get(Contact.CONTACT_STATUS), joins.getLab().get(AbstractDomainObject.UUID), joins.getCaseFacility().get(AbstractDomainObject.UUID) };
Collections.addAll(selections, tmp);
selections.addAll(sampleService.getJurisdictionSelections(sampleQueryContext));
cq.multiselect(selections);
Predicate filter = sampleService.createUserFilter(sampleQueryContext, sampleCriteria);
if (sampleCriteria != null) {
Predicate criteriaFilter = sampleService.buildCriteriaFilter(sampleCriteria, sampleQueryContext);
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, sampleRoot.get(AbstractDomainObject.UUID));
} else if (caseCriteria != null) {
Predicate criteriaFilter = caseService.createCriteriaFilter(caseCriteria, new CaseQueryContext(cb, cq, joins.getCaseJoins()));
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
filter = CriteriaBuilderHelper.and(cb, filter, cb.isFalse(sampleRoot.get(CoreAdo.DELETED)));
filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, joins.getCaze().get(AbstractDomainObject.UUID));
}
if (filter != null) {
cq.where(filter);
}
cq.orderBy(cb.desc(sampleRoot.get(Sample.REPORT_DATE_TIME)), cb.desc(sampleRoot.get(AbstractDomainObject.ID)));
List<SampleExportDto> resultList = QueryHelper.getResultList(em, cq, first, max);
for (SampleExportDto exportDto : resultList) {
Sample sampleFromExportDto = sampleService.getById(exportDto.getId());
List<PathogenTest> pathogenTests = sampleFromExportDto.getPathogenTests();
int count = 0;
for (PathogenTest pathogenTest : pathogenTests) {
String lab = pathogenTest.getLab() != null ? FacilityHelper.buildFacilityString(pathogenTest.getLab().getUuid(), pathogenTest.getLab().getName(), pathogenTest.getLabDetails()) : null;
SampleExportDto.SampleExportPathogenTest sampleExportPathogenTest = new SampleExportDto.SampleExportPathogenTest(pathogenTest.getTestType(), pathogenTest.getTestTypeText(), DiseaseHelper.toString(pathogenTest.getTestedDisease(), pathogenTest.getTestedDiseaseDetails()), pathogenTest.getTestDateTime(), lab, pathogenTest.getTestResult(), pathogenTest.getTestResultVerified());
switch(++count) {
case 1:
exportDto.setPathogenTest1(sampleExportPathogenTest);
break;
case 2:
exportDto.setPathogenTest2(sampleExportPathogenTest);
break;
case 3:
exportDto.setPathogenTest3(sampleExportPathogenTest);
break;
default:
exportDto.addOtherPathogenTest(sampleExportPathogenTest);
break;
}
}
if (exportDto.getAdditionalTestingRequested()) {
List<AdditionalTest> additionalTests = additionalTestService.getAllBySample(sampleFromExportDto);
if (!additionalTests.isEmpty()) {
exportDto.setAdditionalTest(AdditionalTestFacadeEjb.toDto(additionalTests.get(0)));
}
if (additionalTests.size() > 1) {
exportDto.setOtherAdditionalTestsDetails(I18nProperties.getString(Strings.yes));
} else {
exportDto.setOtherAdditionalTestsDetails(I18nProperties.getString(Strings.no));
}
} else {
exportDto.setOtherAdditionalTestsDetails(I18nProperties.getString(Strings.no));
}
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
boolean isInJurisdiction = exportDto.getSampleJurisdictionFlagsDto().getInJurisdiction();
pseudonymizer.pseudonymizeDto(SampleExportDto.class, exportDto, isInJurisdiction, s -> pseudonymizer.pseudonymizeDtoCollection(SampleExportDto.SampleExportPathogenTest.class, exportDto.getOtherPathogenTests(), t -> isInJurisdiction, null));
}
return resultList;
}
use of de.symeda.sormas.api.sample.SampleExportDto in project SORMAS-Project by hzi-braunschweig.
the class SampleFacadeEjbPseudonymizationTest method testPseudonymizeExportList.
@Test
public void testPseudonymizeExportList() {
CaseDataDto caze1 = creator.createCase(user2.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf2);
SampleDto sample1 = createCaseSample(caze1, user2);
createPathogenTest(sample1, user2);
CaseDataDto caze2 = creator.createCase(user1.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf1);
ContactDto contact1 = creator.createContact(user2.toReference(), null, creator.createPerson("John", "Smith").toReference(), caze2, new Date(), new Date(), Disease.CORONAVIRUS, rdcf2);
SampleDto sample2 = createCaseSample(caze2, user1);
createPathogenTest(sample2, user1);
createPathogenTest(sample2, user1);
createPathogenTest(sample2, user1);
createPathogenTest(sample2, user1);
SampleDto sample3 = createContactSample(contact1);
ContactDto contact2 = creator.createContact(user1.toReference(), null, creator.createPerson("John", "Smith").toReference(), caze2, new Date(), new Date(), Disease.CORONAVIRUS, rdcf1);
SampleDto sample4 = createContactSample(contact2);
List<SampleExportDto> exportList = getSampleFacade().getExportList(new SampleCriteria(), Collections.emptySet(), 0, 100);
SampleExportDto export1 = exportList.stream().filter(t -> t.getUuid().equals(sample1.getUuid())).findFirst().get();
assertThat(export1.getSampleAssociatedCase().getFirstName(), is("John"));
assertThat(export1.getSampleAssociatedCase().getLastName(), is("Smith"));
assertThat(export1.getLab(), is("Lab - Test lab details"));
assertThat(export1.getPathogenTestLab1(), is("Lab - Test lab details"));
assertThat(export1.getPathogenTestType1(), is("Test type text"));
SampleExportDto export2 = exportList.stream().filter(t -> t.getUuid().equals(sample2.getUuid())).findFirst().get();
assertThat(export2.getSampleAssociatedCase().getFirstName(), is("Confidential"));
assertThat(export2.getSampleAssociatedCase().getLastName(), is("Confidential"));
assertThat(export2.getLab(), is("Lab - Test lab details"));
assertThat(export2.getPathogenTestLab1(), is("Lab - Test lab details"));
assertThat(export2.getPathogenTestType1(), is("Confidential"));
assertThat(export2.getPathogenTestLab2(), is("Lab - Test lab details"));
assertThat(export2.getPathogenTestType2(), is("Confidential"));
assertThat(export2.getPathogenTestLab3(), is("Lab - Test lab details"));
assertThat(export2.getPathogenTestType3(), is("Confidential"));
assertThat(export2.getOtherPathogenTestsDetails(), is("2020-06-10 (Confidential, COVID-19, Pending)"));
SampleExportDto export3 = exportList.stream().filter(t -> t.getUuid().equals(sample3.getUuid())).findFirst().get();
assertThat(export3.getAssociatedContact().getContactName().getFirstName(), is("John"));
assertThat(export3.getAssociatedContact().getContactName().getLastName(), is("Smith"));
assertThat(export3.getLab(), is("Lab"));
SampleExportDto export4 = exportList.stream().filter(t -> t.getUuid().equals(sample4.getUuid())).findFirst().get();
assertThat(export4.getAssociatedContact().getContactName().getFirstName(), is("Confidential"));
assertThat(export4.getAssociatedContact().getContactName().getLastName(), is("Confidential"));
assertThat(export4.getLab(), is("Lab"));
}
Aggregations