use of de.symeda.sormas.api.contact.ContactClassification in project SORMAS-Project by hzi-braunschweig.
the class CaseContactsView method createFilterBar.
public HorizontalLayout createFilterBar() {
HorizontalLayout topLayout = new HorizontalLayout();
topLayout.setSpacing(true);
topLayout.setSizeUndefined();
classificationFilter = ComboBoxHelper.createComboBoxV7();
classificationFilter.setWidth(240, Unit.PIXELS);
classificationFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.CONTACT_CLASSIFICATION));
classificationFilter.addValueChangeListener(e -> criteria.setContactClassification((ContactClassification) e.getProperty().getValue()));
topLayout.addComponent(classificationFilter);
UserDto user = UserProvider.getCurrent().getUser();
regionFilter = ComboBoxHelper.createComboBoxV7();
if (user.getRegion() == null) {
regionFilter.setWidth(240, Unit.PIXELS);
regionFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.REGION_UUID));
regionFilter.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
regionFilter.addValueChangeListener(e -> {
RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
if (region != null) {
officerFilter.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRoles(region, UserRole.CONTACT_OFFICER));
} else {
officerFilter.removeAllItems();
}
criteria.region(region);
});
topLayout.addComponent(regionFilter);
}
districtFilter = ComboBoxHelper.createComboBoxV7();
districtFilter.setWidth(240, Unit.PIXELS);
districtFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.DISTRICT_UUID));
districtFilter.addValueChangeListener(e -> criteria.district((DistrictReferenceDto) e.getProperty().getValue()));
if (user.getRegion() != null && user.getDistrict() == null) {
districtFilter.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(user.getRegion().getUuid()));
districtFilter.setEnabled(true);
} else {
regionFilter.addValueChangeListener(e -> {
RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
districtFilter.removeAllItems();
if (region != null) {
districtFilter.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
districtFilter.setEnabled(true);
} else {
districtFilter.setEnabled(false);
}
});
districtFilter.setEnabled(false);
}
topLayout.addComponent(districtFilter);
Label infoLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml(), ContentMode.HTML);
infoLabel.setSizeUndefined();
infoLabel.setDescription(I18nProperties.getString(Strings.infoContactsViewRegionDistrictFilter), ContentMode.HTML);
CssStyles.style(infoLabel, CssStyles.LABEL_XLARGE, CssStyles.LABEL_SECONDARY);
topLayout.addComponent(infoLabel);
officerFilter = ComboBoxHelper.createComboBoxV7();
officerFilter.setWidth(240, Unit.PIXELS);
officerFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.CONTACT_OFFICER_UUID));
officerFilter.addValueChangeListener(e -> criteria.setContactOfficer((UserReferenceDto) e.getProperty().getValue()));
if (user.getRegion() != null) {
officerFilter.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRoles(user.getRegion(), UserRole.CONTACT_OFFICER));
}
topLayout.addComponent(officerFilter);
searchField = new TextField();
searchField.setWidth(150, Unit.PIXELS);
searchField.setNullRepresentation("");
searchField.setInputPrompt(I18nProperties.getString(Strings.promptContactsSearchField));
searchField.addTextChangeListener(e -> criteria.setContactOrCaseLike(e.getText()));
topLayout.addComponent(searchField);
personLikeField = new TextField();
personLikeField.setWidth(150, Unit.PIXELS);
personLikeField.setNullRepresentation("");
personLikeField.setInputPrompt(I18nProperties.getString(Strings.promptRelatedPersonLikeField));
personLikeField.addTextChangeListener(e -> criteria.setPersonLike(e.getText()));
topLayout.addComponent(personLikeField);
resetButton = ButtonHelper.createButton(Captions.actionResetFilters, event -> {
ViewModelProviders.of(CaseContactsView.class).remove(ContactCriteria.class);
navigateTo(null);
});
resetButton.setVisible(false);
topLayout.addComponent(resetButton);
applyButton = ButtonHelper.createButton(Captions.actionApplyFilters, event -> navigateTo(criteria));
applyButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
applyButton.setVisible(false);
topLayout.addComponent(applyButton);
classificationFilter.addValueChangeListener(e -> updateApplyResetButtons());
regionFilter.addValueChangeListener(e -> updateApplyResetButtons());
officerFilter.addValueChangeListener(e -> updateApplyResetButtons());
districtFilter.addValueChangeListener(e -> updateApplyResetButtons());
searchField.addValueChangeListener(e -> updateApplyResetButtons());
personLikeField.addValueChangeListener(e -> updateApplyResetButtons());
return topLayout;
}
use of de.symeda.sormas.api.contact.ContactClassification in project SORMAS-Project by hzi-braunschweig.
the class ContactClassificationCurveBuilder method buildEpiCurve.
@Override
public void buildEpiCurve(List<Date> datesGroupedBy, DashboardDataProvider dashboardDataProvider) {
int[] unconfirmedNumbers = new int[datesGroupedBy.size()];
int[] confirmedNumbers = new int[datesGroupedBy.size()];
for (int i = 0; i < datesGroupedBy.size(); i++) {
Date date = datesGroupedBy.get(i);
ContactCriteria contactCriteria = new ContactCriteria().disease(dashboardDataProvider.getDisease()).region(dashboardDataProvider.getRegion()).district(dashboardDataProvider.getDistrict());
if (epiCurveGrouping == DAY) {
contactCriteria.reportDateBetween(DateHelper.getStartOfDay(date), DateHelper.getEndOfDay(date));
} else if (epiCurveGrouping == EpiCurveGrouping.WEEK) {
contactCriteria.reportDateBetween(DateHelper.getStartOfWeek(date), DateHelper.getEndOfWeek(date));
} else {
contactCriteria.reportDateBetween(DateHelper.getStartOfMonth(date), DateHelper.getEndOfMonth(date));
}
Map<ContactClassification, Long> contactCounts = FacadeProvider.getContactFacade().getNewContactCountPerClassification(contactCriteria);
Long unconfirmedCount = contactCounts.get(ContactClassification.UNCONFIRMED);
Long confirmedCount = contactCounts.get(ContactClassification.CONFIRMED);
unconfirmedNumbers[i] = unconfirmedCount != null ? unconfirmedCount.intValue() : 0;
confirmedNumbers[i] = confirmedCount != null ? confirmedCount.intValue() : 0;
}
hcjs.append("series: [");
hcjs.append("{ name: '" + I18nProperties.getCaption(Captions.dashboardUnconfirmedContact) + "', color: '#808080', dataLabels: { allowOverlap: false }, data: [");
for (int i = 0; i < unconfirmedNumbers.length; i++) {
if (i == unconfirmedNumbers.length - 1) {
hcjs.append(unconfirmedNumbers[i] + "]},");
} else {
hcjs.append(unconfirmedNumbers[i] + ", ");
}
}
hcjs.append("{ name: '" + I18nProperties.getCaption(Captions.dashboardConfirmedContact) + "', color: '#005A9C', dataLabels: { allowOverlap: false }, data: [");
for (int i = 0; i < confirmedNumbers.length; i++) {
if (i == confirmedNumbers.length - 1) {
hcjs.append(confirmedNumbers[i] + "]}],");
} else {
hcjs.append(confirmedNumbers[i] + ", ");
}
}
}
use of de.symeda.sormas.api.contact.ContactClassification in project SORMAS-Project by hzi-braunschweig.
the class ContactService method getNewContactCountPerClassification.
public Map<ContactClassification, Long> getNewContactCountPerClassification(ContactCriteria contactCriteria, User user) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<Contact> contact = cq.from(getElementClass());
final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contact);
Predicate filter = createUserFilter(cb, cq, contact);
Predicate criteriaFilter = buildCriteriaFilter(contactCriteria, contactQueryContext);
Predicate notDeleted = cb.isFalse(contact.get(Contact.DELETED));
if (filter != null) {
filter = cb.and(filter, criteriaFilter, notDeleted);
} else {
filter = cb.and(criteriaFilter, notDeleted);
}
if (filter != null) {
cq.where(filter);
}
cq.groupBy(contact.get(Contact.CONTACT_CLASSIFICATION));
cq.multiselect(contact.get(Contact.CONTACT_CLASSIFICATION), cb.count(contact));
List<Object[]> results = em.createQuery(cq).getResultList();
return results.stream().collect(Collectors.toMap(e -> (ContactClassification) e[0], e -> (Long) e[1]));
}
use of de.symeda.sormas.api.contact.ContactClassification in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method getMatchingContacts.
@Override
public List<SimilarContactDto> getMatchingContacts(ContactSimilarityCriteria criteria) {
final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery<SimilarContactDto> cq = cb.createQuery(SimilarContactDto.class);
final Root<Contact> contactRoot = cq.from(Contact.class);
cq.distinct(true);
ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contactRoot);
ContactJoins<Contact> joins = (ContactJoins<Contact>) contactQueryContext.getJoins();
List<Selection<?>> selections = new ArrayList<>(Arrays.asList(joins.getPerson().get(Person.FIRST_NAME), joins.getPerson().get(Person.LAST_NAME), contactRoot.get(Contact.UUID), joins.getCaze().get(Case.UUID), joins.getCasePerson().get(Person.FIRST_NAME), joins.getCasePerson().get(Person.LAST_NAME), contactRoot.get(Contact.CASE_ID_EXTERNAL_SYSTEM), contactRoot.get(Contact.LAST_CONTACT_DATE), contactRoot.get(Contact.CONTACT_PROXIMITY), contactRoot.get(Contact.CONTACT_CLASSIFICATION), contactRoot.get(Contact.CONTACT_STATUS), contactRoot.get(Contact.FOLLOW_UP_STATUS)));
selections.addAll(service.getJurisdictionSelections(contactQueryContext));
cq.multiselect(selections);
final Predicate defaultFilter = service.createDefaultFilter(cb, contactRoot);
final Predicate userFilter = service.createUserFilter(cb, cq, contactRoot);
final PersonReferenceDto person = criteria.getPerson();
final Predicate samePersonFilter = person != null ? cb.equal(joins.getPerson().get(Person.UUID), person.getUuid()) : null;
final Disease disease = criteria.getDisease();
final Predicate diseaseFilter = disease != null ? cb.equal(contactRoot.get(Contact.DISEASE), disease) : null;
final CaseReferenceDto caze = criteria.getCaze();
final Predicate cazeFilter = caze != null ? cb.equal(joins.getCaze().get(Case.UUID), caze.getUuid()) : null;
final ContactClassification contactClassification = criteria.getContactClassification();
final Predicate contactClassificationFilter = contactClassification != null ? cb.equal(contactRoot.get(Contact.CONTACT_CLASSIFICATION), contactClassification) : null;
final Predicate noResulingCaseFilter = Boolean.TRUE.equals(criteria.getNoResultingCase()) ? cb.isNull(contactRoot.get(Contact.RESULTING_CASE)) : null;
final Date reportDate = criteria.getReportDate();
final Date lastContactDate = criteria.getLastContactDate();
final Predicate recentContactsFilter = CriteriaBuilderHelper.and(cb, service.recentDateFilter(cb, reportDate, contactRoot.get(Contact.REPORT_DATE_TIME), 30), service.recentDateFilter(cb, lastContactDate, contactRoot.get(Contact.LAST_CONTACT_DATE), 30));
final Date relevantDate = criteria.getRelevantDate();
final Predicate relevantDateFilter = CriteriaBuilderHelper.or(cb, service.recentDateFilter(cb, relevantDate, contactRoot.get(Contact.REPORT_DATE_TIME), 30), service.recentDateFilter(cb, relevantDate, contactRoot.get(Contact.LAST_CONTACT_DATE), 30));
cq.where(CriteriaBuilderHelper.and(cb, defaultFilter, userFilter, samePersonFilter, diseaseFilter, cazeFilter, contactClassificationFilter, noResulingCaseFilter, recentContactsFilter, relevantDateFilter));
List<SimilarContactDto> contacts = em.createQuery(cq).getResultList();
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
pseudonymizer.pseudonymizeDtoCollection(SimilarContactDto.class, contacts, c -> c.getInJurisdiction(), (c, isInJurisdiction) -> {
CaseReferenceDto contactCase = c.getCaze();
if (contactCase != null) {
pseudonymizer.pseudonymizeDto(CaseReferenceDto.class, contactCase, c.getCaseInJurisdiction(), null);
}
});
if (Boolean.TRUE.equals(criteria.getExcludePseudonymized())) {
contacts = contacts.stream().filter(c -> !c.isPseudonymized()).collect(Collectors.toList());
}
return contacts;
}
use of de.symeda.sormas.api.contact.ContactClassification in project SORMAS-Project by hzi-braunschweig.
the class ContactService method udpateContactStatus.
/**
* Calculates resultingCase and contact status based on: - existing disease
* cases (and classification) of the person - the incubation period - the
* contact classification - the follow-up status
*/
public void udpateContactStatus(Contact contact) {
ContactClassification contactClassification = contact.getContactClassification();
if (contactClassification == null) {
// Fall-back
contactClassification = ContactClassification.UNCONFIRMED;
}
switch(contactClassification) {
case UNCONFIRMED:
contact.setContactStatus(ContactStatus.ACTIVE);
break;
case NO_CONTACT:
contact.setContactStatus(ContactStatus.DROPPED);
cancelFollowUp(contact, I18nProperties.getString(Strings.messageSystemFollowUpCanceledByDropping));
break;
case CONFIRMED:
if (contact.getResultingCase() != null) {
contact.setContactStatus(ContactStatus.CONVERTED);
} else {
if (contact.getFollowUpStatus() != null) {
switch(contact.getFollowUpStatus()) {
case CANCELED:
case COMPLETED:
case LOST:
case NO_FOLLOW_UP:
contact.setContactStatus(ContactStatus.DROPPED);
break;
case FOLLOW_UP:
contact.setContactStatus(ContactStatus.ACTIVE);
break;
default:
throw new NoSuchElementException(contact.getFollowUpStatus().toString());
}
} else {
contact.setContactStatus(ContactStatus.ACTIVE);
}
}
break;
default:
throw new NoSuchElementException(DataHelper.toStringNullable(contactClassification));
}
externalJournalService.handleExternalJournalPersonUpdateAsync(contact.getPerson().toReference());
ensurePersisted(contact);
}
Aggregations