use of de.symeda.sormas.api.infrastructure.facility.FacilityDto in project SORMAS-Project by hzi-braunschweig.
the class FacilityFacadeEjb method getAllByRegionAfter.
@Override
public List<FacilityDto> getAllByRegionAfter(String regionUuid, Date date) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<FacilityDto> cq = cb.createQuery(FacilityDto.class);
Root<Facility> facility = cq.from(Facility.class);
selectDtoFields(cq, facility);
Predicate filter = service.createChangeDateFilter(cb, facility, date);
if (regionUuid != null) {
Predicate regionFilter = cb.equal(facility.get(Facility.REGION), regionService.getByUuid(regionUuid));
filter = CriteriaBuilderHelper.and(cb, filter, regionFilter);
}
if (filter != null) {
cq.where(filter);
}
return em.createQuery(cq).getResultList();
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityDto in project SORMAS-Project by hzi-braunschweig.
the class FacilityFacadeEjb method getAllWithoutRegionAfter.
@Override
public List<FacilityDto> getAllWithoutRegionAfter(Date date) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<FacilityDto> cq = cb.createQuery(FacilityDto.class);
Root<Facility> facility = cq.from(Facility.class);
selectDtoFields(cq, facility);
Predicate filter = service.createChangeDateFilter(cb, facility, date);
Predicate regionFilter = cb.isNull(facility.get(Facility.REGION));
filter = CriteriaBuilderHelper.and(cb, filter, regionFilter);
if (filter != null) {
cq.where(filter);
}
return em.createQuery(cq).getResultList();
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityDto in project SORMAS-Project by hzi-braunschweig.
the class FacilityFacadeEjbTest method testGetAllByRegionAfter.
@Test
public void testGetAllByRegionAfter() throws InterruptedException {
RDCF rdcf = creator.createRDCF();
getFacilityService().doFlush();
Date date = new Date();
List<FacilityDto> results = getFacilityFacade().getAllByRegionAfter(rdcf.region.getUuid(), date);
// List should be empty
assertEquals(0, results.size());
// delay to ignore known rounding issues in change date filter
Thread.sleep(1);
String facilityName = "facility2";
creator.createFacility(facilityName, rdcf.region, rdcf.district, rdcf.community);
results = getFacilityFacade().getAllByRegionAfter(rdcf.region.getUuid(), date);
// List should have one entry
assertEquals(1, results.size());
assertEquals(facilityName, results.get(0).getName());
assertEquals(rdcf.community.getUuid(), results.get(0).getCommunity().getUuid());
assertEquals(rdcf.region.getUuid(), results.get(0).getRegion().getUuid());
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityDto in project SORMAS-Project by hzi-braunschweig.
the class FacilityFacadeEjbTest method testGetAllWithoutRegionAfter.
@Test
public void testGetAllWithoutRegionAfter() throws InterruptedException {
FacilityDto facility = FacilityDto.build();
facility.setName("facility");
// only lab can be saved without region
facility.setType(FacilityType.LABORATORY);
getFacilityFacade().save(facility);
getFacilityService().doFlush();
Date date = new Date();
List<FacilityDto> results = getFacilityFacade().getAllWithoutRegionAfter(date);
// List should be empty
assertEquals(0, results.size());
// delay to ignore known rounding issues in change date filter
Thread.sleep(1);
String facilityName = "facility2";
facility = FacilityDto.build();
facility.setName(facilityName);
facility.setType(FacilityType.LABORATORY);
getFacilityFacade().save(facility);
results = getFacilityFacade().getAllWithoutRegionAfter(date);
// List should have one entry
assertEquals(1, results.size());
assertEquals(facilityName, results.get(0).getName());
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityDto in project SORMAS-Project by hzi-braunschweig.
the class CaseController method getCaseCreateComponent.
public CommitDiscardWrapperComponent<CaseCreateForm> getCaseCreateComponent(ContactDto convertedContact, EventParticipantDto convertedEventParticipant, TravelEntryDto convertedTravelEntry, Disease unrelatedDisease, boolean createdFromLabMessage) {
assert ((convertedContact == null && convertedEventParticipant == null) || (convertedContact == null && convertedTravelEntry == null) || (convertedEventParticipant == null && convertedTravelEntry == null));
assert (unrelatedDisease == null || (convertedEventParticipant == null && convertedTravelEntry == null));
CaseCreateForm createForm;
if (createdFromLabMessage) {
createForm = new CaseCreateForm(true, false, null);
} else {
createForm = convertedContact == null && convertedEventParticipant == null && convertedTravelEntry == null && unrelatedDisease == null ? new CaseCreateForm() : new CaseCreateForm(convertedTravelEntry);
}
CaseDataDto caze;
PersonDto person;
SymptomsDto symptoms;
if (convertedContact != null) {
VisitDto lastVisit = FacadeProvider.getVisitFacade().getLastVisitByContact(convertedContact.toReference());
if (lastVisit != null) {
symptoms = lastVisit.getSymptoms();
} else {
symptoms = null;
}
person = FacadeProvider.getPersonFacade().getPersonByUuid(convertedContact.getPerson().getUuid());
if (unrelatedDisease == null) {
caze = CaseDataDto.buildFromContact(convertedContact);
caze.getEpiData().setContactWithSourceCaseKnown(YesNoUnknown.YES);
} else {
caze = CaseDataDto.buildFromUnrelatedContact(convertedContact, unrelatedDisease);
}
} else if (convertedEventParticipant != null) {
EventDto event = FacadeProvider.getEventFacade().getEventByUuid(convertedEventParticipant.getEvent().getUuid(), false);
symptoms = null;
person = convertedEventParticipant.getPerson();
if (unrelatedDisease == null) {
caze = CaseDataDto.buildFromEventParticipant(convertedEventParticipant, person, event.getDisease());
} else {
caze = CaseDataDto.buildFromEventParticipant(convertedEventParticipant, person, unrelatedDisease);
}
} else if (convertedTravelEntry != null) {
symptoms = null;
person = FacadeProvider.getPersonFacade().getPersonByUuid(convertedTravelEntry.getPerson().getUuid());
caze = CaseDataDto.buildFromTravelEntry(convertedTravelEntry, person);
} else {
symptoms = null;
person = null;
caze = CaseDataDto.build(null, null);
}
UserDto user = UserProvider.getCurrent().getUser();
UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
caze.setReportingUser(userReference);
if (UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
caze.setResponsibleRegion(user.getRegion());
caze.setResponsibleDistrict(user.getDistrict());
caze.setCaseOrigin(CaseOrigin.POINT_OF_ENTRY);
caze.setDisease(Disease.UNDEFINED);
} else if (user.getHealthFacility() != null) {
FacilityDto healthFacility = FacadeProvider.getFacilityFacade().getByUuid(user.getHealthFacility().getUuid());
caze.setResponsibleRegion(healthFacility.getRegion());
caze.setResponsibleDistrict(healthFacility.getDistrict());
caze.setResponsibleCommunity(healthFacility.getCommunity());
caze.setHealthFacility(healthFacility.toReference());
} else if (convertedTravelEntry == null) {
caze.setResponsibleRegion(user.getRegion());
caze.setResponsibleDistrict(user.getDistrict());
caze.setResponsibleCommunity(user.getCommunity());
}
createForm.setValue(caze);
createForm.setPerson(person);
createForm.setSymptoms(symptoms);
if (convertedContact != null || convertedEventParticipant != null || convertedTravelEntry != null) {
createForm.setPersonalDetailsReadOnlyIfNotEmpty(true);
createForm.setDiseaseReadOnly(true);
}
final CommitDiscardWrapperComponent<CaseCreateForm> editView = new CommitDiscardWrapperComponent<CaseCreateForm>(createForm, UserProvider.getCurrent().hasUserRight(UserRight.CASE_CREATE), createForm.getFieldGroup());
if (createForm.getHomeAddressForm() != null) {
editView.addFieldGroups(createForm.getHomeAddressForm().getFieldGroup());
}
editView.addCommitListener(() -> {
if (!createForm.getFieldGroup().isModified()) {
final CaseDataDto dto = createForm.getValue();
if (dto.getHealthFacility() == null || FacilityDto.NONE_FACILITY_UUID.equals(dto.getHealthFacility().getUuid())) {
dto.setFacilityType(null);
}
if (convertedContact != null) {
int incubationPeriod = FacadeProvider.getDiseaseConfigurationFacade().getCaseFollowUpDuration(dto.getDisease());
List<VisitDto> visits = FacadeProvider.getVisitFacade().getVisitsByContactAndPeriod(convertedContact.toReference(), DateHelper.subtractDays(dto.getReportDate(), incubationPeriod), DateHelper.addDays(dto.getReportDate(), incubationPeriod));
for (VisitDto visit : visits) {
SymptomsHelper.updateSymptoms(visit.getSymptoms(), dto.getSymptoms());
}
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
dto.getSymptoms().setUuid(DataHelper.createUuid());
dto.getHealthConditions().setUuid(DataHelper.createUuid());
dto.getEpiData().setUuid(DataHelper.createUuid());
dto.getEpiData().getExposures().forEach(exposure -> {
exposure.setUuid(DataHelper.createUuid());
exposure.getLocation().setUuid(DataHelper.createUuid());
});
dto.setWasInQuarantineBeforeIsolation(YesNoUnknown.YES);
transferDataToPerson(createForm, person);
FacadeProvider.getPersonFacade().savePerson(person);
saveCase(dto);
// retrieve the contact just in case it has been changed during case saving
ContactDto updatedContact = FacadeProvider.getContactFacade().getByUuid(convertedContact.getUuid());
// automatically change the contact status to "converted"
updatedContact.setContactStatus(ContactStatus.CONVERTED);
// automatically change the contact classification to "confirmed"
updatedContact.setContactClassification(ContactClassification.CONFIRMED);
// set resulting case on contact and save it
updatedContact.setResultingCase(dto.toReference());
FacadeProvider.getContactFacade().save(updatedContact);
FacadeProvider.getCaseFacade().setSampleAssociations(updatedContact.toReference(), dto.toReference());
Notification.show(I18nProperties.getString(Strings.messageCaseCreated), Type.ASSISTIVE_NOTIFICATION);
if (!createdFromLabMessage) {
navigateToView(CaseDataView.VIEW_NAME, dto.getUuid(), null);
}
} else if (convertedEventParticipant != null) {
selectOrCreateCase(dto, convertedEventParticipant.getPerson(), uuid -> {
if (uuid == null) {
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
saveCase(dto);
// retrieve the event participant just in case it has been changed during case saving
EventParticipantDto updatedEventParticipant = FacadeProvider.getEventParticipantFacade().getEventParticipantByUuid(convertedEventParticipant.getUuid());
if (unrelatedDisease == null) {
// set resulting case on event participant and save it
updatedEventParticipant.setResultingCase(dto.toReference());
FacadeProvider.getEventParticipantFacade().saveEventParticipant(updatedEventParticipant);
FacadeProvider.getCaseFacade().setSampleAssociations(updatedEventParticipant.toReference(), dto.toReference());
} else {
FacadeProvider.getCaseFacade().setSampleAssociationsUnrelatedDisease(updatedEventParticipant.toReference(), dto.toReference());
}
if (!createdFromLabMessage) {
navigateToView(CaseDataView.VIEW_NAME, dto.getUuid(), null);
}
} else {
convertedEventParticipant.setResultingCase(FacadeProvider.getCaseFacade().getReferenceByUuid(uuid));
FacadeProvider.getEventParticipantFacade().saveEventParticipant(convertedEventParticipant);
if (!createdFromLabMessage) {
navigateToView(CaseDataView.VIEW_NAME, uuid, null);
}
}
});
} else if (convertedTravelEntry != null) {
transferDataToPerson(createForm, person);
FacadeProvider.getPersonFacade().savePerson(person);
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
saveCase(dto);
// retrieve the travel entry just in case it has been changed during case saving
TravelEntryDto updatedTravelEntry = FacadeProvider.getTravelEntryFacade().getByUuid(convertedTravelEntry.getUuid());
// set resulting case on travel entry and save it
updatedTravelEntry.setResultingCase(dto.toReference());
FacadeProvider.getTravelEntryFacade().save(updatedTravelEntry);
Notification.show(I18nProperties.getString(Strings.messageCaseCreated), Type.ASSISTIVE_NOTIFICATION);
if (!createdFromLabMessage) {
navigateToView(CaseDataView.VIEW_NAME, dto.getUuid(), null);
}
} else if (createdFromLabMessage) {
PersonDto dbPerson = FacadeProvider.getPersonFacade().getPersonByUuid(dto.getPerson().getUuid());
if (dbPerson == null) {
PersonDto personDto = PersonDto.build();
transferDataToPerson(createForm, personDto);
FacadeProvider.getPersonFacade().savePerson(personDto);
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
dto.setPerson(personDto.toReference());
saveCase(dto);
} else {
transferDataToPerson(createForm, dbPerson);
FacadeProvider.getPersonFacade().savePerson(dbPerson);
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
saveCase(dto);
}
} else {
PersonDto searchedPerson = createForm.getSearchedPerson();
if (searchedPerson != null) {
dto.setPerson(searchedPerson.toReference());
selectOrCreateCase(createForm, dto, searchedPerson.toReference());
} else {
// look for potential duplicate
final PersonDto duplicatePerson = PersonDto.build();
transferDataToPerson(createForm, duplicatePerson);
ControllerProvider.getPersonController().selectOrCreatePerson(duplicatePerson, I18nProperties.getString(Strings.infoSelectOrCreatePersonForCase), selectedPerson -> {
if (selectedPerson != null) {
dto.setPerson(selectedPerson);
selectOrCreateCase(createForm, dto, selectedPerson);
}
}, true);
}
}
}
});
return editView;
}
Aggregations