use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method postUpdate.
public CaseDataDto postUpdate(String uuid, JsonNode caseDataDtoJson) {
CaseDataDto existingCaseDto = getCaseDataWithoutPseudonyimization(uuid);
PatchHelper.postUpdate(caseDataDtoJson, existingCaseDto);
return this.save(existingCaseDto);
}
use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method restorePseudonymizedDto.
public void restorePseudonymizedDto(CaseDataDto dto, CaseDataDto existingCaseDto, Case caze, Pseudonymizer pseudonymizer) {
if (existingCaseDto != null) {
boolean inJurisdiction = service.inJurisdictionOrOwned(caze);
User currentUser = userService.getCurrentUser();
pseudonymizer.restoreUser(caze.getReportingUser(), currentUser, dto, dto::setReportingUser);
pseudonymizer.restoreUser(caze.getClassificationUser(), currentUser, dto, dto::setClassificationUser);
pseudonymizer.restorePseudonymizedValues(CaseDataDto.class, dto, existingCaseDto, inJurisdiction);
EpiDataDto epiData = dto.getEpiData();
EpiDataDto existingEpiData = existingCaseDto.getEpiData();
pseudonymizer.restorePseudonymizedValues(EpiDataDto.class, epiData, existingEpiData, inJurisdiction);
epiData.getExposures().forEach(exposure -> {
ExposureDto existingExposure = existingEpiData.getExposures().stream().filter(exp -> DataHelper.isSame(exposure, exp)).findFirst().orElse(null);
if (existingExposure != null) {
pseudonymizer.restorePseudonymizedValues(ExposureDto.class, exposure, existingExposure, inJurisdiction);
pseudonymizer.restorePseudonymizedValues(LocationDto.class, exposure.getLocation(), existingExposure.getLocation(), inJurisdiction);
}
});
pseudonymizer.restorePseudonymizedValues(HealthConditionsDto.class, dto.getHealthConditions(), existingCaseDto.getHealthConditions(), inJurisdiction);
dto.getHospitalization().getPreviousHospitalizations().forEach(previousHospitalization -> existingCaseDto.getHospitalization().getPreviousHospitalizations().stream().filter(eh -> DataHelper.isSame(previousHospitalization, eh)).findFirst().ifPresent(existingPreviousHospitalization -> pseudonymizer.restorePseudonymizedValues(PreviousHospitalizationDto.class, previousHospitalization, existingPreviousHospitalization, inJurisdiction)));
pseudonymizer.restorePseudonymizedValues(SymptomsDto.class, dto.getSymptoms(), existingCaseDto.getSymptoms(), inJurisdiction);
pseudonymizer.restorePseudonymizedValues(MaternalHistoryDto.class, dto.getMaternalHistory(), existingCaseDto.getMaternalHistory(), inJurisdiction);
}
}
use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method onCaseChanged.
public void onCaseChanged(CaseDataDto existingCase, Case newCase, boolean syncShares) {
// If its a new case and the case is new and the geo coordinates of the case's
// health facility are null, set its coordinates to the case's report
// coordinates, if available. Else if case report coordinates are null set them
// to the facility's coordinates
Facility facility = newCase.getHealthFacility();
if (existingCase == null && facility != null && !FacilityHelper.isOtherOrNoneHealthFacility(facility.getUuid())) {
if ((facility.getLatitude() == null || facility.getLongitude() == null) && newCase.getReportLat() != null && newCase.getReportLon() != null) {
facility.setLatitude(newCase.getReportLat());
facility.setLongitude(newCase.getReportLon());
facilityService.ensurePersisted(facility);
} else if (newCase.getReportLat() == null && newCase.getReportLon() == null && newCase.getReportLatLonAccuracy() == null) {
newCase.setReportLat(facility.getLatitude());
newCase.setReportLon(facility.getLongitude());
}
}
// Clear facility type if no facility or home was selected
if (newCase.getHealthFacility() == null || FacilityDto.NONE_FACILITY_UUID.equals(newCase.getHealthFacility().getUuid())) {
newCase.setFacilityType(null);
}
// Generate epid number if missing or incomplete
FieldVisibilityCheckers fieldVisibilityCheckers = FieldVisibilityCheckers.withCountry(configFacade.getCountryLocale());
if (fieldVisibilityCheckers.isVisible(CaseDataDto.class, CaseDataDto.EPID_NUMBER) && !CaseLogic.isCompleteEpidNumber(newCase.getEpidNumber())) {
newCase.setEpidNumber(generateEpidNumber(newCase.getEpidNumber(), newCase.getUuid(), newCase.getDisease(), newCase.getReportDate(), newCase.getResponsibleDistrict().getUuid()));
}
// update the plague type based on symptoms
if (newCase.getDisease() == Disease.PLAGUE) {
PlagueType plagueType = DiseaseHelper.getPlagueTypeForSymptoms(SymptomsFacadeEjb.toDto(newCase.getSymptoms()));
if (plagueType != newCase.getPlagueType() && plagueType != null) {
newCase.setPlagueType(plagueType);
}
}
District survOffDistrict = newCase.getSurveillanceOfficer() != null ? newCase.getSurveillanceOfficer().getDistrict() : null;
if (survOffDistrict == null || (!survOffDistrict.equals(newCase.getResponsibleDistrict()) && !survOffDistrict.equals(newCase.getDistrict()))) {
setResponsibleSurveillanceOfficer(newCase);
}
updateInvestigationByStatus(existingCase, newCase);
updatePersonAndCaseByOutcome(existingCase, newCase);
updateCaseAge(existingCase, newCase);
// Change the disease of all contacts if the case disease or disease details have changed
if (existingCase != null && (newCase.getDisease() != existingCase.getDisease() || !StringUtils.equals(newCase.getDiseaseDetails(), existingCase.getDiseaseDetails()))) {
for (Contact contact : contactService.findBy(new ContactCriteria().caze(newCase.toReference()), null)) {
if (contact.getDisease() != newCase.getDisease() || !StringUtils.equals(contact.getDiseaseDetails(), newCase.getDiseaseDetails())) {
// Only do the change if it hasn't been done in the mobile app before
contact.setDisease(newCase.getDisease());
contact.setDiseaseDetails(newCase.getDiseaseDetails());
contactService.ensurePersisted(contact);
}
}
}
if (existingCase != null && (newCase.getDisease() != existingCase.getDisease() || !Objects.equals(newCase.getReportDate(), existingCase.getReportDate()) || !Objects.equals(newCase.getSymptoms().getOnsetDate(), existingCase.getSymptoms().getOnsetDate()))) {
// Update follow-up until and status of all contacts
for (Contact contact : contactService.findBy(new ContactCriteria().caze(newCase.toReference()), null)) {
contactService.updateFollowUpDetails(contact, false);
contactService.udpateContactStatus(contact);
}
for (Contact contact : contactService.getAllByResultingCase(newCase)) {
contactService.updateFollowUpDetails(contact, false);
contactService.udpateContactStatus(contact);
}
}
updateTasksOnCaseChanged(newCase, existingCase);
// Update case classification if the feature is enabled
CaseClassification classification = null;
if (configFacade.isFeatureAutomaticCaseClassification()) {
if (newCase.getCaseClassification() != CaseClassification.NO_CASE) {
// calculate classification
CaseDataDto newCaseDto = toDto(newCase);
classification = caseClassificationFacade.getClassification(newCaseDto);
// only update when classification by system changes - user may overwrite this
if (classification != newCase.getSystemCaseClassification()) {
newCase.setSystemCaseClassification(classification);
// really a change? (user may have already set it)
if (classification != newCase.getCaseClassification()) {
newCase.setCaseClassification(classification);
newCase.setClassificationUser(null);
newCase.setClassificationDate(new Date());
}
}
}
}
// calculate reference definition for cases
if (configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) {
boolean fulfilled = evaluateFulfilledCondition(toDto(newCase), classification);
newCase.setCaseReferenceDefinition(fulfilled ? CaseReferenceDefinition.FULFILLED : CaseReferenceDefinition.NOT_FULFILLED);
}
// are not empty
if (!newCase.getHospitalization().getPreviousHospitalizations().isEmpty() && YesNoUnknown.YES != newCase.getHospitalization().getHospitalizedPreviously()) {
newCase.getHospitalization().setHospitalizedPreviously(YesNoUnknown.YES);
}
if (!newCase.getEpiData().getExposures().isEmpty() && !YesNoUnknown.YES.equals(newCase.getEpiData().getExposureDetailsKnown())) {
newCase.getEpiData().setExposureDetailsKnown(YesNoUnknown.YES);
}
// Update completeness value
newCase.setCompleteness(null);
// changed
if (existingCase != null && existingCase.getCaseClassification() != newCase.getCaseClassification()) {
try {
String message = String.format(I18nProperties.getString(MessageContents.CONTENT_CASE_CLASSIFICATION_CHANGED), DataHelper.getShortUuid(newCase.getUuid()), newCase.getCaseClassification().toString());
notificationService.sendNotifications(NotificationType.CASE_CLASSIFICATION_CHANGED, JurisdictionHelper.getCaseRegions(newCase), null, MessageSubject.CASE_CLASSIFICATION_CHANGED, message);
} catch (NotificationDeliveryFailedException e) {
logger.error("NotificationDeliveryFailedException when trying to notify supervisors about the change of a case classification. ");
}
}
// Unspecified VHF case has changed
if (existingCase != null && existingCase.getDisease() == Disease.UNSPECIFIED_VHF && existingCase.getDisease() != newCase.getDisease()) {
try {
String message = String.format(I18nProperties.getString(MessageContents.CONTENT_DISEASE_CHANGED), DataHelper.getShortUuid(newCase.getUuid()), existingCase.getDisease().toString(), newCase.getDisease().toString());
notificationService.sendNotifications(NotificationType.DISEASE_CHANGED, JurisdictionHelper.getCaseRegions(newCase), null, MessageSubject.DISEASE_CHANGED, message);
} catch (NotificationDeliveryFailedException e) {
logger.error("NotificationDeliveryFailedException when trying to notify supervisors about the change of a case disease.");
}
}
// If the case is a newly created case or if it was not in a CONFIRMED status
// and now the case is in a CONFIRMED status, notify related surveillance officers
Set<CaseClassification> confirmedClassifications = CaseClassification.getConfirmedClassifications();
if ((existingCase == null || !confirmedClassifications.contains(existingCase.getCaseClassification())) && confirmedClassifications.contains(newCase.getCaseClassification())) {
sendConfirmedCaseNotificationsForEvents(newCase);
}
if (existingCase != null && syncShares && sormasToSormasFacade.isFeatureConfigured()) {
syncSharesAsync(new ShareTreeCriteria(existingCase.getUuid()));
}
// This logic should be consistent with CaseDataForm.onQuarantineEndChange
if (existingCase != null && existingCase.getQuarantineTo() != null && !existingCase.getQuarantineTo().equals(newCase.getQuarantineTo())) {
newCase.setPreviousQuarantineTo(existingCase.getQuarantineTo());
}
if (existingCase == null) {
vaccinationFacade.updateVaccinationStatuses(newCase);
}
// On German systems, correct and clean up reinfection data
if (configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) {
newCase.setReinfectionDetails(cleanUpReinfectionDetails(newCase.getReinfectionDetails()));
newCase.setReinfectionStatus(CaseLogic.calculateReinfectionStatus(newCase.getReinfectionDetails()));
}
}
use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class CaseImportFacadeEjb method saveImportedEntities.
@Override
public ImportLineResultDto<CaseImportEntities> saveImportedEntities(@Valid CaseImportEntities entities, boolean skipPersonValidation) {
CaseDataDto caze = entities.getCaze();
PersonDto person = entities.getPerson();
List<SampleDto> samples = entities.getSamples();
List<PathogenTestDto> pathogenTests = entities.getPathogenTests();
List<VaccinationDto> vaccinations = entities.getVaccinations();
try {
// Necessary to make sure that the follow-up information is retained
if (featureConfigurationFacade.isFeatureEnabled(FeatureType.CASE_FOLLOWUP) && caze.getFollowUpStatus() == null) {
caze.setFollowUpStatus(FollowUpStatus.FOLLOW_UP);
}
if (caze.getEpidNumber() != null && caseFacade.doesEpidNumberExist(caze.getEpidNumber(), caze.getUuid(), caze.getDisease())) {
return ImportLineResultDto.errorResult(I18nProperties.getString(Strings.messageEpidNumberWarning));
}
// PersonDto savedPerson = personFacade.savePerson(person);
final PersonDto savedPerson = personFacade.savePerson(person, skipPersonValidation);
caze.setPerson(savedPerson.toReference());
// Workaround: Reset the change date to avoid OutdatedEntityExceptions
// Should be changed when doing #2265
caze.setChangeDate(new Date());
caseFacade.save(caze);
for (SampleDto sample : samples) {
sampleFacade.saveSample(sample);
}
for (PathogenTestDto pathogenTest : pathogenTests) {
pathogenTestFacade.savePathogenTest(pathogenTest);
}
for (VaccinationDto vaccination : vaccinations) {
vaccinationFacade.createWithImmunization(vaccination, caze.getResponsibleRegion(), caze.getResponsibleDistrict(), caze.getPerson(), caze.getDisease());
}
return ImportLineResultDto.successResult();
} catch (ValidationRuntimeException e) {
return ImportLineResultDto.errorResult(e.getMessage());
}
}
use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjbTest method testGetAllActiveCasesIncludeExtendedChangeDateFiltersPathogenTest.
@Test
public void testGetAllActiveCasesIncludeExtendedChangeDateFiltersPathogenTest() throws InterruptedException {
RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
SampleDto sample = creator.createSample(caze.toReference(), user.toReference(), rdcf.facility);
PathogenTestDto pathogenTestDto = creator.createPathogenTest(sample.toReference(), caze);
Date date = new Date();
// the delay is needed in order to ensure the time difference between the date and the case dependent objects update
Thread.sleep(10L);
pathogenTestDto.setTestResultText("test result changed");
getPathogenTestFacade().savePathogenTest(pathogenTestDto);
assertEquals(0, getCaseFacade().getAllActiveCasesAfter(date).size());
assertEquals(1, getCaseFacade().getAllActiveCasesAfter(date, true).size());
}
Aggregations