use of de.symeda.sormas.backend.infrastructure.country.Country in project SORMAS-Project by hzi-braunschweig.
the class StartupShutdownService method upgrade.
private void upgrade() {
@SuppressWarnings("unchecked") List<Integer> versionsNeedingUpgrade = em.createNativeQuery("SELECT version_number FROM schema_version WHERE upgradeNeeded").getResultList();
for (Integer versionNeedingUpgrade : versionsNeedingUpgrade) {
switch(versionNeedingUpgrade) {
case 95:
// update follow up and status for all contacts
for (Contact contact : contactService.getAll()) {
contactService.updateFollowUpDetails(contact, false);
contactService.udpateContactStatus(contact);
}
break;
case 354:
CountryReferenceDto serverCountry = countryFacade.getServerCountry();
if (serverCountry != null) {
Country country = countryService.getByUuid(serverCountry.getUuid());
em.createQuery("UPDATE Region set country = :server_country, changeDate = :change_date WHERE country is null").setParameter("server_country", country).setParameter("change_date", new Timestamp(new Date().getTime())).executeUpdate();
}
break;
default:
throw new NoSuchElementException(DataHelper.toStringNullable(versionNeedingUpgrade));
}
int updatedRows = em.createNativeQuery("UPDATE schema_version SET upgradeNeeded=false WHERE version_number=?1").setParameter(1, versionNeedingUpgrade).executeUpdate();
if (updatedRows != 1) {
logger.error("Could not UPDATE schema_version table. Missing user rights?");
}
}
}
use of de.symeda.sormas.backend.infrastructure.country.Country in project SORMAS-Project by hzi-braunschweig.
the class InfraValidationSoundnessTest method setUpInfra.
protected void setUpInfra(boolean randomUuid) {
DefaultEntitiesCreator defaultEntitiesCreator = getDefaultEntitiesCreator();
Continent continent = defaultEntitiesCreator.createDefaultContinent(randomUuid);
getContinentService().ensurePersisted(continent);
Subcontinent subcontinent = defaultEntitiesCreator.createDefaultSubcontinent(continent, randomUuid);
getSubcontinentService().ensurePersisted(subcontinent);
Country country = defaultEntitiesCreator.createDefaultCountry(subcontinent, randomUuid);
getCountryService().ensurePersisted(country);
Region region = defaultEntitiesCreator.createDefaultRegion(randomUuid);
getRegionService().ensurePersisted(region);
District district = defaultEntitiesCreator.createDefaultDistrict(region, randomUuid);
getDistrictService().ensurePersisted(district);
Community community = defaultEntitiesCreator.createDefaultCommunity(district, randomUuid);
getCommunityService().ensurePersisted(community);
assert !getRegionService().getAll().isEmpty();
}
use of de.symeda.sormas.backend.infrastructure.country.Country in project SORMAS-Project by hzi-braunschweig.
the class RegionFacadeEjb method getIndexList.
@Override
public List<RegionIndexDto> getIndexList(RegionCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Region> cq = cb.createQuery(Region.class);
Root<Region> region = cq.from(Region.class);
Join<Region, Area> area = region.join(Region.AREA, JoinType.LEFT);
Join<Region, Country> country = region.join(Region.COUNTRY, JoinType.LEFT);
Predicate filter = null;
if (criteria != null) {
filter = service.buildCriteriaFilter(criteria, cb, region);
}
if (filter != null) {
cq.where(filter);
}
if (CollectionUtils.isNotEmpty(sortProperties)) {
List<Order> order = new ArrayList<>(sortProperties.size());
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case Region.NAME:
case Region.EPID_CODE:
case Region.GROWTH_RATE:
case Region.EXTERNAL_ID:
expression = region.get(sortProperty.propertyName);
break;
case Region.AREA:
expression = area.get(Area.NAME);
break;
case RegionIndexDto.COUNTRY:
expression = country.get(Country.DEFAULT_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.asc(region.get(Region.NAME)));
}
cq.select(region);
return QueryHelper.getResultList(em, cq, first, max, this::toIndexDto);
}
use of de.symeda.sormas.backend.infrastructure.country.Country in project SORMAS-Project by hzi-braunschweig.
the class ContinentFacadeEjb method getByCountry.
@Override
public ContinentReferenceDto getByCountry(CountryReferenceDto countryReferenceDto) {
final Country country = countryService.getByUuid(countryReferenceDto.getUuid());
final Subcontinent subcontinent = country.getSubcontinent();
return subcontinent != null ? toReferenceDto(subcontinent.getContinent()) : null;
}
use of de.symeda.sormas.backend.infrastructure.country.Country in project SORMAS-Project by hzi-braunschweig.
the class EventParticipantFacadeEjb method getExportList.
@Override
public List<EventParticipantExportDto> getExportList(EventParticipantCriteria eventParticipantCriteria, Collection<String> selectedRows, int first, int max, Language userLanguage, ExportConfigurationDto exportConfiguration) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<EventParticipantExportDto> cq = cb.createQuery(EventParticipantExportDto.class);
Root<EventParticipant> eventParticipant = cq.from(EventParticipant.class);
EventParticipantQueryContext eventParticipantQueryContext = new EventParticipantQueryContext(cb, cq, eventParticipant);
EventParticipantJoins<EventParticipant> joins = (EventParticipantJoins<EventParticipant>) eventParticipantQueryContext.getJoins();
Join<EventParticipant, Person> person = joins.getPerson();
PersonQueryContext personQueryContext = new PersonQueryContext(cb, cq, person);
Join<Person, Location> address = joins.getAddress();
Join<Person, Country> birthCountry = person.join(Person.BIRTH_COUNTRY, JoinType.LEFT);
Join<Person, Country> citizenship = person.join(Person.CITIZENSHIP, JoinType.LEFT);
Join<EventParticipant, Event> event = joins.getEvent();
Join<Event, Location> eventLocation = joins.getEventAddress();
Join<EventParticipant, Case> resultingCase = joins.getResultingCase();
cq.multiselect(eventParticipant.get(EventParticipant.ID), person.get(Person.ID), person.get(Person.UUID), eventParticipant.get(EventParticipant.UUID), person.get(Person.NATIONAL_HEALTH_ID), person.get(Location.ID), JurisdictionHelper.booleanSelector(cb, service.inJurisdictionOrOwned(eventParticipantQueryContext)), event.get(Event.UUID), event.get(Event.EVENT_STATUS), event.get(Event.EVENT_INVESTIGATION_STATUS), event.get(Event.DISEASE), event.get(Event.TYPE_OF_PLACE), event.get(Event.START_DATE), event.get(Event.END_DATE), event.get(Event.EVENT_TITLE), event.get(Event.EVENT_DESC), eventLocation.join(Location.REGION, JoinType.LEFT).get(Region.NAME), eventLocation.join(Location.DISTRICT, JoinType.LEFT).get(District.NAME), eventLocation.join(Location.COMMUNITY, JoinType.LEFT).get(Community.NAME), eventLocation.get(Location.CITY), eventLocation.get(Location.STREET), eventLocation.get(Location.HOUSE_NUMBER), person.get(Person.FIRST_NAME), person.get(Person.LAST_NAME), person.get(Person.SALUTATION), person.get(Person.OTHER_SALUTATION), person.get(Person.SEX), eventParticipant.get(EventParticipant.INVOLVEMENT_DESCRIPTION), person.get(Person.APPROXIMATE_AGE), person.get(Person.APPROXIMATE_AGE_TYPE), person.get(Person.BIRTHDATE_DD), person.get(Person.BIRTHDATE_MM), person.get(Person.BIRTHDATE_YYYY), person.get(Person.PRESENT_CONDITION), person.get(Person.DEATH_DATE), person.get(Person.BURIAL_DATE), person.get(Person.BURIAL_CONDUCTOR), person.get(Person.BURIAL_PLACE_DESCRIPTION), joins.getAddressRegion().get(Region.NAME), joins.getAddressDistrict().get(District.NAME), joins.getAddressCommunity().get(Community.NAME), address.get(Location.CITY), address.get(Location.STREET), address.get(Location.HOUSE_NUMBER), address.get(Location.ADDITIONAL_INFORMATION), address.get(Location.POSTAL_CODE), personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_PHONE_SUBQUERY), personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_EMAIL_SUBQUERY), resultingCase.get(Case.UUID), person.get(Person.BIRTH_NAME), birthCountry.get(Country.ISO_CODE), birthCountry.get(Country.DEFAULT_NAME), citizenship.get(Country.ISO_CODE), citizenship.get(Country.DEFAULT_NAME), eventParticipant.get(EventParticipant.VACCINATION_STATUS));
Predicate filter = service.buildCriteriaFilter(eventParticipantCriteria, eventParticipantQueryContext);
filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, eventParticipant.get(EventParticipant.UUID));
cq.where(filter);
List<EventParticipantExportDto> eventParticipantResultList = QueryHelper.getResultList(em, cq, first, max);
if (!eventParticipantResultList.isEmpty()) {
Map<String, Long> eventParticipantContactCount = getContactCountPerEventParticipant(eventParticipantResultList.stream().map(EventParticipantExportDto::getEventParticipantUuid).collect(Collectors.toList()), eventParticipantCriteria);
Map<Long, Location> personAddresses = null;
if (ExportHelper.shouldExportFields(exportConfiguration, PersonDto.ADDRESS, CaseExportDto.ADDRESS_GPS_COORDINATES)) {
CriteriaQuery<Location> personAddressesCq = cb.createQuery(Location.class);
Root<Location> personAddressesRoot = personAddressesCq.from(Location.class);
Expression<String> personAddressesIdsExpr = personAddressesRoot.get(Location.ID);
personAddressesCq.where(personAddressesIdsExpr.in(eventParticipantResultList.stream().map(EventParticipantExportDto::getPersonAddressId).collect(Collectors.toList())));
List<Location> personAddressesList = em.createQuery(personAddressesCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
personAddresses = personAddressesList.stream().collect(Collectors.toMap(Location::getId, Function.identity()));
}
Map<Long, List<Sample>> samples = null;
if (ExportHelper.shouldExportFields(exportConfiguration, EventParticipantExportDto.SAMPLE_INFORMATION)) {
List<Sample> samplesList = null;
CriteriaQuery<Sample> samplesCq = cb.createQuery(Sample.class);
Root<Sample> samplesRoot = samplesCq.from(Sample.class);
Join<Sample, EventParticipant> samplesEventParticipantJoin = samplesRoot.join(Sample.ASSOCIATED_EVENT_PARTICIPANT, JoinType.LEFT);
Expression<String> eventParticipantIdsExpr = samplesEventParticipantJoin.get(EventParticipant.ID);
samplesCq.where(eventParticipantIdsExpr.in(eventParticipantResultList.stream().map(EventParticipantExportDto::getId).collect(Collectors.toList())));
samplesList = em.createQuery(samplesCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
samples = samplesList.stream().collect(Collectors.groupingBy(s -> s.getAssociatedEventParticipant().getId()));
}
Map<Long, List<Immunization>> immunizations = null;
if (exportConfiguration == null || exportConfiguration.getProperties().stream().anyMatch(p -> StringUtils.equalsAny(p, ExportHelper.getVaccinationExportProperties()))) {
List<Immunization> immunizationList;
CriteriaQuery<Immunization> immunizationsCq = cb.createQuery(Immunization.class);
Root<Immunization> immunizationsCqRoot = immunizationsCq.from(Immunization.class);
Join<Immunization, Person> personJoin = immunizationsCqRoot.join(Immunization.PERSON, JoinType.LEFT);
Expression<String> personIdsExpr = personJoin.get(Person.ID);
immunizationsCq.where(CriteriaBuilderHelper.and(cb, cb.or(cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION), cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION_RECOVERY)), personIdsExpr.in(eventParticipantResultList.stream().map(EventParticipantExportDto::getPersonId).collect(Collectors.toList()))));
immunizationList = em.createQuery(immunizationsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
immunizations = immunizationList.stream().collect(Collectors.groupingBy(i -> i.getPerson().getId()));
}
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
for (EventParticipantExportDto exportDto : eventParticipantResultList) {
final boolean inJurisdiction = exportDto.getInJurisdiction();
if (personAddresses != null) {
Optional.ofNullable(personAddresses.get(exportDto.getPersonAddressId())).ifPresent(personAddress -> exportDto.setAddressGpsCoordinates(personAddress.buildGpsCoordinatesCaption()));
}
if (samples != null) {
Optional.ofNullable(samples.get(exportDto.getId())).ifPresent(eventParticipantSamples -> {
int count = 0;
for (Sample sample : eventParticipantSamples) {
EmbeddedSampleExportDto sampleDto = new EmbeddedSampleExportDto(sample.getUuid(), sample.getSampleDateTime(), sample.getLab() != null ? FacilityHelper.buildFacilityString(sample.getLab().getUuid(), sample.getLab().getName(), sample.getLabDetails()) : null, sample.getPathogenTestResult());
exportDto.addEventParticipantSample(sampleDto);
}
});
}
if (immunizations != null) {
Optional.ofNullable(immunizations.get(exportDto.getPersonId())).ifPresent(epImmunizations -> {
List<Immunization> filteredImmunizations = epImmunizations.stream().filter(i -> i.getDisease() == exportDto.getEventDisease()).collect(Collectors.toList());
filteredImmunizations.sort(Comparator.comparing(i -> ImmunizationEntityHelper.getDateForComparison(i, false)));
Immunization mostRecentImmunization = filteredImmunizations.get(filteredImmunizations.size() - 1);
exportDto.setVaccinationDoses(String.valueOf(mostRecentImmunization.getNumberOfDoses()));
if (CollectionUtils.isNotEmpty(mostRecentImmunization.getVaccinations())) {
List<Vaccination> sortedVaccinations = mostRecentImmunization.getVaccinations().stream().sorted(Comparator.comparing(ImmunizationEntityHelper::getVaccinationDateForComparison)).collect(Collectors.toList());
Vaccination firstVaccination = sortedVaccinations.get(0);
Vaccination lastVaccination = sortedVaccinations.get(sortedVaccinations.size() - 1);
exportDto.setFirstVaccinationDate(firstVaccination.getVaccinationDate());
exportDto.setLastVaccinationDate(lastVaccination.getVaccinationDate());
exportDto.setVaccineName(lastVaccination.getVaccineName());
exportDto.setOtherVaccineName(lastVaccination.getOtherVaccineName());
exportDto.setVaccineManufacturer(lastVaccination.getVaccineManufacturer());
exportDto.setOtherVaccineManufacturer(lastVaccination.getOtherVaccineManufacturer());
exportDto.setVaccinationInfoSource(lastVaccination.getVaccinationInfoSource());
exportDto.setVaccineAtcCode(lastVaccination.getVaccineAtcCode());
exportDto.setVaccineBatchNumber(lastVaccination.getVaccineBatchNumber());
exportDto.setVaccineUniiCode(lastVaccination.getVaccineUniiCode());
exportDto.setVaccineInn(lastVaccination.getVaccineInn());
}
});
}
Optional.ofNullable(eventParticipantContactCount.get(exportDto.getEventParticipantUuid())).ifPresent(exportDto::setContactCount);
pseudonymizer.pseudonymizeDto(EventParticipantExportDto.class, exportDto, inJurisdiction, (c) -> {
pseudonymizer.pseudonymizeDto(BirthDateDto.class, c.getBirthdate(), inJurisdiction, null);
pseudonymizer.pseudonymizeDtoCollection(EmbeddedSampleExportDto.class, c.getEventParticipantSamples(), s -> inJurisdiction, null);
pseudonymizer.pseudonymizeDto(BurialInfoDto.class, c.getBurialInfo(), inJurisdiction, null);
});
}
}
return eventParticipantResultList;
}
Aggregations