use of de.symeda.sormas.api.Disease in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationDataForm method addFields.
@SuppressWarnings("deprecation")
@Override
protected void addFields() {
TextField immunizationUuuidField = addField(ImmunizationDto.UUID, TextField.class);
immunizationUuuidField.setReadOnly(true);
TextField externalIdField = addField(ImmunizationDto.EXTERNAL_ID, TextField.class);
style(externalIdField, ERROR_COLOR_PRIMARY);
addField(ImmunizationDto.REPORT_DATE, DateField.class);
addField(ImmunizationDto.REPORTING_USER, ComboBox.class);
ComboBox cbDisease = addDiseaseField(ImmunizationDto.DISEASE, false);
addField(ImmunizationDto.DISEASE_DETAILS, TextField.class);
ComboBox meansOfImmunizationField = addField(ImmunizationDto.MEANS_OF_IMMUNIZATION, ComboBox.class);
addField(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS, TextField.class);
overwriteImmunizationManagementStatus = addCustomField(OVERWRITE_IMMUNIZATION_MANAGEMENT_STATUS, Boolean.class, CheckBox.class);
overwriteImmunizationManagementStatus.addStyleName(VSPACE_3);
ComboBox managementStatusField = addField(ImmunizationDto.IMMUNIZATION_MANAGEMENT_STATUS, ComboBox.class);
managementStatusField.setNullSelectionAllowed(false);
managementStatusField.setEnabled(false);
ComboBox immunizationStatusField = addField(ImmunizationDto.IMMUNIZATION_STATUS, ComboBox.class);
immunizationStatusField.setEnabled(false);
addField(ImmunizationDto.PREVIOUS_INFECTION, NullableOptionGroup.class);
addField(ImmunizationDto.LAST_INFECTION_DATE, DateField.class);
ComboBox country = addInfrastructureField(ImmunizationDto.COUNTRY);
country.addItems(FacadeProvider.getCountryFacade().getAllActiveAsReference());
TextArea descriptionField = addField(ImmunizationDto.ADDITIONAL_DETAILS, TextArea.class, new ResizableTextAreaWrapper<>());
descriptionField.setRows(2);
descriptionField.setDescription(I18nProperties.getPrefixDescription(ImmunizationDto.I18N_PREFIX, ImmunizationDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingResponsibleJurisdiction));
jurisdictionHeadingLabel.addStyleName(H3);
getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
ComboBox responsibleRegion = addInfrastructureField(ImmunizationDto.RESPONSIBLE_REGION);
responsibleRegion.setRequired(true);
ComboBox responsibleDistrictCombo = addInfrastructureField(ImmunizationDto.RESPONSIBLE_DISTRICT);
responsibleDistrictCombo.setRequired(true);
ComboBox responsibleCommunityCombo = addInfrastructureField(ImmunizationDto.RESPONSIBLE_COMMUNITY);
responsibleCommunityCombo.setNullSelectionAllowed(true);
responsibleCommunityCombo.addStyleName(SOFT_REQUIRED);
InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrictCombo, responsibleCommunityCombo);
facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
facilityTypeGroup.setId("typeGroup");
facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
facilityTypeGroup.addItems(FacilityTypeGroup.values());
getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
ComboBox facilityType = addField(ImmunizationDto.FACILITY_TYPE);
ComboBox facilityCombo = addInfrastructureField(ImmunizationDto.HEALTH_FACILITY);
facilityCombo.setImmediate(true);
TextField facilityDetails = addField(ImmunizationDto.HEALTH_FACILITY_DETAILS, TextField.class);
facilityDetails.setVisible(false);
DateField startDate = addField(ImmunizationDto.START_DATE, DateField.class);
DateField endDate = addDateField(ImmunizationDto.END_DATE, DateField.class, -1);
DateComparisonValidator.addStartEndValidators(startDate, endDate);
DateField validFrom = addDateField(ImmunizationDto.VALID_FROM, DateField.class, -1);
DateField validUntil = addDateField(ImmunizationDto.VALID_UNTIL, DateField.class, -1);
DateComparisonValidator.addStartEndValidators(validFrom, validUntil);
MeansOfImmunization meansOfImmunizationValue = (MeansOfImmunization) meansOfImmunizationField.getValue();
boolean isVaccinationVisibleInitial = shouldShowVaccinationFields(meansOfImmunizationValue);
Label vaccinationHeadingLabel = new Label(I18nProperties.getString(Strings.headingVaccination));
vaccinationHeadingLabel.addStyleName(H3);
getContent().addComponent(vaccinationHeadingLabel, VACCINATION_HEADING_LOC);
vaccinationHeadingLabel.setVisible(isVaccinationVisibleInitial);
Field numberOfDosesField = addField(ImmunizationDto.NUMBER_OF_DOSES);
numberOfDosesField.addValidator(new NumberValidator(I18nProperties.getValidationError(Validations.vaccineDosesFormat), 1, 10, false));
numberOfDosesField.setVisible(isVaccinationVisibleInitial);
Field numberOfDosesDetailsField = addField(ImmunizationDto.NUMBER_OF_DOSES_DETAILS);
numberOfDosesDetailsField.setReadOnly(true);
numberOfDosesDetailsField.setVisible(isVaccinationVisibleInitial && getValue().getNumberOfDosesDetails() != null);
VaccinationsField vaccinationsField = addField(ImmunizationDto.VACCINATIONS, VaccinationsField.class);
FieldHelper.setVisibleWhen(getFieldGroup(), ImmunizationDto.VACCINATIONS, ImmunizationDto.MEANS_OF_IMMUNIZATION, Arrays.asList(MeansOfImmunization.VACCINATION, MeansOfImmunization.VACCINATION_RECOVERY), false);
cbDisease.addValueChangeListener(e -> vaccinationsField.setDisease((Disease) cbDisease.getValue()));
Label recoveryHeadingLabel = new Label(I18nProperties.getString(Strings.headingRecovery));
recoveryHeadingLabel.addStyleName(H3);
getContent().addComponent(recoveryHeadingLabel, RECOVERY_HEADING_LOC);
recoveryHeadingLabel.setVisible(shouldShowRecoveryFields(meansOfImmunizationValue));
DateField positiveTestResultDate = addField(ImmunizationDto.POSITIVE_TEST_RESULT_DATE, DateField.class);
DateField recoveryDate = addField(ImmunizationDto.RECOVERY_DATE, DateField.class);
Button linkImmunizationToCaseButton;
if (relatedCase != null) {
linkImmunizationToCaseButton = ButtonHelper.createButton(Captions.openLinkedCaseToImmunizationButton, e -> ControllerProvider.getCaseController().navigateToCase(relatedCase.getUuid()), ValoTheme.BUTTON_PRIMARY, FORCE_CAPTION);
} else {
linkImmunizationToCaseButton = ButtonHelper.createButton(Captions.linkImmunizationToCaseButton, e -> buildAndOpenSearchSpecificCaseWindow(), ValoTheme.BUTTON_PRIMARY, FORCE_CAPTION);
}
getContent().addComponent(linkImmunizationToCaseButton, LINK_IMMUNIZATION_TO_CASE_BTN_LOC);
linkImmunizationToCaseButton.setVisible(shouldShowRecoveryFields(meansOfImmunizationValue));
// Set initial visibilities & accesses
initializeVisibilitiesAndAllowedVisibilities();
setRequired(true, ImmunizationDto.REPORT_DATE, ImmunizationDto.DISEASE, ImmunizationDto.MEANS_OF_IMMUNIZATION);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(ImmunizationDto.DISEASE_DETAILS), ImmunizationDto.DISEASE, Arrays.asList(Disease.OTHER), true);
FieldHelper.setRequiredWhen(getFieldGroup(), ImmunizationDto.DISEASE, Arrays.asList(ImmunizationDto.DISEASE_DETAILS), Arrays.asList(Disease.OTHER));
FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS), ImmunizationDto.MEANS_OF_IMMUNIZATION, Collections.singletonList(MeansOfImmunization.OTHER), true);
overwriteImmunizationManagementStatus.addValueChangeListener(valueChangeEvent -> {
boolean selectedValue = (boolean) valueChangeEvent.getProperty().getValue();
if (!selectedValue) {
ImmunizationManagementStatus value = getValue().getImmunizationManagementStatus();
managementStatusField.setValue(value);
}
managementStatusField.setEnabled(selectedValue);
ignoreMeansOfImmunizationChange = selectedValue;
});
meansOfImmunizationField.addValueChangeListener(valueChangeEvent -> {
MeansOfImmunization meansOfImmunization = (MeansOfImmunization) valueChangeEvent.getProperty().getValue();
boolean isVaccinationVisible = shouldShowVaccinationFields(meansOfImmunization);
boolean isRecoveryVisible = shouldShowRecoveryFields(meansOfImmunization);
if (!ignoreMeansOfImmunizationChange) {
if (MeansOfImmunization.RECOVERY.equals(meansOfImmunization) || MeansOfImmunization.OTHER.equals(meansOfImmunization)) {
managementStatusField.setValue(ImmunizationManagementStatus.COMPLETED);
if (CollectionUtils.isNotEmpty(vaccinationsField.getValue())) {
VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingDeleteVaccinations), new Label(I18nProperties.getString(Strings.messageDeleteImmunizationVaccinations)), questionWindow -> {
ConfirmationComponent confirmationComponent = new ConfirmationComponent(false) {
private static final long serialVersionUID = 1L;
@Override
protected void onConfirm() {
vaccinationsField.clear();
previousMeansOfImmunization = meansOfImmunization;
if (!isVaccinationVisible) {
numberOfDosesField.setValue(null);
}
questionWindow.close();
}
@Override
protected void onCancel() {
ignoreMeansOfImmunizationChange = true;
meansOfImmunizationField.setValue(previousMeansOfImmunization);
ignoreMeansOfImmunizationChange = false;
questionWindow.close();
}
};
confirmationComponent.getConfirmButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
confirmationComponent.getCancelButton().setCaption(I18nProperties.getCaption(Captions.actionCancel));
return confirmationComponent;
}, null);
} else {
previousMeansOfImmunization = meansOfImmunization;
}
} else {
previousMeansOfImmunization = meansOfImmunization;
}
}
vaccinationHeadingLabel.setVisible(isVaccinationVisible);
numberOfDosesField.setVisible(isVaccinationVisible);
numberOfDosesDetailsField.setVisible(isVaccinationVisible && getValue().getNumberOfDosesDetails() != null);
recoveryHeadingLabel.setVisible(isRecoveryVisible);
positiveTestResultDate.setVisible(isRecoveryVisible);
recoveryDate.setVisible(isRecoveryVisible);
});
managementStatusField.addValueChangeListener(valueChangeEvent -> {
ImmunizationManagementStatus managementStatusValue = (ImmunizationManagementStatus) valueChangeEvent.getProperty().getValue();
switch(managementStatusValue) {
case SCHEDULED:
case ONGOING:
immunizationStatusField.setValue(ImmunizationStatus.PENDING);
break;
case COMPLETED:
immunizationStatusField.setValue(ImmunizationStatus.ACQUIRED);
break;
case CANCELED:
immunizationStatusField.setValue(ImmunizationStatus.NOT_ACQUIRED);
break;
default:
break;
}
});
setReadOnly(true, ImmunizationDto.REPORTING_USER);
FieldHelper.setVisibleWhen(getFieldGroup(), ImmunizationDto.LAST_INFECTION_DATE, ImmunizationDto.PREVIOUS_INFECTION, Collections.singletonList(YesNoUnknown.YES), true);
meansOfImmunizationField.addValueChangeListener(e -> {
if (shouldShowRecoveryFields((MeansOfImmunization) e.getProperty().getValue())) {
positiveTestResultDate.setVisible(true);
recoveryDate.setVisible(true);
linkImmunizationToCaseButton.setVisible(true);
} else {
positiveTestResultDate.setVisible(false);
recoveryDate.setVisible(false);
linkImmunizationToCaseButton.setVisible(false);
}
});
responsibleDistrictCombo.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
if (districtDto != null && facilityType.getValue() != null) {
FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
}
});
responsibleCommunityCombo.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
if (facilityType.getValue() != null) {
FieldHelper.updateItems(facilityCombo, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, false) : responsibleDistrictCombo.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) responsibleDistrictCombo.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
}
});
facilityTypeGroup.addValueChangeListener(e -> {
if (facilityTypeGroup.getValue() == null) {
facilityType.clear();
}
FieldHelper.updateEnumData(facilityType, facilityTypeGroup.getValue() != null ? FacilityType.getTypes((FacilityTypeGroup) facilityTypeGroup.getValue()) : Arrays.stream(FacilityType.values()).collect(Collectors.toList()));
});
facilityType.addValueChangeListener(e -> {
FieldHelper.removeItems(facilityCombo);
if (facilityType.getValue() != null && responsibleDistrictCombo.getValue() != null) {
if (responsibleCommunityCombo.getValue() != null) {
FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType((CommunityReferenceDto) responsibleCommunityCombo.getValue(), (FacilityType) facilityType.getValue(), true, false));
} else {
FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) responsibleDistrictCombo.getValue(), (FacilityType) facilityType.getValue(), true, false));
}
}
});
facilityCombo.addValueChangeListener(e -> {
updateFacilityFields(facilityCombo, facilityDetails);
});
addValueChangeListener(e -> {
FacilityType facilityTypeValue = getValue().getFacilityType();
if (facilityTypeValue != null) {
facilityTypeGroup.setValue(facilityTypeValue.getFacilityTypeGroup());
facilityCombo.setValue(getValue().getHealthFacility());
facilityDetails.setValue(getValue().getHealthFacilityDetails());
}
});
}
use of de.symeda.sormas.api.Disease in project SORMAS-Project by hzi-braunschweig.
the class EventsFilterForm method applyDependenciesOnNewValue.
@Override
protected void applyDependenciesOnNewValue(EventCriteria criteria) {
applyDateDependencyOnNewValue(EVENT_WEEK_AND_DATE_FILTER, criteria.getDateFilterOption(), criteria.getEventDateFrom(), criteria.getEventDateTo());
applyDateDependencyOnNewValue(EVENT_SIGNAL_EVOLUTION_WEEK_AND_DATE_FILTER, criteria.getEvolutionDateFilterOption(), criteria.getEventEvolutionDateFrom(), criteria.getEventEvolutionDateTo());
applyDateDependencyOnNewValue(ACTION_CHANGE_WEEK_AND_DATE_FILTER, criteria.getActionChangeDateFilterOption(), criteria.getActionChangeDateFrom(), criteria.getActionChangeDateTo());
applyDateDependencyOnNewValue(ACTION_WEEK_AND_DATE_FILTER, criteria.getActionDateFilterOption(), criteria.getActionDateFrom(), criteria.getActionDateTo());
RegionReferenceDto region = criteria.getRegion();
DistrictReferenceDto district = criteria.getDistrict();
applyRegionAndDistrictFilterDependency(region, LocationDto.DISTRICT, district, LocationDto.COMMUNITY);
applyFacilityFieldsDependencies(criteria.getTypeOfPlace(), criteria.getDistrict(), criteria.getCommunity());
updateResponsibleUserFieldItems(criteria.getDistrict(), criteria.getRegion());
ComboBox diseaseField = getField(CaseDataDto.DISEASE);
Disease disease = (Disease) diseaseField.getValue();
applyDiseaseFilterDependency(disease);
}
use of de.symeda.sormas.api.Disease in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method getCaseMeasurePerDistrict.
@Override
public List<Pair<DistrictDto, BigDecimal>> getCaseMeasurePerDistrict(Date fromDate, Date toDate, Disease disease, CaseMeasure caseMeasure) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<Case> caseRoot = cq.from(Case.class);
Root<District> districtRoot = cq.from(District.class);
Predicate filter = service.createDefaultFilter(cb, caseRoot);
if (fromDate != null || toDate != null) {
filter = service.createCaseRelevanceFilter(cb, caseRoot, fromDate, toDate);
}
if (disease != null) {
Predicate diseaseFilter = cb.equal(caseRoot.get(Case.DISEASE), disease);
filter = filter != null ? cb.and(filter, diseaseFilter) : diseaseFilter;
}
Predicate districtFilter = cb.or(cb.equal(caseRoot.get(Case.DISTRICT), districtRoot), cb.and(cb.isNull(caseRoot.get(Case.DISTRICT)), cb.equal(caseRoot.get(Case.RESPONSIBLE_DISTRICT), districtRoot)));
filter = filter != null ? cb.and(filter, districtFilter) : districtFilter;
cq.where(filter);
cq.groupBy(districtRoot);
cq.multiselect(districtRoot, cb.count(caseRoot));
if (caseMeasure == CaseMeasure.CASE_COUNT) {
cq.orderBy(cb.asc(cb.count(caseRoot)));
}
List<Object[]> results = em.createQuery(cq).getResultList();
if (caseMeasure == CaseMeasure.CASE_COUNT) {
List<Pair<DistrictDto, BigDecimal>> resultList = results.stream().map(e -> new Pair<DistrictDto, BigDecimal>(districtFacade.toDto((District) e[0]), new BigDecimal((Long) e[1]))).collect(Collectors.toList());
return resultList;
} else {
List<Pair<DistrictDto, BigDecimal>> resultList = results.stream().map(e -> {
District district = (District) e[0];
Integer population = populationDataFacade.getProjectedDistrictPopulation(district.getUuid());
Long caseCount = (Long) e[1];
if (population == null || population <= 0) {
// No or negative population - these entries will be cut off in the UI
return new Pair<DistrictDto, BigDecimal>(districtFacade.toDto(district), new BigDecimal(0));
} else {
return new Pair<DistrictDto, BigDecimal>(districtFacade.toDto(district), InfrastructureHelper.getCaseIncidence(caseCount.intValue(), population, InfrastructureHelper.CASE_INCIDENCE_DIVISOR));
}
}).sorted(new Comparator<Pair<DistrictDto, BigDecimal>>() {
@Override
public int compare(Pair<DistrictDto, BigDecimal> o1, Pair<DistrictDto, BigDecimal> o2) {
return o1.getElement1().compareTo(o2.getElement1());
}
}).collect(Collectors.toList());
return resultList;
}
}
use of de.symeda.sormas.api.Disease in project SORMAS-Project by hzi-braunschweig.
the class CaseService method getCasesForDuplicateMerging.
public List<CaseIndexDto[]> getCasesForDuplicateMerging(CaseCriteria criteria, boolean ignoreRegion, double nameSimilarityThreshold) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<Case> root = cq.from(Case.class);
final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, root);
final CaseJoins<Case> joins = (CaseJoins<Case>) caseQueryContext.getJoins();
Root<Case> root2 = cq.from(Case.class);
Join<Case, Person> person = joins.getPerson();
Join<Case, Person> person2 = root2.join(Case.PERSON, JoinType.LEFT);
Join<Case, Region> responsibleRegion = joins.getResponsibleRegion();
Join<Case, Region> responsibleRegion2 = root2.join(Case.RESPONSIBLE_REGION, JoinType.LEFT);
Join<Case, Region> region = joins.getRegion();
Join<Case, Region> region2 = root2.join(Case.REGION, JoinType.LEFT);
Join<Case, Symptoms> symptoms = joins.getSymptoms();
Join<Case, Symptoms> symptoms2 = root2.join(Case.SYMPTOMS, JoinType.LEFT);
cq.distinct(true);
// similarity:
// * first & last name concatenated with whitespace. Similarity function with default threshold of 0.65D
// uses postgres pg_trgm: https://www.postgresql.org/docs/9.6/pgtrgm.html
// * same disease
// * same region (optional)
// * report date within 30 days of each other
// * same sex or same birth date (when defined)
// * same birth date (when fully defined)
// * onset date within 30 days of each other (when defined)
Predicate userFilter = createUserFilter(cb, cq, root);
Predicate criteriaFilter = criteria != null ? createCriteriaFilter(criteria, caseQueryContext) : null;
Expression<String> nameSimilarityExpr = cb.concat(person.get(Person.FIRST_NAME), " ");
nameSimilarityExpr = cb.concat(nameSimilarityExpr, person.get(Person.LAST_NAME));
Expression<String> nameSimilarityExpr2 = cb.concat(person2.get(Person.FIRST_NAME), " ");
nameSimilarityExpr2 = cb.concat(nameSimilarityExpr2, person2.get(Person.LAST_NAME));
Predicate nameSimilarityFilter = cb.gt(cb.function("similarity", double.class, nameSimilarityExpr, nameSimilarityExpr2), nameSimilarityThreshold);
Predicate diseaseFilter = cb.equal(root.get(Case.DISEASE), root2.get(Case.DISEASE));
Predicate regionFilter = cb.and(cb.equal(responsibleRegion.get(Region.ID), responsibleRegion2.get(Region.ID)), cb.or(cb.and(cb.isNull(region)), cb.equal(region.get(Region.ID), region2.get(Region.ID))));
Predicate reportDateFilter = cb.lessThanOrEqualTo(cb.abs(cb.diff(cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), root.get(Case.REPORT_DATE)), cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), root2.get(Case.REPORT_DATE)))), SECONDS_30_DAYS);
// // todo this should use PersonService.buildSimilarityCriteriaFilter
// Sex filter: only when sex is filled in for both cases
Predicate sexFilter = cb.or(cb.or(cb.isNull(person.get(Person.SEX)), cb.isNull(person2.get(Person.SEX))), cb.or(cb.equal(person.get(Person.SEX), Sex.UNKNOWN), cb.equal(person2.get(Person.SEX), Sex.UNKNOWN)), cb.equal(person.get(Person.SEX), person2.get(Person.SEX)));
// Birth date filter: only when birth date is filled in for both cases
Predicate birthDateFilter = cb.or(cb.or(cb.isNull(person.get(Person.BIRTHDATE_DD)), cb.isNull(person.get(Person.BIRTHDATE_MM)), cb.isNull(person.get(Person.BIRTHDATE_YYYY)), cb.isNull(person2.get(Person.BIRTHDATE_DD)), cb.isNull(person2.get(Person.BIRTHDATE_MM)), cb.isNull(person2.get(Person.BIRTHDATE_YYYY))), cb.and(cb.equal(person.get(Person.BIRTHDATE_DD), person2.get(Person.BIRTHDATE_DD)), cb.equal(person.get(Person.BIRTHDATE_MM), person2.get(Person.BIRTHDATE_MM)), cb.equal(person.get(Person.BIRTHDATE_YYYY), person2.get(Person.BIRTHDATE_YYYY))));
// Onset date filter: only when onset date is filled in for both cases
Predicate onsetDateFilter = cb.or(cb.or(cb.isNull(symptoms.get(Symptoms.ONSET_DATE)), cb.isNull(symptoms2.get(Symptoms.ONSET_DATE))), cb.lessThanOrEqualTo(cb.abs(cb.diff(cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), symptoms.get(Symptoms.ONSET_DATE)), cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), symptoms2.get(Symptoms.ONSET_DATE)))), SECONDS_30_DAYS));
Predicate creationDateFilter = cb.or(cb.lessThan(root.get(Case.CREATION_DATE), root2.get(Case.CREATION_DATE)), cb.or(cb.lessThanOrEqualTo(root2.get(Case.CREATION_DATE), DateHelper.getStartOfDay(criteria.getCreationDateFrom())), cb.greaterThanOrEqualTo(root2.get(Case.CREATION_DATE), DateHelper.getEndOfDay(criteria.getCreationDateTo()))));
Predicate filter = cb.and(createDefaultFilter(cb, root), createDefaultFilter(cb, root2));
if (userFilter != null) {
filter = cb.and(filter, userFilter);
}
if (filter != null) {
filter = cb.and(filter, criteriaFilter);
} else {
filter = criteriaFilter;
}
if (filter != null) {
filter = cb.and(filter, nameSimilarityFilter);
} else {
filter = nameSimilarityFilter;
}
filter = cb.and(filter, diseaseFilter);
if (!ignoreRegion) {
filter = cb.and(filter, regionFilter);
}
filter = cb.and(filter, reportDateFilter);
filter = cb.and(filter, cb.and(sexFilter, birthDateFilter));
filter = cb.and(filter, onsetDateFilter);
filter = cb.and(filter, creationDateFilter);
filter = cb.and(filter, cb.notEqual(root.get(Case.ID), root2.get(Case.ID)));
cq.where(filter);
cq.multiselect(root.get(Case.ID), root2.get(Case.ID), root.get(Case.CREATION_DATE));
cq.orderBy(cb.desc(root.get(Case.CREATION_DATE)));
List<Object[]> foundIds = em.createQuery(cq).setParameter("date_type", "epoch").getResultList();
List<CaseIndexDto[]> resultList = new ArrayList<>();
if (!foundIds.isEmpty()) {
CriteriaQuery<CaseIndexDto> indexCasesCq = cb.createQuery(CaseIndexDto.class);
Root<Case> indexRoot = indexCasesCq.from(Case.class);
selectIndexDtoFields(new CaseQueryContext(cb, indexCasesCq, indexRoot));
indexCasesCq.where(indexRoot.get(Case.ID).in(foundIds.stream().map(a -> Arrays.copyOf(a, 2)).flatMap(Arrays::stream).collect(Collectors.toSet())));
Map<Long, CaseIndexDto> indexCases = em.createQuery(indexCasesCq).getResultStream().collect(Collectors.toMap(c -> c.getId(), Function.identity()));
for (Object[] idPair : foundIds) {
try {
// Cloning is necessary here to allow us to add the same CaseIndexDto to the grid multiple times
CaseIndexDto parent = (CaseIndexDto) indexCases.get(idPair[0]).clone();
CaseIndexDto child = (CaseIndexDto) indexCases.get(idPair[1]).clone();
if (parent.getCompleteness() == null && child.getCompleteness() == null || parent.getCompleteness() != null && (child.getCompleteness() == null || (parent.getCompleteness() >= child.getCompleteness()))) {
resultList.add(new CaseIndexDto[] { parent, child });
} else {
resultList.add(new CaseIndexDto[] { child, parent });
}
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
}
return resultList;
}
use of de.symeda.sormas.api.Disease in project SORMAS-Project by hzi-braunschweig.
the class CasePartialUpdateTest method testDiseaseChangePartialUpdates.
@Test
public void testDiseaseChangePartialUpdates() {
TestDataCreator.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);
ObjectMapper mapper = new ObjectMapper();
JsonNode caseJson = mapper.convertValue(caze, JsonNode.class);
// check if the disease is the same in the converted json
Disease actualDisease = Enum.valueOf(Disease.class, caseJson.get("disease").textValue());
assertEquals(Disease.EVD, actualDisease);
// change the disease in the caze and convert to json
// check if the disease in json reflects the modification
caze.setDisease(Disease.MEASLES);
caseJson = mapper.convertValue(caze, JsonNode.class);
actualDisease = Enum.valueOf(Disease.class, caseJson.get("disease").textValue());
assertEquals(Disease.MEASLES, actualDisease);
// remove from json some nodes such as person, region, etc to simulate a partial json
((ObjectNode) caseJson).remove("person");
((ObjectNode) caseJson).remove("region");
((ObjectNode) caseJson).remove("district");
((ObjectNode) caseJson).remove("community");
((ObjectNode) caseJson).remove("healthFacility");
((ObjectNode) caseJson).remove("epiData");
((ObjectNode) caseJson).remove("surveillanceOfficer");
((ObjectNode) caseJson).remove("symptoms");
// call the partial update
CaseDataDto casePostUpdated = getCaseFacade().postUpdate(caze.getUuid(), caseJson);
// check if the disease was changed
assertEquals(Disease.MEASLES, casePostUpdated.getDisease());
// check if the fields that were not in the json file has not be deleted
assertEquals(cazePerson.toReference(), casePostUpdated.getPerson());
}
Aggregations