Skip to content

Commit

Permalink
SORMAS-Foundation#13029 - Search by NationalID is not consistently wo…
Browse files Browse the repository at this point in the history
…rking in all locations
  • Loading branch information
sergiupacurariu authored and daveotengo committed Mar 19, 2024
1 parent 8f13336 commit 60b7f41
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1663,9 +1663,11 @@ public interface Strings {
String promptNewCaseDateType = "promptNewCaseDateType";
String promptPersonDuplicateSearchIdExternalId = "promptPersonDuplicateSearchIdExternalId";
String promptPersonsSearchField = "promptPersonsSearchField";
String promptPersonsSearchFieldLuxembourg = "promptPersonsSearchFieldLuxembourg";
String promptPrescriptionTextFilter = "promptPrescriptionTextFilter";
String promptRegion = "promptRegion";
String promptRelatedPersonLikeField = "promptRelatedPersonLikeField";
String promptRelatedPersonLikeFieldLuxembourg = "promptRelatedPersonLikeFieldLuxembourg";
String promptSampleDashboardFilterDateType = "promptSampleDashboardFilterDateType";
String promptSampleDateFrom = "promptSampleDateFrom";
String promptSampleDateTo = "promptSampleDateTo";
Expand All @@ -1685,6 +1687,7 @@ public interface Strings {
String promptTravelEntryEpiWeekFrom = "promptTravelEntryEpiWeekFrom";
String promptTravelEntryEpiWeekTo = "promptTravelEntryEpiWeekTo";
String promptTravelEntrySearchField = "promptTravelEntrySearchField";
String promptTravelEntrySearchFieldLuxembourg = "promptTravelEntrySearchFieldLuxembourg";
String promptTreatmentTextFilter = "promptTreatmentTextFilter";
String promptTypeToAdd = "promptTypeToAdd";
String promptUserSearch = "promptUserSearch";
Expand Down
3 changes: 3 additions & 0 deletions sormas-api/src/main/resources/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ promptCasesEpiWeekTo = ... to epi week
promptCasesSearchField = ID, EPID number, external ID, facility
promptCaseOrContactEventSearchField = Event: ID, title, description
promptPersonsSearchField = ID, name, phone number, email, city, street, postal code
promptPersonsSearchFieldLuxembourg = ID, name, phone number, email, city, street, postal code, national health ID
promptCreationDateFrom = Creation date from ...
promptDateTo = ... to
promptNamePhoneEmail = Name, phone number and email address
Expand Down Expand Up @@ -1629,6 +1630,7 @@ promptNewCaseDateType = Case reference date
promptPrescriptionTextFilter = Prescription details or prescribing clinician
promptRegion = Region
promptRelatedPersonLikeField = Person ID/name/contact information/location
promptRelatedPersonLikeFieldLuxembourg = Person ID/name/contact information/location/National Health ID
promptSamplesSearchField = Sample ID/name, case name/epid number/ID, contact name/ID, event participant name/ID
promptSampleDateFrom = Sample date from ...
promptSampleDateTo = ... to
Expand All @@ -1643,6 +1645,7 @@ promptTaskDateTo = ... to
promptTaskEpiWeekFrom = Tasks from epi week...
promptTaskEpiWeekTo = ... to epi week
promptTravelEntrySearchField = Person first and last name, person UUID, person external ID, travel entry UUID, travel entry external ID
promptTravelEntrySearchFieldLuxembourg = Person first and last name, person UUID, person external ID, travel entry UUID, travel entry external ID, national health ID
promptTreatmentTextFilter = Treatment details or executing staff member
promptTypeToAdd = Type here to add...
promptUserSearch = Search user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import de.symeda.sormas.api.CountryHelper;
import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.EditPermissionType;
import de.symeda.sormas.api.EntityRelevanceStatus;
Expand Down Expand Up @@ -124,6 +125,7 @@
import de.symeda.sormas.backend.common.AbstractDomainObject;
import de.symeda.sormas.backend.common.ChangeDateBuilder;
import de.symeda.sormas.backend.common.ChangeDateFilterBuilder;
import de.symeda.sormas.backend.common.ConfigFacadeEjb;
import de.symeda.sormas.backend.common.CriteriaBuilderHelper;
import de.symeda.sormas.backend.common.DeletableAdo;
import de.symeda.sormas.backend.contact.Contact;
Expand Down Expand Up @@ -249,6 +251,8 @@ public class CaseService extends AbstractCoreAdoService<Case, CaseJoins> {
private DistrictService districtService;
@EJB
private SpecialCaseAccessService specialCaseAccessService;
@EJB
private ConfigFacadeEjb.ConfigFacadeEjbLocal configFacade;

public CaseService() {
super(Case.class, DeletableEntityType.CASE);
Expand Down Expand Up @@ -854,7 +858,10 @@ public <T extends AbstractDomainObject> Predicate createCriteriaFilter(CaseCrite
CriteriaBuilderHelper
.unaccentedIlike(cb, personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_PRIMARY_OTHER_SUBQUERY), textFilter),
CriteriaBuilderHelper.unaccentedIlike(cb, joins.getPersonAddress().get(Location.CITY), textFilter),
CriteriaBuilderHelper.ilike(cb, joins.getPersonAddress().get(Location.POSTAL_CODE), textFilter)));
CriteriaBuilderHelper.ilike(cb, joins.getPersonAddress().get(Location.POSTAL_CODE), textFilter),
configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG)
? CriteriaBuilderHelper.unaccentedIlike(cb, joins.getPerson().get(Person.NATIONAL_HEALTH_ID), textFilter)
: cb.disjunction()));

filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import de.symeda.sormas.api.CountryHelper;
import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.EditPermissionType;
import de.symeda.sormas.api.EntityRelevanceStatus;
Expand Down Expand Up @@ -1356,7 +1357,10 @@ public Predicate buildCriteriaFilter(ContactCriteria contactCriteria, ContactQue
CriteriaBuilderHelper
.unaccentedIlike(cb, personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_PRIMARY_OTHER_SUBQUERY), textFilter),
CriteriaBuilderHelper.unaccentedIlike(cb, location.get(Location.CITY), textFilter),
CriteriaBuilderHelper.ilike(cb, location.get(Location.POSTAL_CODE), textFilter)));
CriteriaBuilderHelper.ilike(cb, location.get(Location.POSTAL_CODE), textFilter),
configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG)
? CriteriaBuilderHelper.unaccentedIlike(cb, joins.getPerson().get(Person.NATIONAL_HEALTH_ID), textFilter)
: cb.disjunction()));

filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import de.symeda.sormas.api.CountryHelper;
import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.EditPermissionType;
import de.symeda.sormas.api.EntityRelevanceStatus;
Expand Down Expand Up @@ -76,6 +77,7 @@
import de.symeda.sormas.backend.common.AbstractDomainObject;
import de.symeda.sormas.backend.common.ChangeDateBuilder;
import de.symeda.sormas.backend.common.ChangeDateFilterBuilder;
import de.symeda.sormas.backend.common.ConfigFacadeEjb;
import de.symeda.sormas.backend.common.CriteriaBuilderHelper;
import de.symeda.sormas.backend.common.DeletableAdo;
import de.symeda.sormas.backend.contact.Contact;
Expand Down Expand Up @@ -137,6 +139,8 @@ public class EventService extends AbstractCoreAdoService<Event, EventJoins> {
private EventFacadeEjb.EventFacadeEjbLocal eventFacade;
@EJB
private ExternalSurveillanceToolGatewayFacadeEjb.ExternalSurveillanceToolGatewayFacadeEjbLocal externalSurveillanceToolGatewayFacade;
@EJB
private ConfigFacadeEjb.ConfigFacadeEjbLocal configFacade;

public EventService() {
super(Event.class, DeletableEntityType.EVENT);
Expand Down Expand Up @@ -827,7 +831,10 @@ public Predicate buildCriteriaFilter(EventCriteria eventCriteria, EventQueryCont
CriteriaBuilderHelper.unaccentedIlike(cb, personJoin.get(Person.FIRST_NAME), textFilter),
CriteriaBuilderHelper.unaccentedIlike(cb, personJoin.get(Person.LAST_NAME), textFilter),
CriteriaBuilderHelper.ilike(cb, personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_PHONE_SUBQUERY), textFilter),
CriteriaBuilderHelper.ilike(cb, personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_EMAIL_SUBQUERY), textFilter));
CriteriaBuilderHelper.ilike(cb, personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_EMAIL_SUBQUERY), textFilter),
configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG)
? CriteriaBuilderHelper.unaccentedIlike(cb, personJoin.get(Person.NATIONAL_HEALTH_ID), textFilter)
: cb.disjunction());
filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}
filter = CriteriaBuilderHelper.and(cb, filter, cb.isFalse(eventParticipantJoin.get(EventParticipant.DELETED)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Tuple;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
Expand All @@ -28,6 +27,7 @@

import org.apache.commons.collections4.CollectionUtils;

import de.symeda.sormas.api.CountryHelper;
import de.symeda.sormas.api.EntityRelevanceStatus;
import de.symeda.sormas.api.common.DeletableEntityType;
import de.symeda.sormas.api.feature.FeatureType;
Expand All @@ -37,12 +37,12 @@
import de.symeda.sormas.api.immunization.ImmunizationIndexDto;
import de.symeda.sormas.api.immunization.ImmunizationManagementStatus;
import de.symeda.sormas.api.person.PersonAssociation;
import de.symeda.sormas.api.person.PersonCriteria;
import de.symeda.sormas.api.person.PersonIndexDto;
import de.symeda.sormas.api.utils.DataHelper;
import de.symeda.sormas.api.utils.DateHelper;
import de.symeda.sormas.api.utils.SortProperty;
import de.symeda.sormas.backend.common.AbstractDeletableAdoService;
import de.symeda.sormas.backend.common.ConfigFacadeEjb;
import de.symeda.sormas.backend.common.CriteriaBuilderHelper;
import de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal;
import de.symeda.sormas.backend.immunization.entity.DirectoryImmunization;
Expand Down Expand Up @@ -78,6 +78,8 @@ public class DirectoryImmunizationService extends AbstractDeletableAdoService<Di
private FeatureConfigurationFacadeEjbLocal featureConfigurationFacade;
@EJB
private SpecialCaseAccessService specialCaseAccessService;
@EJB
private ConfigFacadeEjb.ConfigFacadeEjbLocal configFacade;

public DirectoryImmunizationService() {
super(DirectoryImmunization.class, DeletableEntityType.IMMUNIZATION);
Expand Down Expand Up @@ -305,6 +307,9 @@ private Predicate buildCriteriaFilter(ImmunizationCriteria criteria, DirectoryIm
CriteriaBuilderHelper.ilike(cb, person.get(Person.INTERNAL_TOKEN), textFilter),
CriteriaBuilderHelper.ilike(cb, person.get(Person.EXTERNAL_ID), textFilter),
CriteriaBuilderHelper.ilike(cb, person.get(Person.EXTERNAL_TOKEN), textFilter),
configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG)
? CriteriaBuilderHelper.unaccentedIlike(cb, person.get(Person.NATIONAL_HEALTH_ID), textFilter)
: cb.disjunction(),
CriteriaBuilderHelper.unaccentedIlike(cb, lastVaccineType.get(LastVaccineType.VACCINE_TYPE), textFilter));
filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}
Expand Down Expand Up @@ -406,7 +411,7 @@ private Predicate createUserFilter(DirectoryImmunizationQueryContext qc) {
final CriteriaBuilder cb = qc.getCriteriaBuilder();
Predicate filter = null;

filter = isInJurisdictionOrOwned(qc);
filter = isInJurisdictionOrOwned(qc);

From<?, DirectoryImmunization> root = qc.getRoot();
DirectoryImmunizationJoins joins = qc.getJoins();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ private Predicate buildCriteriaFilter(TravelEntryCriteria criteria, TravelEntryQ
CriteriaBuilderHelper.ilike(cb, from.get(TravelEntry.UUID), textFilter),
CriteriaBuilderHelper.ilike(cb, from.get(TravelEntry.EXTERNAL_ID), textFilter),
CriteriaBuilderHelper.ilike(cb, person.get(Person.UUID), textFilter),
CriteriaBuilderHelper.ilike(cb, person.get(Person.EXTERNAL_ID), textFilter)));
CriteriaBuilderHelper.ilike(cb, person.get(Person.EXTERNAL_ID), textFilter),
CriteriaBuilderHelper.unaccentedIlike(cb, person.get(Person.NATIONAL_HEALTH_ID), textFilter)));
filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.mockito.Mockito;

import de.symeda.sormas.api.CaseMeasure;
import de.symeda.sormas.api.CountryHelper;
import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.Language;
import de.symeda.sormas.api.VisitOrigin;
Expand Down Expand Up @@ -183,6 +184,7 @@
import de.symeda.sormas.backend.MockProducer;
import de.symeda.sormas.backend.TestDataCreator;
import de.symeda.sormas.backend.TestDataCreator.RDCF;
import de.symeda.sormas.backend.common.ConfigFacadeEjb;
import de.symeda.sormas.backend.infrastructure.district.District;
import de.symeda.sormas.backend.infrastructure.region.Region;
import de.symeda.sormas.backend.share.ExternalShareInfo;
Expand Down Expand Up @@ -3112,6 +3114,43 @@ public void searchCasesByPersonOtherDetail() {
assertEquals(0, caseIndexDetailedDtos.size());
}

@Test
public void testGetCasesByPersonNationalHealthId() {
MockProducer.getProperties().setProperty(ConfigFacadeEjb.COUNTRY_LOCALE, CountryHelper.COUNTRY_CODE_LUXEMBOURG);
PersonReferenceDto person1 = creator.createPerson().toReference();
PersonDto personDto1 = getPersonFacade().getByUuid(person1.getUuid());
personDto1.setNationalHealthId("firstNationalId");
getPersonFacade().save(personDto1);
CaseDataDto case1 = getCaseFacade().save(creator.createCase(surveillanceOfficer.toReference(), person1, rdcf));

PersonReferenceDto person2 = creator.createPerson().toReference();
PersonDto personDto2 = getPersonFacade().getByUuid(person2.getUuid());
personDto2.setNationalHealthId("secondNationalId");
getPersonFacade().save(personDto2);
getCaseFacade().save(creator.createCase(surveillanceOfficer.toReference(), person2, rdcf));

PersonReferenceDto person3 = creator.createPerson().toReference();
PersonDto personDto3 = getPersonFacade().getByUuid(person3.getUuid());
personDto3.setNationalHealthId("third");
getPersonFacade().save(personDto3);
getCaseFacade().save(creator.createCase(surveillanceOfficer.toReference(), person3, rdcf));

CaseCriteria caseCriteria = new CaseCriteria();
caseCriteria.setPersonLike("firstNationalId");

List<CaseIndexDto> caseIndexDtos1 = getCaseFacade().getIndexList(caseCriteria, 0, 100, null);
assertEquals(1, caseIndexDtos1.size());
assertEquals(case1.getUuid(), caseIndexDtos1.get(0).getUuid());

caseCriteria.setPersonLike("National");
List<CaseIndexDto> caseIndexDtosNational = getCaseFacade().getIndexList(caseCriteria, 0, 100, null);
assertEquals(2, caseIndexDtosNational.size());

caseCriteria.setPersonLike(null);
List<CaseIndexDto> caseIndexDtosAll = getCaseFacade().getIndexList(caseCriteria, 0, 100, null);
assertEquals(3, caseIndexDtosAll.size());
}

@Test
public void testArchiveAllArchivableCases() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.commons.lang3.time.DateUtils;
import org.junit.jupiter.api.Test;

import de.symeda.sormas.api.CountryHelper;
import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.Language;
import de.symeda.sormas.api.VisitOrigin;
Expand Down Expand Up @@ -133,8 +134,10 @@
import de.symeda.sormas.api.visit.VisitSummaryExportDetailsDto;
import de.symeda.sormas.api.visit.VisitSummaryExportDto;
import de.symeda.sormas.backend.AbstractBeanTest;
import de.symeda.sormas.backend.MockProducer;
import de.symeda.sormas.backend.TestDataCreator;
import de.symeda.sormas.backend.TestDataCreator.RDCF;
import de.symeda.sormas.backend.common.ConfigFacadeEjb;
import de.symeda.sormas.backend.contact.ContactFacadeEjb.ContactFacadeEjbLocal;
import de.symeda.sormas.backend.infrastructure.community.Community;
import de.symeda.sormas.backend.infrastructure.district.District;
Expand Down Expand Up @@ -2216,6 +2219,46 @@ public void searchContactsByPersonOtherDetail() {
assertEquals(0, contactIndexDetailedDtos.size());
}

@Test
public void testGetContactsByPersonNationalHealthId() {
MockProducer.getProperties().setProperty(ConfigFacadeEjb.COUNTRY_LOCALE, CountryHelper.COUNTRY_CODE_LUXEMBOURG);
RDCF rdcf = creator.createRDCF();
UserDto user = creator.createSurveillanceSupervisor(rdcf);

PersonReferenceDto person1 = creator.createPerson().toReference();
PersonDto personDto1 = getPersonFacade().getByUuid(person1.getUuid());
personDto1.setNationalHealthId("firstNationalId");
getPersonFacade().save(personDto1);
ContactDto contact1 = getContactFacade().save(creator.createContact(user.toReference(), person1));

PersonReferenceDto person2 = creator.createPerson().toReference();
PersonDto personDto2 = getPersonFacade().getByUuid(person2.getUuid());
personDto2.setNationalHealthId("secondNationalId");
getPersonFacade().save(personDto2);
getContactFacade().save(creator.createContact(user.toReference(), person2));

PersonReferenceDto person3 = creator.createPerson().toReference();
PersonDto personDto3 = getPersonFacade().getByUuid(person3.getUuid());
personDto3.setNationalHealthId("third");
getPersonFacade().save(personDto3);
getContactFacade().save(creator.createContact(user.toReference(), person3));

ContactCriteria contactCriteria = new ContactCriteria();
contactCriteria.setPersonLike("firstNationalId");

List<ContactIndexDto> contactIndexDtos1 = getContactFacade().getIndexList(contactCriteria, 0, 100, null);
assertEquals(1, contactIndexDtos1.size());
assertEquals(contact1.getUuid(), contactIndexDtos1.get(0).getUuid());

contactCriteria.setPersonLike("National");
List<ContactIndexDto> contactIndexDtosNational = getContactFacade().getIndexList(contactCriteria, 0, 100, null);
assertEquals(2, contactIndexDtosNational.size());

contactCriteria.setPersonLike(null);
List<ContactIndexDto> contactIndexDtosAll = getContactFacade().getIndexList(contactCriteria, 0, 100, null);
assertEquals(3, contactIndexDtosAll.size());
}

@Test
public void testContactsForDashboard() {

Expand Down
Loading

0 comments on commit 60b7f41

Please sign in to comment.