Commit 09921b95 authored by Franck Desaize's avatar Franck Desaize
Browse files

TUs Service : 100%

parent 93ce7b05
Pipeline #262752 failed with stages
in 4 minutes and 36 seconds
......@@ -68,7 +68,7 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
queryForPatientAliases.setParameter("patient", patientDB);
List<CrossReferenceDB> crossReferenceDBS = queryForPatientAliases.getResultList();
if (crossReferenceDBS.isEmpty()) {
throw new SearchCrossReferenceException("No PatientAliases found with given patient ");
throw new SearchCrossReferenceException("Search error : No X-ref for given Patient");
}
return crossReferenceDBS;
}
......
package net.ihe.gazelle.app.patientregistryservice.application;
import net.ihe.gazelle.app.patientregistryapi.application.DomainService;
import net.ihe.gazelle.app.patientregistryapi.application.PatientCrossReferenceSearch;
import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
......@@ -19,14 +18,11 @@ import java.util.HashSet;
import java.util.List;
public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSearch {
private DomainService domainDao;
private PatientCrossReferenceDAO patientCrossReferenceDAO;
@Inject
public PatientCrossReferenceSearchImpl(@Named("domainDAOService") DomainService domainDao,
@Named("PatientCrossReferenceDAO") PatientCrossReferenceDAO patientCrossReferenceDAO) {
this.domainDao = domainDao;
public PatientCrossReferenceSearchImpl(
@Named("PatientCrossReferenceDAO") PatientCrossReferenceDAO patientCrossReferenceDAO) {
this.patientCrossReferenceDAO = patientCrossReferenceDAO;
}
......@@ -46,19 +42,27 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
checkSourceIdentifier(sourceIdentifier);
PatientDB patientDB = null;
PatientAliases patientAlias = null;
try {
patientDB = patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(sourceIdentifier);
List<CrossReferenceDB> crossReferenceDBS = patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB);
PatientAliases patientAlias = processingOnResult(crossReferenceDBS,patientDB);
return patientAlias;
} catch (SearchCrossReferenceException searchCrossReferenceException){
if (searchCrossReferenceException.getMessage().equals("No X-refFound ")) {
patientAlias = processingOnResult(crossReferenceDBS, patientDB);
} catch (SearchCrossReferenceException searchCrossReferenceException) {
if(searchCrossReferenceException.getMessage().equals("System not found")){
throw new SearchCrossReferenceException("Error in the sourceIdentifier : System doesn't exit");
}else if(searchCrossReferenceException.getMessage().equals("PatientIdentifier not found")){
throw new SearchCrossReferenceException("Error in the sourceIdentifier : it doesn't match any identity");
}else if(searchCrossReferenceException.getMessage().equals("Patient not found with with corresponding PatientIdentifier")){
throw new SearchCrossReferenceException("Error in the sourceIdentifier : it doesn't match any Patient");
}
if (searchCrossReferenceException.getMessage().equals("Search error : No X-ref for given Patient")) {
return convertPatientDBTPatientAliases(patientDB);
}
//TO Catch Exception.
}catch (Exception exception){
throw new SearchCrossReferenceException("An Error occurred during CrossReference Search",exception);
}
//TODO
throw new SearchCrossReferenceException("To defined ");
return patientAlias;
}
/**
......@@ -86,37 +90,21 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
}
}
/**
* Merge the list of patient for each patient alias into one
*
* @param patientAliases
* @return
*/
private List<Patient> getUniqueMemberFromPatientAliases(List<PatientAliases> patientAliases) {
List<Patient> members = new ArrayList<>();
for (PatientAliases pa : patientAliases) {
members.addAll(pa.getMembers());
}
List<Patient> uniquePatients = new ArrayList<>(new HashSet<>(members));
return uniquePatients;
}
/**
*
* @param crossReferenceDBS
* @param patientDB
* @return PatientAliases
*/
private PatientAliases processingOnResult(List<CrossReferenceDB> crossReferenceDBS,PatientDB patientDB) {
List<CrossReferenceDB> cleanListOfXRef = deleteKnownPatientInCrossReference(patientDB,crossReferenceDBS);
private PatientAliases processingOnResult(List<CrossReferenceDB> crossReferenceDBS, PatientDB patientDB) {
List<CrossReferenceDB> cleanListOfXRef = deleteKnownPatientInCrossReference(patientDB, crossReferenceDBS);
List<PatientAliases> patientAliasesList = PatientAliasesConverter.toListOfPatientAliases(cleanListOfXRef);
if (patientAliasesList.size() == 1) {
return patientAliasesList.get(0);
}else {
} else {
PatientAliases patientAliasOk = new PatientAliases();
for (PatientAliases patientAliases :patientAliasesList) {
for (PatientAliases patientAliases : patientAliasesList) {
patientAliasOk.addMembers(patientAliases.getMembers());
}
return patientAliasOk;
......@@ -132,8 +120,8 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
return patientAliases;
}
private List<CrossReferenceDB> deleteKnownPatientInCrossReference(PatientDB patientDB, List<CrossReferenceDB> crossReferences){
for (CrossReferenceDB crossReference :crossReferences) {
private List<CrossReferenceDB> deleteKnownPatientInCrossReference(PatientDB patientDB, List<CrossReferenceDB> crossReferences) {
for (CrossReferenceDB crossReference : crossReferences) {
if (crossReference.getPatients().size() > 1) {
crossReference.getPatients().remove(patientDB);
}
......
package net.ihe.gazelle.app.patientregistryservice.application;
import net.ihe.gazelle.app.patientregistryapi.application.DomainService;
public class DomainServiceMock implements DomainService {
@Override
public boolean exist(String domainIdentifier) {
return domainIdentifier.equals("3b19b902-cfe8-11ea-87d0-0242ac130003");
}
@Override
public void createDomain(String domainIdentifier, String domainName) {
//Not used here
}
}
package net.ihe.gazelle.app.patientregistryservice.application;
import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryapi.business.PatientAliases;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.references.CrossReferenceDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.PatientCrossReferenceDAO;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class PatientCrossReferenceDAOMock implements PatientCrossReferenceDAO {
@Override
public PatientDB searchForPatientDBWithSourceIdentifier(EntityIdentifier sourceIdentifier) throws SearchCrossReferenceException {
switch (sourceIdentifier.getValue()) {
case "UnexpectedException":
throw new IllegalArgumentException("Exception");
case "SystemNotFound":
throw new SearchCrossReferenceException("System not found");
case "PatientIdentifiernotfound":
throw new SearchCrossReferenceException("PatientIdentifier not found");
case "PatientNotFound":
throw new SearchCrossReferenceException("Patient not found with with corresponding PatientIdentifier");
case "NoXCrossrefFound":
PatientDB patientDB = new PatientDB();
patientDB.setUuid("NoCrossRef");
patientDB.setFirstName("testFirstName");
patientDB.setLastName("testLastName");
return patientDB;
case "1CrossFound":
PatientDB patientDB2 = new PatientDB();
patientDB2.setUuid("original");
patientDB2.setFirstName("testFirstName");
patientDB2.setLastName("testLastName");
return patientDB2;
case "3CrossFound":
PatientDB patientDB3 = new PatientDB();
patientDB3.setUuid("original3");
patientDB3.setFirstName("testFirstName");
patientDB3.setLastName("testLastName");
return patientDB3;
}
return null;
}
@Override
public List<CrossReferenceDB> searchForPatientAliasesWithPatientDB(PatientDB patient) throws SearchCrossReferenceException {
switch (patient.getUuid()) {
case "NoCrossRef":
throw new SearchCrossReferenceException("Search error : No X-ref for given Patient");
case "original":
List<CrossReferenceDB> crossReferenceDBS = new ArrayList<>();
crossReferenceDBS.add(crossReferenceDBS(patient,""));
return crossReferenceDBS;
case "original3":
return multipleCrossReferenceDBS(patient);
}
return null;
}
private List<CrossReferenceDB> multipleCrossReferenceDBS(PatientDB patient){
List<CrossReferenceDB>crossReferenceDBS= new ArrayList<>();
crossReferenceDBS.add(crossReferenceDBS(patient,"1"));
crossReferenceDBS.add(crossReferenceDBS(patient,"2"));
crossReferenceDBS.add(crossReferenceDBS(patient,"3"));
return crossReferenceDBS;
}
private CrossReferenceDB crossReferenceDBS(PatientDB patient, String numb){
String lastModifier = "test";
Date lastModifierDateTime = new Date();
CrossReferenceDB patientAliases = new CrossReferenceDB();
patientAliases.setLastChanged(lastModifierDateTime);
patientAliases.setLastModifier(lastModifier);
PatientDB patientDB = new PatientDB();
patientDB.setUuid("Retrieved1"+ numb);
patientDB.setFirstName("testFirstName");
patientDB.setLastName("testLastName");
PatientDB patientDB2 = new PatientDB();
patientDB2.setUuid("Retrieved2"+ numb);
patientDB2.setFirstName("testFirstName");
patientDB2.setLastName("testLastName");
PatientDB patientDB3 = new PatientDB();
patientDB3.setUuid("Retrieved3"+ numb);
patientDB3.setFirstName("testFirstName");
patientDB3.setLastName("testLastName");
List<PatientDB> patientDBS = new ArrayList<>();
patientDBS.add(patient);
patientDBS.add(patientDB);
patientDBS.add(patientDB2);
patientDBS.add(patientDB3);
patientAliases.setPatients(patientDBS);
return patientAliases;
}
}
package net.ihe.gazelle.app.patientregistryservice.application;
import net.ihe.gazelle.app.patientregistryapi.application.DomainService;
import net.ihe.gazelle.app.patientregistryapi.application.PatientCrossReferenceSearch;
import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryapi.business.PatientAliases;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.PatientCrossReferenceDAO;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
@PrepareForTest({PatientCrossReferenceDAOMock.class})
@RunWith(PowerMockRunner.class)
public class PatientCrossReferenceSearchImplTest {
private final DomainService domainDao = new DomainServiceMock();
private final PatientCrossReferenceDAO patientCrossReferenceDAO = new PatientCrossReferenceDAOMock();
private PatientCrossReferenceSearch patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(new PatientCrossReferenceDAOMock());
/**
* Test to search with a null parameter
*/
@Test
public void searchTestWithNullSourceIdentifier() {
PatientCrossReferenceSearchImpl patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(domainDao, patientCrossReferenceDAO);
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceSearch.search(null));
assertEquals("The source identifier cannot be null", exception.getMessage());
}
@Test
public void searchTestWithNullSystemIdentifier() {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
PatientCrossReferenceSearchImpl patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(domainDao, patientCrossReferenceDAO);
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceSearch.search(sourceIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceSearch.search(sourceIdentifier));
assertEquals("The system identifier from sourceIdentifier cannot be null or empty", exception.getMessage());
}
......@@ -49,9 +37,8 @@ public class PatientCrossReferenceSearchImplTest {
public void searchTestWithBlankSystemIdentifier() {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("");
PatientCrossReferenceSearchImpl patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(domainDao, patientCrossReferenceDAO);
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceSearch.search(sourceIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceSearch.search(sourceIdentifier));
assertEquals("The system identifier from sourceIdentifier cannot be null or empty", exception.getMessage());
}
......@@ -60,10 +47,8 @@ public class PatientCrossReferenceSearchImplTest {
public void searchTestWithNullValue() {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("toto");
PatientCrossReferenceSearchImpl patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(domainDao, patientCrossReferenceDAO);
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceSearch.search(sourceIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceSearch.search(sourceIdentifier));
assertEquals("The value from sourceIdentifier cannot be null or empty", exception.getMessage());
}
......@@ -73,109 +58,97 @@ public class PatientCrossReferenceSearchImplTest {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("toto");
sourceIdentifier.setValue("");
PatientCrossReferenceSearchImpl patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(domainDao, patientCrossReferenceDAO);
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceSearch.search(sourceIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceSearch.search(sourceIdentifier));
assertEquals("The value from sourceIdentifier cannot be null or empty", exception.getMessage());
}
@Test
public void searchTestWithNonExistingSourceIdentifier() {
public void searchTestWithNonExistingSystem() {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("toto");
sourceIdentifier.setValue("value");
PatientCrossReferenceSearchImpl patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(domainDao, patientCrossReferenceDAO);
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceSearch.search(sourceIdentifier));
sourceIdentifier.setValue("SystemNotFound");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceSearch.search(sourceIdentifier));
assertEquals("This source identifier does not exist", exception.getMessage());
assertEquals("Error in the sourceIdentifier : System doesn't exit", exception.getMessage());
}
@Test
public void searchTestWithNullDomainService() {
public void searchTestWithUnexpectedException() {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("toto");
sourceIdentifier.setValue("value");
PatientCrossReferenceSearchImpl patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(null, patientCrossReferenceDAO);
sourceIdentifier.setValue("UnexpectedException");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceSearch.search(sourceIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceSearch.search(sourceIdentifier));
assertEquals("An Error occurred during CrossReference Search", exception.getMessage());
}
assertEquals("This source identifier does not exist", exception.getMessage());
@Test
public void searchTestNoPatientIdentifierFoundException() {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("toto");
sourceIdentifier.setValue("PatientIdentifiernotfound");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceSearch.search(sourceIdentifier));
assertEquals("Error in the sourceIdentifier : it doesn't match any identity", exception.getMessage());
}
@Test
public void searchWithExistingSourceIdentifierTest() throws SearchCrossReferenceException {
public void searchTestNoPatientFoundException() {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("3b19b902-cfe8-11ea-87d0-0242ac130003");
sourceIdentifier.setValue("value");
PatientCrossReferenceSearchImpl patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(this.domainDao, patientCrossReferenceDAO);
PatientAliases patientAlias = patientCrossReferenceSearch.search(sourceIdentifier);
assertEquals(patientAlias.getMembers().size(),3);
sourceIdentifier.setSystemIdentifier("toto");
sourceIdentifier.setValue("PatientNotFound");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceSearch.search(sourceIdentifier));
assertEquals("Error in the sourceIdentifier : it doesn't match any Patient", exception.getMessage());
}
@Test
public void searchWithZeroPatientAliasesTest() throws SearchCrossReferenceException {
public void searchTestNoXRefFoundException() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("3b19b902-cfe8-11ea-87d0-0242ac130003");
sourceIdentifier.setValue("value");
PatientCrossReferenceDAO patientCrossReferenceDAO2 = Mockito.mock(PatientCrossReferenceDAOMock.class);
Mockito.when(patientCrossReferenceDAO2.searchForPatientAliasesInSourceIdentifier(sourceIdentifier)).thenReturn(new ArrayList<>());
PatientCrossReferenceSearchImpl patientCrossReferenceSearch = new PatientCrossReferenceSearchImpl(this.domainDao, patientCrossReferenceDAO2);
PatientAliases patientAlias = patientCrossReferenceSearch.search(sourceIdentifier);
assertEquals(patientAlias.getMembers().size(),0);
sourceIdentifier.setSystemIdentifier("toto");
sourceIdentifier.setValue("NoXCrossrefFound");
PatientAliases patientAliases = patientCrossReferenceSearch.search(sourceIdentifier);
Assert.assertEquals("The X-ref shall contain only the patient matching with the sourceIdentifier, no cross ref has been found ", 1,
patientAliases.getMembers().size());
Assert.assertEquals("The X-ref shall contain only the patient matching with the sourceIdentifier, the uuid shall be : NoCrossRef",
patientAliases.getMembers().get(0).getUuid(), "NoCrossRef");
}
}
class DomainServiceMock implements DomainService {
@Test
public void searchTestXUniqueCrossRefFound() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("toto");
sourceIdentifier.setValue("1CrossFound");
PatientAliases patientAliases = patientCrossReferenceSearch.search(sourceIdentifier);
for (Patient patient : patientAliases.getMembers()) {
if (patient.getUuid().equals("original")) {
fail();
}
}
Assert.assertEquals("The X-ref shall contain the patients matching with the sourceIdentifier, no cross ref has been found ", 3,
patientAliases.getMembers().size());
@Override
public boolean exist(String domainIdentifier) {
return domainIdentifier.equals("3b19b902-cfe8-11ea-87d0-0242ac130003");
}
@Override
public void createDomain(String domainIdentifier, String domainName) {
//Not used here
}
}
class PatientCrossReferenceDAOMock implements PatientCrossReferenceDAO {
@Override
public List<PatientAliases> searchForPatientAliasesInSourceIdentifier(EntityIdentifier sourceIdentifier) {
String uuid = "3b19b902-cfe8-11ea-87d0-0242ac130003";
String lastModifier = "toto";
Date lastModifierDateTime = new Date();
Patient patient1 = new Patient();
patient1.setUuid("TEST-uuid1");
PatientAliases patientAlias = new PatientAliases(uuid, lastModifier, lastModifierDateTime);
patientAlias.addMember(patient1);
String uuid2 = "11111111-cfe8-11ea-87d0-0242ac130003";
String lastModifier2 = "tata";
Date lastModifierDateTime2 = new Date();
Patient patient2 = new Patient();
patient2.setUuid("TEST-uuid2");
PatientAliases patientAlias2 = new PatientAliases(uuid2, lastModifier2, lastModifierDateTime2);
patientAlias2.addMember(patient2);
String uuid3 = "22222222-cfe8-11ea-87d0-0242ac130003";
String lastModifier3 = "tutu";
Date lastModifierDateTime3 = new Date();
Patient patient3 = new Patient();
patient3.setUuid("TEST-uuid3");
PatientAliases patientAlias3 = new PatientAliases(uuid3, lastModifier3, lastModifierDateTime3);
patientAlias3.addMember(patient1);
patientAlias3.addMember(patient2);
patientAlias3.addMember(patient3);
List<PatientAliases> patientAliases = new ArrayList<>();
patientAliases.add(patientAlias);
patientAliases.add(patientAlias2);
patientAliases.add(patientAlias3);
return patientAliases;
@Test
public void searchTestMultipleCrossRefFound() throws SearchCrossReferenceException {
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("toto");
sourceIdentifier.setValue("3CrossFound");
PatientAliases patientAliases = patientCrossReferenceSearch.search(sourceIdentifier);
for (Patient patient : patientAliases.getMembers()) {
if (patient.getUuid().equals("original3")) {
fail();
}
}
Assert.assertEquals("The X-ref shall contain the patients matching with the sourceIdentifier, no cross ref has been found ", 9,
patientAliases.getMembers().size());
}
}
}
\ No newline at end of file
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