use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testGetReShares.
@Test
public void testGetReShares() throws SormasToSormasException {
useSurveillanceOfficerLogin(rdcf);
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
CaseDataDto caze = creator.createCase(officer, creator.createPerson().toReference(), rdcf);
User officerUser = getUserService().getByReferenceDto(officer);
ShareRequestInfo shareRequestInfo = createShareRequestInfo(officerUser, SECOND_SERVER_ID, true, ShareRequestStatus.ACCEPTED, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference())));
getShareRequestInfoService().persist(shareRequestInfo);
Mockito.when(MockProducer.getSormasToSormasClient().post(eq(SECOND_SERVER_ID), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> {
SormasToSormasShareInfoDto shareInfo = new SormasToSormasShareInfoDto();
shareInfo.setTargetDescriptor(new SormasServerDescriptor("dummy SORMAS"));
shareInfo.setOwnershipHandedOver(false);
shareInfo.setComment("re-shared");
return encryptShareDataAsArray(new SormasToSormasShareTree(null, shareInfo, Collections.emptyList(), false));
});
Mockito.when(MockProducer.getSormasToSormasClient().post(eq("dummy SORMAS"), eq("/sormasToSormas/cases/shares"), ArgumentMatchers.any(), ArgumentMatchers.any())).thenAnswer(invocation -> encryptShareData(Collections.emptyList()));
mockS2Snetwork();
SormasToSormasEncryptedDataDto encryptedCriteria = encryptShareData(new ShareTreeCriteria(caze.getUuid(), null, false));
SormasToSormasEncryptedDataDto encryptedShares = getSormasToSormasCaseFacade().getShareTrees(encryptedCriteria);
mockDefaultServerAccess();
SormasToSormasShareTree[] shares = getSormasToSormasEncryptionFacade().decryptAndVerify(new SormasToSormasEncryptedDataDto(SECOND_SERVER_ID, encryptedShares.getData()), SormasToSormasShareTree[].class);
assertThat(shares, arrayWithSize(1));
assertThat(shares[0].getShare().getTargetDescriptor().getId(), is(SECOND_SERVER_ID));
assertThat(shares[0].getShare().isOwnershipHandedOver(), is(true));
assertThat(shares[0].getReShares().get(0).getShare().getTargetDescriptor().getId(), is("dummy SORMAS"));
assertThat(shares[0].getReShares().get(0).getShare().isOwnershipHandedOver(), is(false));
assertThat(shares[0].getReShares().get(0).getReShares(), hasSize(0));
}
use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class DtoHelperTest method testFillDto.
@Test
public void testFillDto() {
RDCFEntities rdcf = creator.createRDCFEntities();
RDCFEntities rdcf2 = creator.createRDCFEntities();
rdcf2.facility.setType(FacilityType.LABORATORY);
UserDto user = creator.createUser(rdcf, UserRole.ADMIN);
// Test simple values
{
HealthConditionsDto targetDto = new HealthConditionsDto();
HealthConditionsDto sourceDto = new HealthConditionsDto();
// lead and other have different values
targetDto.setTuberculosis(YesNoUnknown.YES);
sourceDto.setTuberculosis(YesNoUnknown.NO);
// lead has value, other has not
targetDto.setAsplenia(YesNoUnknown.YES);
// lead has no value, other has
sourceDto.setDiabetes(YesNoUnknown.YES);
DtoHelper.copyDtoValues(targetDto, sourceDto, false);
// Check no values
assertNull(targetDto.getHiv());
// Check 'lead and other have different values'
assertNotEquals(sourceDto.getTuberculosis(), targetDto.getTuberculosis());
// Check 'lead has value, other has not'
assertEquals(YesNoUnknown.YES, targetDto.getAsplenia());
assertNull(sourceDto.getAsplenia());
// Check 'lead has no value, other has'
assertEquals(sourceDto.getDiabetes(), targetDto.getDiabetes());
}
// Test complex subDto
{
PersonDto person = creator.createPerson("First", "Last");
CaseDataDto targetDto = creator.createCase(user.toReference(), person.toReference(), rdcf);
CaseDataDto sourceDto = creator.createCase(user.toReference(), person.toReference(), rdcf);
SymptomsDto targetSymptomsDto = targetDto.getSymptoms();
SymptomsDto sourceSymptomsDto = sourceDto.getSymptoms();
// lead and other have different values
SymptomState abdominalPain = SymptomState.NO;
targetSymptomsDto.setAbdominalPain(abdominalPain);
sourceSymptomsDto.setAbdominalPain(SymptomState.UNKNOWN);
// lead has value, other has not
SymptomState alteredConsciousness = SymptomState.YES;
targetSymptomsDto.setAlteredConsciousness(alteredConsciousness);
// lead has no value, other has
SymptomState anorexiaAppetiteLoss = SymptomState.UNKNOWN;
sourceSymptomsDto.setAnorexiaAppetiteLoss(anorexiaAppetiteLoss);
targetDto.setSymptoms(targetSymptomsDto);
sourceDto.setSymptoms(sourceSymptomsDto);
DtoHelper.copyDtoValues(targetDto, sourceDto, false);
// Check no values
assertNull(targetDto.getSymptoms().getBackache());
// Check 'lead and other have different values'
assertEquals(abdominalPain, targetDto.getSymptoms().getAbdominalPain());
// Check 'lead has value, other has not'
assertEquals(alteredConsciousness, targetDto.getSymptoms().getAlteredConsciousness());
// Check 'lead has no value, other has'
assertEquals(anorexiaAppetiteLoss, targetDto.getSymptoms().getAnorexiaAppetiteLoss());
}
// Test List
{
PersonDto person = creator.createPerson("First", "Last");
CaseDataDto targetDto = creator.createCase(user.toReference(), person.toReference(), rdcf);
CaseDataDto sourceDto = creator.createCase(user.toReference(), person.toReference(), rdcf);
ExposureDto subDto1 = ExposureDto.build(ExposureType.TRAVEL);
ExposureDto subDto2 = ExposureDto.build(ExposureType.TRAVEL);
// lead and other have different values
ArrayList<ExposureDto> targetList1 = new ArrayList<>();
targetList1.add(subDto1);
ArrayList<ExposureDto> sourceList1 = new ArrayList<>();
sourceList1.add(subDto2);
// lead has values, other has not
ArrayList<ExposureDto> targetList2 = new ArrayList<>();
targetList2.add(subDto1);
targetList2.add(subDto2);
// lead has no values, other has
ArrayList<ExposureDto> sourceList2 = new ArrayList<>();
sourceList2.add(subDto1);
sourceList2.add(subDto2);
// Check no values
DtoHelper.copyDtoValues(targetDto, sourceDto, false);
assertTrue(targetDto.getEpiData().getExposures().isEmpty());
// Check 'lead has still same entries'
targetDto.getEpiData().setExposures(targetList1);
sourceDto.getEpiData().setExposures(sourceList1);
String existingUuid = targetList1.get(0).getUuid();
DtoHelper.copyDtoValues(targetDto, sourceDto, false);
assertEquals(targetList1.size(), targetDto.getEpiData().getExposures().size());
assertNotNull(targetDto.getEpiData().getExposures().get(0).getUuid());
assertEquals(existingUuid, targetDto.getEpiData().getExposures().get(0).getUuid());
assertNotEquals(existingUuid, sourceDto.getEpiData().getExposures().get(0).getUuid());
// Check 'lead has value, other has not'
targetDto.getEpiData().setExposures(targetList2);
sourceDto.getEpiData().setExposures(null);
DtoHelper.copyDtoValues(targetDto, sourceDto, false);
assertNotNull(targetDto.getEpiData().getExposures().get(0).getUuid());
assertEquals(targetList2.size(), targetDto.getEpiData().getExposures().size());
assertEquals(targetList2.get(0).getUuid(), targetDto.getEpiData().getExposures().get(0).getUuid());
assertEquals(targetList2.get(1).getUuid(), targetDto.getEpiData().getExposures().get(1).getUuid());
// Check 'lead has no value, other has'
targetDto.getEpiData().setExposures(null);
sourceDto.getEpiData().setExposures(sourceList2);
DtoHelper.copyDtoValues(targetDto, sourceDto, false);
assertNotNull(targetDto.getEpiData().getExposures().get(0).getUuid());
assertEquals(sourceList2.size(), targetDto.getEpiData().getExposures().size());
assertNotEquals(sourceList2.get(0).getUuid(), targetDto.getEpiData().getExposures().get(0).getUuid());
assertNotEquals(sourceList2.get(1).getUuid(), targetDto.getEpiData().getExposures().get(1).getUuid());
}
// test non-entity list
{
PersonDto person = creator.createPerson("First", "Last");
CaseDataDto targetCaseDto = creator.createCase(user.toReference(), person.toReference(), rdcf);
CaseDataDto sourceCaseDto = creator.createCase(user.toReference(), person.toReference(), rdcf);
SampleDto sourceDto = creator.createSample(sourceCaseDto.toReference(), user.toReference(), rdcf2.facility);
sourceDto.setPathogenTestingRequested(true);
sourceDto.getRequestedPathogenTests().add(PathogenTestType.ANTIGEN_DETECTION);
sourceDto.getRequestedPathogenTests().add(PathogenTestType.NEUTRALIZING_ANTIBODIES);
SampleDto targetDto = SampleDto.build(user.toReference(), targetCaseDto.toReference());
DtoHelper.copyDtoValues(targetDto, sourceDto, false);
assertEquals(2, targetDto.getRequestedPathogenTests().size());
}
// test map
{
TestDataCreator.RDCF caseRdcf = creator.createRDCF();
Map<ReinfectionDetail, Boolean> map1 = new EnumMap<>(ReinfectionDetail.class);
map1.put(ReinfectionDetail.GENOME_SEQUENCE_CURRENT_INFECTION_KNOWN, true);
map1.put(ReinfectionDetail.PREVIOUS_ASYMPTOMATIC_INFECTION, true);
map1.put(ReinfectionDetail.LAST_PCR_DETECTION_NOT_RECENT, false);
PersonDto person = creator.createPerson();
CaseDataDto sourceCase = creator.createCase(user.toReference(), person.toReference(), caseRdcf);
CaseDataDto targetCase = creator.createCase(user.toReference(), person.toReference(), caseRdcf);
// Map must not be persisted because H2 can't map it to JSON
sourceCase.setReinfectionDetails(map1);
DtoHelper.copyDtoValues(targetCase, sourceCase, false);
assertEquals(3, targetCase.getReinfectionDetails().size());
sourceCase.getReinfectionDetails().put(ReinfectionDetail.PREVIOUS_ASYMPTOMATIC_INFECTION, false);
sourceCase.getReinfectionDetails().put(ReinfectionDetail.TESTED_NEGATIVE_AFTER_PREVIOUS_INFECTION, true);
DtoHelper.copyDtoValues(targetCase, sourceCase, false);
assertEquals(4, targetCase.getReinfectionDetails().size());
assertTrue(targetCase.getReinfectionDetails().get(ReinfectionDetail.PREVIOUS_ASYMPTOMATIC_INFECTION));
DtoHelper.copyDtoValues(targetCase, sourceCase, true);
assertEquals(4, targetCase.getReinfectionDetails().size());
assertFalse(targetCase.getReinfectionDetails().get(ReinfectionDetail.PREVIOUS_ASYMPTOMATIC_INFECTION));
sourceCase.setReinfectionDetails(null);
DtoHelper.copyDtoValues(targetCase, sourceCase, false);
assertEquals(4, targetCase.getReinfectionDetails().size());
DtoHelper.copyDtoValues(targetCase, sourceCase, true);
assertEquals(4, targetCase.getReinfectionDetails().size());
}
}
use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class SymptomsPseudonymizationTest method testSymptomsOutsideJurisdiction.
@Test
public void testSymptomsOutsideJurisdiction() {
CaseDataDto caze = createCaseWithSymptoms(user1, rdcf1);
SymptomsDto symptoms = getCaseFacade().getCaseDataByUuid(caze.getUuid()).getSymptoms();
assertThat(symptoms.getOnsetSymptom(), is("Test onset"));
assertThat(symptoms.getOtherHemorrhagicSymptomsText(), isEmptyString());
assertThat(symptoms.getOtherNonHemorrhagicSymptomsText(), isEmptyString());
assertThat(symptoms.getPatientIllLocation(), isEmptyString());
assertThat(symptoms.getCongenitalHeartDiseaseDetails(), isEmptyString());
}
use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class TaskFacadeEjbPseudonymizationTest method testGetTaskWithCaseOutsideJurisdiction.
@Test
public void testGetTaskWithCaseOutsideJurisdiction() {
CaseDataDto caze = creator.createCase(user1.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf1);
TaskDto task = createCaseTask(caze);
assertPseudonymized(getTaskFacade().getByUuid(task.getUuid()));
}
use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class TaskFacadeEjbPseudonymizationTest method testPseudonymizeExportList.
@Test
public void testPseudonymizeExportList() {
CaseDataDto caze1 = creator.createCase(user2.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf2);
TaskDto task1 = createCaseTask(caze1);
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);
TaskDto task2 = createCaseTask(caze2);
TaskDto task3 = createContactTask(contact1);
ContactDto contact2 = creator.createContact(user1.toReference(), null, creator.createPerson("John", "Smith").toReference(), caze2, new Date(), new Date(), Disease.CORONAVIRUS, rdcf1);
TaskDto task4 = createContactTask(contact2);
List<TaskExportDto> exportList = getTaskFacade().getExportList(new TaskCriteria(), null, 1, 100);
TaskExportDto export1 = exportList.stream().filter(t -> t.getUuid().equals(task1.getUuid())).findFirst().get();
assertThat(export1.getPersonFirstName(), is("John"));
assertThat(export1.getPersonLastName(), is("Smith"));
TaskExportDto export2 = exportList.stream().filter(t -> t.getUuid().equals(task2.getUuid())).findFirst().get();
assertThat(export2.getPersonFirstName(), is("Confidential"));
assertThat(export2.getPersonLastName(), is("Confidential"));
TaskExportDto export3 = exportList.stream().filter(t -> t.getUuid().equals(task3.getUuid())).findFirst().get();
assertThat(export3.getPersonFirstName(), is("John"));
assertThat(export3.getPersonLastName(), is("Smith"));
TaskExportDto export4 = exportList.stream().filter(t -> t.getUuid().equals(task4.getUuid())).findFirst().get();
assertThat(export4.getPersonFirstName(), is("Confidential"));
assertThat(export4.getPersonLastName(), is("Confidential"));
}
Aggregations