Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 7eb0407c authored by Wylem Bars's avatar Wylem Bars

PATREG-33 | Add tests for Domain and multiple OR/AND criterion

parent 11040327
Pipeline #138128 passed with stages
in 8 minutes and 47 seconds
......@@ -52,7 +52,7 @@ public class PatientSearchCriterionJPAMappingService implements SearchCriterionJ
((Join) p).getAttribute().getName().equals(PATIENT_IDENTIFIER_ATTRIBUTE) &&
JoinType.LEFT.equals(((Join) p).getJoinType()))
.findAny().orElse(null);
return from2 != null ? from : from.join(entityType.getList(PATIENT_IDENTIFIER_ATTRIBUTE, PatientIdentifierDB.class), JoinType.LEFT);
return from2 != null ? from2 : from.join(entityType.getList(PATIENT_IDENTIFIER_ATTRIBUTE, PatientIdentifierDB.class), JoinType.LEFT);
} else if (PatientSearchCriterionKey.DOMAIN.equals(patientSearchCriterionKey)) {
From from2 = (From) from.getJoins().stream()
.filter(p ->
......
......@@ -18,6 +18,11 @@ public class PatientFeedApplication implements PatientFeedService {
DomainService domainDao;
/**
* Default injection constructor for the class.
* @param patientDAO Data Access Object for {@link net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB}
* @param domainDao Data Access Object for {@link net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.HierarchicDesignatorDB}
*/
@Inject
public PatientFeedApplication(@Named("PatientDAO") PatientDAO patientDAO,
@Named("domainDAOService") DomainService domainDao) {
......@@ -25,6 +30,9 @@ public class PatientFeedApplication implements PatientFeedService {
this.domainDao = domainDao;
}
/**
* {@inheritDoc}
*/
@Override
public String feedPatient(Patient patient) throws PatientFeedException{
String uuid = generateUuid();
......@@ -40,6 +48,11 @@ public class PatientFeedApplication implements PatientFeedService {
return uuid;
}
/**
* Generate a new UUID
* @return the literal value of the new UUID
* @throws PatientFeedException if the UUID cannot be checked to be unique.
*/
private String generateUuid() throws PatientFeedException{
String uuid = UUID.randomUUID().toString();
try {
......@@ -53,6 +66,10 @@ public class PatientFeedApplication implements PatientFeedService {
return uuid;
}
/**
* Create {@link net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.HierarchicDesignatorDB} if they do not exist.
* @param identifiers list of {@link EntityIdentifier} containing Domains to create if not existing.
*/
private void createIdentifiersDomainIfMissing(List<EntityIdentifier> identifiers) {
identifiers.forEach(identifier -> {
if(identifier.getSystemIdentifier() != null && !isDomainOfIdentifierExisting(identifier)) {
......@@ -61,6 +78,11 @@ public class PatientFeedApplication implements PatientFeedService {
});
}
/**
* Checks if a Domain exists.
* @param identifier {@link EntityIdentifier} defining the Domain System Identifier
* @return true if the Domain exists, false otherwise.
*/
private boolean isDomainOfIdentifierExisting(EntityIdentifier identifier) {
return this.domainDao.exist(identifier.getSystemIdentifier());
}
......
......@@ -21,8 +21,7 @@ import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
public class PatientSearchDAOTest {
......@@ -205,6 +204,50 @@ public class PatientSearchDAOTest {
assertEquals(patient, retrievedPatients.get(0), "Returned patient shall be equal to the one fed !");
}
/**
* Test Patient search on Domain with multiple patients in DB.
*/
@Test
public void patientSearchDomainMultiplePatient() throws SearchException, PatientCreationException, PatientDeleteException {
Patient patient = new Patient();
String uuid = "test-uuid0";
patient.setUuid(uuid);
String identifier = "test-identifier";
String systemIdentifier = "system-identifier";
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
entityIdentifier.setSystemIdentifier(systemIdentifier);
patient.addIdentifier(entityIdentifier);
createIdentifiersDomainIfMissing(patient.getIdentifiers());
patientDAO.createPatient(patient);
Patient patient1 = new Patient();
String uuid1 = "test-uuid1";
patient1.setUuid(uuid1);
EntityIdentifier entityIdentifier1 = new EntityIdentifier();
entityIdentifier1.setValue("tutu");
entityIdentifier1.setSystemIdentifier("toto");
patient1.addIdentifier(entityIdentifier1);
createIdentifiersDomainIfMissing(patient1.getIdentifiers());
patientDAO.createPatient(patient1);
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.DOMAIN);
searchCriterion.setValue(systemIdentifier);
searchCriteria.addSearchCriterion(searchCriterion);
List<Patient> retrievedPatients = patientSearchDAO.search(searchCriteria);
patientDAO.deletePatient(patient);
patientDAO.deletePatient(patient1);
domainDAO.delete(systemIdentifier);
domainDAO.delete("toto");
assertNotNull(retrievedPatients);
assertEquals(1, retrievedPatients.size());
assertTrue(patient.equals(retrievedPatients.get(0)), "Returned patient shall be equal to the one fed !");
}
/**
* Test Patient search on Identifier with no match in DB.
*/
......@@ -217,12 +260,14 @@ public class PatientSearchDAOTest {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
patient.addIdentifier(entityIdentifier);
createIdentifiersDomainIfMissing(patient.getIdentifiers());
patientDAO.createPatient(patient);
Patient patient1 = new Patient();
String uuid1 = "test-uuid1";
patient1.setUuid(uuid1);
patient1.addIdentifier(entityIdentifier);
createIdentifiersDomainIfMissing(patient1.getIdentifiers());
patientDAO.createPatient(patient1);
SearchCriteria searchCriteria = new SearchCriteria();
......@@ -252,6 +297,7 @@ public class PatientSearchDAOTest {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
patient.addIdentifier(entityIdentifier);
createIdentifiersDomainIfMissing(patient.getIdentifiers());
patientDAO.createPatient(patient);
Patient patient1 = new Patient();
......@@ -294,6 +340,7 @@ public class PatientSearchDAOTest {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
patient.addIdentifier(entityIdentifier);
createIdentifiersDomainIfMissing(patient.getIdentifiers());
patientDAO.createPatient(patient);
Patient patient1 = new Patient();
......@@ -302,6 +349,7 @@ public class PatientSearchDAOTest {
EntityIdentifier entityIdentifier1 = new EntityIdentifier();
entityIdentifier1.setValue("tutu");
patient1.addIdentifier(entityIdentifier1);
createIdentifiersDomainIfMissing(patient1.getIdentifiers());
patientDAO.createPatient(patient1);
Patient patient2 = new Patient();
......@@ -310,6 +358,7 @@ public class PatientSearchDAOTest {
EntityIdentifier entityIdentifier2 = new EntityIdentifier();
entityIdentifier1.setValue("tutu");
patient2.addIdentifier(entityIdentifier2);
createIdentifiersDomainIfMissing(patient2.getIdentifiers());
patientDAO.createPatient(patient2);
SearchCriteria searchCriteria = new SearchCriteria();
......@@ -325,8 +374,71 @@ public class PatientSearchDAOTest {
patientDAO.deletePatient(patient);
patientDAO.deletePatient(patient1);
patientDAO.deletePatient(patient2);
assertNotNull(retrievedPatients);
assertEquals(2, retrievedPatients.size());
}
/**
* Test Patient search on Identifier AND Domain with multiple patients in DB.
*/
@Test
public void patientSearchIdentifierAndDomainMultiplePatient() throws SearchException, PatientCreationException, PatientDeleteException {
Patient patient = new Patient();
String uuid = "test-uuid0";
String identifier = "test-identifier";
String systemIdentifier = "system-identifier";
patient.setUuid(uuid);
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
entityIdentifier.setSystemIdentifier(systemIdentifier);
patient.addIdentifier(entityIdentifier);
createIdentifiersDomainIfMissing(patient.getIdentifiers());
patientDAO.createPatient(patient);
Patient patient1 = new Patient();
String uuid1 = "test-uuid1";
patient1.setUuid(uuid1);
EntityIdentifier entityIdentifier1 = new EntityIdentifier();
entityIdentifier1.setValue(identifier);
entityIdentifier1.setSystemIdentifier("Tarte");
patient1.addIdentifier(entityIdentifier1);
createIdentifiersDomainIfMissing(patient1.getIdentifiers());
patientDAO.createPatient(patient1);
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.DOMAIN);
searchCriterion.setValue(systemIdentifier);
SearchCriterion searchCriterion1 = new StringSearchCriterion(PatientSearchCriterionKey.IDENTIFIER);
searchCriterion1.setValue(identifier);
searchCriteria.addSearchCriterion(searchCriterion);
searchCriteria.addSearchCriterion(searchCriterion1);
searchCriteria.setLogicalOperator(SearchCriteriaLogicalOperator.AND);
List<Patient> retrievedPatients = patientSearchDAO.search(searchCriteria);
patientDAO.deletePatient(patient);
patientDAO.deletePatient(patient1);
domainDAO.delete(systemIdentifier);
domainDAO.delete("Tarte");
assertNotNull(retrievedPatients);
assertEquals(1, retrievedPatients.size());
assertEquals(patient, retrievedPatients.get(0), "Returned patient shall be equal to the one fed !");
}
/**
* Creates domains that does not exist in Database.
* @param identifiers list of identifier with identifiers to create.
*/
private void createIdentifiersDomainIfMissing(List<EntityIdentifier> identifiers) {
identifiers.forEach(identifier -> {
if(identifier.getSystemIdentifier() != null && !domainDAO.exist(identifier.getSystemIdentifier())) {
domainDAO.createDomain(identifier.getSystemIdentifier(), identifier.getSystemName());
}
});
}
}
......@@ -5,7 +5,7 @@ Feature: Feed Patient information
| tmpuuid | gender | active | dateOfBirth | dateOfDeath | multipleBirthOrder |
| tmpuuid0 | MALE | true | 1984-03-12T17:25:04.017+0100 | 2020-03-12T17:25:04.017+0100 | 134 |
And patients have the following identifiers
| tmpuuid | systemIdentifier | value | systemName | type |
| tmpuuid | systemIdentifier | value | systemName | type |
| tmpuuid0 | urn:oid:1.2.3.5 | identifier42 | system0 | PI |
| tmpuuid0 | urn:oid:5.6.7.9 | identifier42 | system2 | PI |
And patients have the following names
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment