use of de.symeda.sormas.ui.TestDataCreator in project SORMAS-Project by hzi-braunschweig.
the class GermanCaseClassificationValidatorTest method testCaseClassificationValidator.
@Test
@Ignore("see #2599")
public void testCaseClassificationValidator() {
final TestDataCreator creator = new TestDataCreator();
final TestDataCreator.RDCF rdcf = creator.createRDCF("region", "district", "community", "facility");
final UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
final PersonDto cazePerson = creator.createPerson("Case", "Person");
final CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.CORONAVIRUS, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
final SymptomsDto symptoms = SymptomsDto.build();
caze.setSymptoms(symptoms);
final GermanCaseClassificationValidator validator = new GermanCaseClassificationValidator(caze.getUuid(), INVALID_CASE_CLASSIFICATION);
// assert classifications when no symptoms & no lab result
valid(CaseClassification.NOT_CLASSIFIED, validator);
invalid(CaseClassification.SUSPECT, validator);
valid(CaseClassification.PROBABLE, validator);
invalid(CaseClassification.CONFIRMED, validator);
invalid(CaseClassification.CONFIRMED_NO_SYMPTOMS, validator);
invalid(CaseClassification.CONFIRMED_UNKNOWN_SYMPTOMS, validator);
valid(CaseClassification.NO_CASE, validator);
// assert classifications when no symptoms & non-positive lab result
final SampleDto sample = creator.createSample(caze.toReference(), new Date(), new Date(), user.toReference(), SampleMaterial.BLOOD, rdcf.facility.toReference());
valid(CaseClassification.NOT_CLASSIFIED, validator);
invalid(CaseClassification.SUSPECT, validator);
valid(CaseClassification.PROBABLE, validator);
invalid(CaseClassification.CONFIRMED, validator);
invalid(CaseClassification.CONFIRMED_NO_SYMPTOMS, validator);
invalid(CaseClassification.CONFIRMED_UNKNOWN_SYMPTOMS, validator);
valid(CaseClassification.NO_CASE, validator);
// assert classifications when no symptoms & positive lab result
sample.setPathogenTestResult(PathogenTestResultType.POSITIVE);
getSampleFacade().saveSample(sample);
valid(CaseClassification.NOT_CLASSIFIED, validator);
invalid(CaseClassification.SUSPECT, validator);
valid(CaseClassification.PROBABLE, validator);
invalid(CaseClassification.CONFIRMED, validator);
invalid(CaseClassification.CONFIRMED_NO_SYMPTOMS, validator);
valid(CaseClassification.CONFIRMED_UNKNOWN_SYMPTOMS, validator);
valid(CaseClassification.NO_CASE, validator);
// assert classifications when no symptoms & positive lab result
sample.setPathogenTestResult(PathogenTestResultType.POSITIVE);
getSampleFacade().saveSample(sample);
valid(CaseClassification.NOT_CLASSIFIED, validator);
invalid(CaseClassification.SUSPECT, validator);
valid(CaseClassification.PROBABLE, validator);
invalid(CaseClassification.CONFIRMED, validator);
invalid(CaseClassification.CONFIRMED_NO_SYMPTOMS, validator);
valid(CaseClassification.CONFIRMED_UNKNOWN_SYMPTOMS, validator);
valid(CaseClassification.NO_CASE, validator);
// assert classifications when other symptoms & positive lab result
caze.getSymptoms().setFever(SymptomState.YES);
CaseDataDto savedCase1 = getCaseFacade().save(caze);
valid(CaseClassification.NOT_CLASSIFIED, validator);
invalid(CaseClassification.SUSPECT, validator);
valid(CaseClassification.PROBABLE, validator);
invalid(CaseClassification.CONFIRMED, validator);
valid(CaseClassification.CONFIRMED_NO_SYMPTOMS, validator);
invalid(CaseClassification.CONFIRMED_UNKNOWN_SYMPTOMS, validator);
valid(CaseClassification.NO_CASE, validator);
// assert classifications when other & covid symptoms & positive lab result
savedCase1.getSymptoms().setPneumoniaClinicalOrRadiologic(SymptomState.YES);
CaseDataDto savedCase2 = getCaseFacade().save(savedCase1);
valid(CaseClassification.NOT_CLASSIFIED, validator);
valid(CaseClassification.SUSPECT, validator);
valid(CaseClassification.PROBABLE, validator);
valid(CaseClassification.CONFIRMED, validator);
valid(CaseClassification.CONFIRMED_NO_SYMPTOMS, validator);
invalid(CaseClassification.CONFIRMED_UNKNOWN_SYMPTOMS, validator);
valid(CaseClassification.NO_CASE, validator);
// assert classifications when other & covid symptoms & negative lab result
sample.setPathogenTestResult(PathogenTestResultType.NEGATIVE);
getSampleFacade().saveSample(sample);
valid(CaseClassification.NOT_CLASSIFIED, validator);
valid(CaseClassification.SUSPECT, validator);
valid(CaseClassification.PROBABLE, validator);
invalid(CaseClassification.CONFIRMED, validator);
invalid(CaseClassification.CONFIRMED_NO_SYMPTOMS, validator);
invalid(CaseClassification.CONFIRMED_UNKNOWN_SYMPTOMS, validator);
valid(CaseClassification.NO_CASE, validator);
}
use of de.symeda.sormas.ui.TestDataCreator in project SORMAS-Project by hzi-braunschweig.
the class CaseImporterTest method testImportWithVaccinations.
@Test
@Ignore("Remove ignore once we have replaced H2, and feature properties can be changed by code")
public void testImportWithVaccinations() throws IOException, InterruptedException, CsvValidationException, InvalidColumnException, URISyntaxException {
TestDataCreator creator = new TestDataCreator();
TestDataCreator.RDCF rdcf = creator.createRDCF();
creator.createFacility("Lab", FacilityType.LABORATORY, rdcf.region.toReference(), rdcf.district.toReference(), rdcf.community.toReference());
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
// import of 3 cases with different number of vaccinations
File csvFile = new File(getClass().getClassLoader().getResource("sormas_case_import_test_vaccinations.csv").toURI());
CaseImporterExtension caseImporter = new CaseImporterExtension(csvFile, true, user);
ImportResultStatus importResult = caseImporter.runImport();
assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
CaseDataDto case1 = getCaseFacade().getByExternalId("case1").get(0);
CaseDataDto case2 = getCaseFacade().getByExternalId("case2").get(0);
CaseDataDto case3 = getCaseFacade().getByExternalId("case3").get(0);
List<VaccinationDto> case1Vaccinations = FacadeProvider.getVaccinationFacade().getAllVaccinations(case1.getPerson().getUuid(), Disease.CORONAVIRUS);
assertEquals(0, case1Vaccinations.size());
List<VaccinationDto> case2Vaccinations = FacadeProvider.getVaccinationFacade().getAllVaccinations(case2.getPerson().getUuid(), Disease.CORONAVIRUS);
assertEquals(1, case2Vaccinations.size());
assertEquals(Vaccine.COMIRNATY, case2Vaccinations.get(0).getVaccineName());
assertNull(case2Vaccinations.get(0).getHealthConditions().getChronicPulmonaryDisease());
List<VaccinationDto> case3Vaccinations = FacadeProvider.getVaccinationFacade().getAllVaccinations(case3.getPerson().getUuid(), Disease.CORONAVIRUS);
assertEquals(2, case3Vaccinations.size());
assertEquals(Vaccine.MRNA_1273, case3Vaccinations.get(0).getVaccineName());
assertEquals(YesNoUnknown.YES, case3Vaccinations.get(0).getHealthConditions().getChronicPulmonaryDisease());
assertEquals(Vaccine.MRNA_1273, case3Vaccinations.get(1).getVaccineName());
assertNull(case3Vaccinations.get(1).getHealthConditions().getChronicPulmonaryDisease());
}
use of de.symeda.sormas.ui.TestDataCreator in project SORMAS-Project by hzi-braunschweig.
the class CaseImporterTest method testImportAllCases.
@Test
public void testImportAllCases() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
TestDataCreator creator = new TestDataCreator();
TestDataCreator.RDCF rdcf = creator.createRDCF("Abia", "Umuahia North", "Urban Ward 2", "Anelechi Hospital");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
// Successful import of 5 cases
File csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_success.csv").toURI());
CaseImporterExtension caseImporter = new CaseImporterExtension(csvFile, true, user);
ImportResultStatus importResult = caseImporter.runImport();
assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
assertEquals(5, getCaseFacade().count(null));
// Failed import of 5 cases because of errors
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_errors.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user);
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importResult);
assertEquals(5, getCaseFacade().count(null));
// Similarity: skip
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@Override
protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
resultConsumer.accept((T) new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.SKIP));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-5", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: pick
List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@Override
protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
List<SimilarPersonDto> entries = new ArrayList<>();
for (SimilarPersonDto person : persons) {
if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
entries.add(person);
}
}
resultConsumer.accept((T) new CaseImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
}
@Override
protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
resultConsumer.accept(new CaseImportSimilarityResult(null, input.getSimilarCases().get(0), ImportSimilarityResultOption.PICK));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-5", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: cancel
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@Override
protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
resultConsumer.accept((T) new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CANCEL));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.CANCELED, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-5", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: override
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@Override
protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
List<SimilarPersonDto> entries = new ArrayList<>();
for (SimilarPersonDto person : persons) {
if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
entries.add(person);
}
}
resultConsumer.accept((T) new CaseImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
}
@Override
protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
resultConsumer.accept(new CaseImportSimilarityResult(null, input.getSimilarCases().get(0), ImportSimilarityResultOption.OVERRIDE));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-10", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: create -> fail because of duplicate epid number
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@Override
protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
List<SimilarPersonDto> entries = new ArrayList<>();
for (SimilarPersonDto person : persons) {
if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
entries.add(person);
}
}
resultConsumer.accept((T) new CaseImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
}
@Override
protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
resultConsumer.accept(new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CREATE));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-10", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Change epid number of the case in database to pass creation test
CaseDataDto caze = getCaseFacade().getAllActiveCasesAfter(null).get(4);
caze.setEpidNumber("ABC-DEF-GHI-19-99");
getCaseFacade().save(caze);
assertEquals("ABC-DEF-GHI-19-99", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: create -> pass
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user);
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(6, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-10", getCaseFacade().getAllActiveCasesAfter(null).get(5).getEpidNumber());
// Successful import of a case with different infrastructure combinations
creator.createRDCF("R1", "D1", "C1", "F1");
creator.createRDCF("R2", "D2", "C2", "F2");
creator.createRDCF("R3", "D3", "C3", "F3");
csvFile = new File(getClass().getClassLoader().getResource("sormas_case_import_test_different_infrastructure.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user);
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(7, getCaseFacade().count(null));
// Successful import of 5 cases from a commented CSV file
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_comment_success.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user);
importResult = caseImporter.runImport();
assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
assertEquals(12, getCaseFacade().count(null));
}
use of de.symeda.sormas.ui.TestDataCreator in project SORMAS-Project by hzi-braunschweig.
the class CaseImporterTest method testLineListingImport.
@Test
public void testLineListingImport() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
TestDataCreator.RDCF rdcf = new TestDataCreator().createRDCF("Abia", "Bende", "Bende Ward", "Bende Maternity Home");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
// Successful import of 5 cases
File csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_line_listing.csv").toURI());
CaseImporterExtension caseImporter = new CaseImporterExtension(csvFile, false, user);
ImportResultStatus importResult = caseImporter.runImport();
assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
assertEquals(5, getCaseFacade().count(null));
// Successful import of 5 cases from commented CSV file
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_comment_line_listing.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, false, user);
importResult = caseImporter.runImport();
assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
assertEquals(10, getCaseFacade().count(null));
}
use of de.symeda.sormas.ui.TestDataCreator in project SORMAS-Project by hzi-braunschweig.
the class CaseImporterTest method testImportAddressTypes.
@Test
public void testImportAddressTypes() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
TestDataCreator creator = new TestDataCreator();
TestDataCreator.RDCF rdcf = creator.createRDCF("Saarland", "RV Saarbrücken", "Kleinblittersdorf", "Winterberg");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
// import of 3 cases with different address types
File csvFile = new File(getClass().getClassLoader().getResource("sormas_case_import_address_type.csv").toURI());
CaseImporterExtension caseImporter = new CaseImporterExtension(csvFile, true, user);
ImportResultStatus importResult = caseImporter.runImport();
PersonDto casePerson1 = getPersonFacade().getPersonByUuid(getCaseFacade().getByExternalId("SL-DEF-GHI-19-1").get(0).getPerson().getUuid());
PersonDto casePerson2 = getPersonFacade().getPersonByUuid(getCaseFacade().getByExternalId("SL-DEF-GHI-19-2").get(0).getPerson().getUuid());
PersonDto casePerson3 = getPersonFacade().getPersonByUuid(getCaseFacade().getByExternalId("SL-DEF-GHI-19-3").get(0).getPerson().getUuid());
assertTrue(CollectionUtils.isEmpty(casePerson1.getAddresses()));
assertEquals("131", casePerson1.getAddress().getHouseNumber());
assertTrue(CollectionUtils.isEmpty(casePerson2.getAddresses()));
assertEquals("132", casePerson2.getAddress().getHouseNumber());
assertTrue(casePerson3.getAddress().checkIsEmptyLocation());
assertEquals(1, casePerson3.getAddresses().size());
assertEquals("133", casePerson3.getAddresses().get(0).getHouseNumber());
}
Aggregations