use of de.symeda.sormas.api.infrastructure.facility.FacilityCriteria in project SORMAS-Project by hzi-braunschweig.
the class StartupShutdownService method createDefaultInfrastructureData.
private void createDefaultInfrastructureData() {
if (!configFacade.isCreateDefaultEntities()) {
// return if isCreateDefaultEntities() is false
logger.info("Skipping the creation of default infrastructure data");
return;
}
// Region
Region region = null;
if (regionService.count() == 0) {
region = defaultEntitiesCreator.createDefaultRegion(false);
regionService.ensurePersisted(region);
}
// District
District district = null;
if (districtService.count() == 0) {
if (region == null) {
region = regionService.getAll().get(0);
}
district = defaultEntitiesCreator.createDefaultDistrict(region, false);
districtService.ensurePersisted(district);
region.getDistricts().add(district);
}
// Community
Community community = null;
if (communityService.count() == 0) {
if (district == null) {
district = districtService.getAll().get(0);
}
community = defaultEntitiesCreator.createDefaultCommunity(district, false);
communityService.ensurePersisted(community);
district.getCommunities().add(community);
}
// Facility
Facility facility;
FacilityCriteria facilityCriteria = new FacilityCriteria();
if (facilityFacade.count(facilityCriteria) == 0) {
if (community == null) {
community = communityService.getAll().get(0);
}
if (district == null) {
district = districtService.getAll().get(0);
}
if (region == null) {
region = regionService.getAll().get(0);
}
facility = defaultEntitiesCreator.createDefaultFacility(region, district, community);
facilityService.ensurePersisted(facility);
}
// Laboratory
Facility laboratory;
facilityCriteria.type(FacilityType.LABORATORY);
if (facilityFacade.count(facilityCriteria) == 0) {
if (community == null) {
community = communityService.getAll().get(0);
}
if (district == null) {
district = districtService.getAll().get(0);
}
if (region == null) {
region = regionService.getAll().get(0);
}
laboratory = defaultEntitiesCreator.createDefaultLaboratory(region, district, community);
facilityService.ensurePersisted(laboratory);
}
// Point of Entry
PointOfEntry pointOfEntry;
if (pointOfEntryService.count() == 0) {
if (district == null) {
district = districtService.getAll().get(0);
}
if (region == null) {
region = regionService.getAll().get(0);
}
pointOfEntry = defaultEntitiesCreator.createDefaultPointOfEntry(region, district);
pointOfEntryService.ensurePersisted(pointOfEntry);
}
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityCriteria in project SORMAS-Project by hzi-braunschweig.
the class DevModeView method generateSamples.
private void generateSamples() {
initializeRandomGenerator();
SampleGenerationConfig config = sampleGeneratorConfigBinder.getBean();
float baseOffset = random().nextFloat();
int daysBetween = (int) ChronoUnit.DAYS.between(config.startDate, config.endDate);
FacilityCriteria facilityCriteria = new FacilityCriteria();
facilityCriteria.region(config.getRegion());
facilityCriteria.district(config.getDistrict());
long dt = System.nanoTime();
UserReferenceDto user = UserProvider.getCurrent().getUserReference();
List<CaseReferenceDto> cases = FacadeProvider.getCaseFacade().getRandomCaseReferences(new CaseCriteria().region(config.getRegion()).district(config.getDistrict()).disease(config.getDisease()), config.getSampleCount() * 2, random());
if (nonNull(cases)) {
for (int i = 0; i < config.getSampleCount(); i++) {
CaseReferenceDto caseReference = random(cases);
List<Disease> diseases = FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true);
Disease disease = config.getDisease();
if (disease == null) {
disease = random(diseases);
config.setDisease(disease);
}
LocalDateTime referenceDateTime = getReferenceDateTime(i, config.getSampleCount(), baseOffset, config.getDisease(), config.getStartDate(), daysBetween);
SampleDto sample = SampleDto.build(user, caseReference);
sample.setSamplePurpose(config.getSamplePurpose());
Date date = Date.from(referenceDateTime.toLocalDate().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
sample.setSampleDateTime(date);
sample.setSampleMaterial(config.getSampleMaterial());
sample.setFieldSampleID(UUID.randomUUID().toString());
sample.setComment(random(sampleComments));
sample.setLab(config.getLaboratory());
if (config.isRequestPathogenTestsToBePerformed()) {
Set pathogenTestTypes = new HashSet<PathogenTestType>();
int until = randomInt(1, PathogenTestType.values().length);
for (int j = 0; j < until; j++) {
pathogenTestTypes.add(PathogenTestType.values()[j]);
}
sample.setPathogenTestingRequested(true);
sample.setRequestedPathogenTests(pathogenTestTypes);
}
if (config.isRequestAdditionalTestsToBePerformed()) {
Set additionalTestTypes = new HashSet<AdditionalTestType>();
int until = randomInt(1, AdditionalTestType.values().length);
for (int j = 0; j < until; j++) {
additionalTestTypes.add(AdditionalTestType.values()[j]);
}
sample.setAdditionalTestingRequested(true);
sample.setRequestedAdditionalTests(additionalTestTypes);
}
if (config.isSendDispatch()) {
sample.setShipped(true);
sample.setShipmentDate(date);
sample.setShipmentDetails(random(sampleShipmentDetails));
}
if (config.isReceived()) {
sample.setReceived(true);
sample.setReceivedDate(date);
sample.setSpecimenCondition(random(SpecimenCondition.values()));
}
SampleDto sampleDto = FacadeProvider.getSampleFacade().saveSample(sample);
if (config.isRequestAdditionalTestsToBePerformed()) {
createAdditionalTest(sampleDto, date);
}
}
dt = System.nanoTime() - dt;
long perSample = dt / config.getSampleCount();
String msg = String.format("Generating %d samples took %.2f s (%.1f ms per sample)", config.getSampleCount(), (double) dt / 1_000_000_000, (double) perSample / 1_000_000);
logger.info(msg);
Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
} else {
String msg = "No Sample has been generated because cases is null ";
logger.info(msg);
Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
}
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityCriteria in project SORMAS-Project by hzi-braunschweig.
the class FacilityFacadeEjbTest method testGetIndexListMappedSorting.
@Test
public void testGetIndexListMappedSorting() {
FacilityCriteria facilityCriteria = new FacilityCriteria();
// 0. No sortProperties
List<FacilityIndexDto> result = getFacilityFacade().getIndexList(facilityCriteria, null, null, new ArrayList<>());
assertThat(result, is(empty()));
List<SortProperty> allSortProperties = new ArrayList<>();
allSortProperties.add(new SortProperty(FacilityDto.NAME));
allSortProperties.add(new SortProperty(FacilityDto.TYPE));
allSortProperties.add(new SortProperty(FacilityDto.REGION));
allSortProperties.add(new SortProperty(FacilityDto.DISTRICT));
allSortProperties.add(new SortProperty(FacilityDto.COMMUNITY));
allSortProperties.add(new SortProperty(FacilityDto.CITY));
allSortProperties.add(new SortProperty(FacilityDto.LATITUDE));
allSortProperties.add(new SortProperty(FacilityDto.LONGITUDE));
allSortProperties.add(new SortProperty(FacilityDto.EXTERNAL_ID));
// 1. Sort by every property
for (SortProperty sortProperty : allSortProperties) {
getFacilityFacade().getIndexList(facilityCriteria, null, null, Collections.singletonList(sortProperty));
assertThat(sortProperty.toString(), result, is(empty()));
}
// 2. Sort by all properties at once
getFacilityFacade().getIndexList(facilityCriteria, null, null, allSortProperties);
assertThat(result, is(empty()));
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityCriteria in project SORMAS-Project by hzi-braunschweig.
the class InfrastructureImporterTest method testDontImportDuplicateInfrastructure.
@Test
public void testDontImportDuplicateInfrastructure() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
RDCF rdcf = new TestDataCreator().createRDCF("Default Region", "Default District", "Default Community", "Default Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Default", "User", UserRole.ADMIN);
// Import region
File regionCsvFile = new File(getClass().getClassLoader().getResource("sormas_region_import_test.csv").toURI());
InfrastructureImporter importer = new InfrastructureImporterExtension(regionCsvFile, user, InfrastructureType.REGION);
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
assertEquals(2, getRegionFacade().count(new RegionCriteria()));
// Import district
File districtCsvFile = new File(getClass().getClassLoader().getResource("sormas_district_import_test.csv").toURI());
importer = new InfrastructureImporterExtension(districtCsvFile, user, InfrastructureType.DISTRICT);
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
assertEquals(2, getDistrictFacade().count(new DistrictCriteria()));
// Import community
File communityCsvFile = new File(getClass().getClassLoader().getResource("sormas_community_import_test.csv").toURI());
importer = new InfrastructureImporterExtension(communityCsvFile, user, InfrastructureType.COMMUNITY);
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
assertEquals(2, getCommunityFacade().count(new CommunityCriteria()));
// Import facility
File facilityCsvFile = new File(getClass().getClassLoader().getResource("sormas_facility_import_test.csv").toURI());
importer = new InfrastructureImporterExtension(facilityCsvFile, user, InfrastructureType.FACILITY);
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
assertEquals(3, getFacilityFacade().count(new FacilityCriteria()));
// Import point of entry
File poeCsvFile = new File(getClass().getClassLoader().getResource("sormas_poe_import_test.csv").toURI());
importer = new InfrastructureImporterExtension(poeCsvFile, user, InfrastructureType.POINT_OF_ENTRY);
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importer.runImport());
assertEquals(1, getPointOfEntryFacade().count(new PointOfEntryCriteria()));
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityCriteria in project SORMAS-Project by hzi-braunschweig.
the class DevModeView method generateEvents.
private void generateEvents() {
initializeRandomGenerator();
EventGenerationConfig config = eventGeneratorConfigBinder.getBean();
int generatedParticipants = 0;
int generatedCases = 0;
int generatedContacts = 0;
Disease disease = config.getDisease();
float baseOffset = random().nextFloat();
int daysBetween = (int) ChronoUnit.DAYS.between(config.startDate, config.endDate);
// this should be adjusted to be much more complex
FacilityCriteria facilityCriteria = new FacilityCriteria();
facilityCriteria.region(config.getRegion());
facilityCriteria.district(config.getDistrict());
List<FacilityIndexDto> healthFacilities = FacadeProvider.getFacilityFacade().getIndexList(facilityCriteria, 0, (int) (config.getMaxParticipantsPerEvent() * config.getPercentageOfCases() / 100), null);
// Filter list, so that only health facilities meant for accomodation are selected
healthFacilities.removeIf(el -> (!el.getType().isAccommodation()));
long dt = System.nanoTime();
for (int i = 0; i < config.getEventCount(); i++) {
LocalDateTime referenceDateTime;
EventDto event = EventDto.build();
// disease
if (disease != null) {
// reset
event.setDisease(disease);
if (event.getDisease() == Disease.OTHER) {
event.setDiseaseDetails("RD " + (random().nextInt(20) + 1));
}
referenceDateTime = getReferenceDateTime(i, config.getEventCount(), baseOffset, disease, config.getStartDate(), daysBetween);
fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
} else {
referenceDateTime = getReferenceDateTime(i, config.getEventCount(), baseOffset, Disease.OTHER, config.getStartDate(), daysBetween);
fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(Disease.OTHER).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
}
// title
event.setEventTitle(random(eventTitles));
// description
event.setEventDesc("Event generated using DevMode on " + LocalDate.now());
// report
UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
event.setReportingUser(userReference);
event.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
// region & district
event.getEventLocation().setRegion(config.getRegion());
event.getEventLocation().setDistrict(config.getDistrict());
// status
event.setEventStatus(EventStatus.EVENT);
FacadeProvider.getEventFacade().save(event);
// EventParticipants
int numParticipants = randomInt(config.getMinParticipantsPerEvent(), config.getMaxParticipantsPerEvent());
for (int j = 0; j < numParticipants; j++) {
EventParticipantDto eventParticipant = EventParticipantDto.build(event.toReference(), UserProvider.getCurrent().getUserReference());
// person
// instead of creating new persons everytime, it would be nice if some persons came of the original database
PersonDto person = PersonDto.build();
fillEntity(person, referenceDateTime);
person.setSymptomJournalStatus(null);
setPersonName(person);
FacadeProvider.getPersonFacade().savePerson(person);
eventParticipant.setPerson(person);
eventParticipant.setInvolvementDescription("Participant");
if (disease != null) {
// generate cases for some participants
if (randomPercent(config.getPercentageOfCases()) && !healthFacilities.isEmpty()) {
CaseDataDto caze = CaseDataDto.buildFromEventParticipant(eventParticipant, person, event.getDisease());
fillEntity(caze, referenceDateTime);
caze.setDisease(event.getDisease());
caze.setReportingUser(UserProvider.getCurrent().getUserReference());
caze.setReportDate(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
caze.setResponsibleRegion(config.getRegion());
caze.setResponsibleDistrict(config.getDistrict());
FacilityIndexDto facility = random(healthFacilities);
caze.setHealthFacility(facility.toReference());
caze.setFacilityType(facility.getType());
caze.setAdditionalDetails("Case generated using DevMode on " + LocalDate.now());
FacadeProvider.getCaseFacade().save(caze);
eventParticipant.setResultingCase(caze.toReference());
generatedCases++;
}
// generate contacts for some participants
List<CaseReferenceDto> cases = FacadeProvider.getCaseFacade().getRandomCaseReferences(new CaseCriteria().region(config.getRegion()).district(config.getDistrict()).disease(event.getDisease()), numParticipants * 2, random());
int numContacts = randomInt(config.getMinContactsPerParticipant(), config.getMaxContactsPerParticipant());
for (int k = 0; (k < numContacts && (cases != null)); k++) {
ContactDto contact = ContactDto.build(eventParticipant);
contact.setDisease(event.getDisease());
contact.setCaze(random(cases));
contact.setReportingUser(UserProvider.getCurrent().getUserReference());
contact.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
contact.setDescription("Contact generated using DevMode on " + LocalDate.now());
FacadeProvider.getContactFacade().save(contact);
generatedContacts++;
}
}
FacadeProvider.getEventParticipantFacade().saveEventParticipant(eventParticipant);
generatedParticipants++;
}
}
dt = System.nanoTime() - dt;
long perCase = dt / config.getEventCount();
String msg = String.format("Generating %d events with a total of %d participants (%d contacts, %d cases) took %.2f s (%.1f ms per event)", config.getEventCount(), generatedParticipants, generatedContacts, generatedCases, (double) dt / 1_000_000_000, (double) perCase / 1_000_000);
logger.info(msg);
Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
}
Aggregations