Commit eafab500 authored by Matthieu Bonnouvrier's avatar Matthieu Bonnouvrier
Browse files

Add TUs

parent d63101f9
Pipeline #262933 canceled with stages
in 3 minutes and 33 seconds
...@@ -64,9 +64,12 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO { ...@@ -64,9 +64,12 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
throw new IllegalArgumentException("The uuid of patientDB shall not be null"); throw new IllegalArgumentException("The uuid of patientDB shall not be null");
} }
TypedQuery<CrossReferenceDB> queryForPatientAliases = entityManager.createNamedQuery("CrossReferenceDB.findByCrossRefId", CrossReferenceDB.class); TypedQuery<CrossReferenceDB> queryForPatientAliases = entityManager.createNamedQuery("CrossReferenceDB.findByCrossRefId", CrossReferenceDB.class);
System.out.println("searchForPatientAliasesWithPatientDB");
System.out.println(patientDB.getPixReference());
System.out.println(patientDB.getPixReference().getId());
queryForPatientAliases.setParameter("pixReference", patientDB.getPixReference().getId()); queryForPatientAliases.setParameter("pixReference", patientDB.getPixReference().getId());
List<CrossReferenceDB> crossReferenceDBS = queryForPatientAliases.getResultList(); List<CrossReferenceDB> crossReferenceDBS = queryForPatientAliases.getResultList();
if (crossReferenceDBS.isEmpty()) { if (crossReferenceDBS.isEmpty() || crossReferenceDBS.get(0).getPatients().isEmpty()) {
throw new SearchCrossReferenceException("Search error : No X-ref for given Patient"); throw new SearchCrossReferenceException("Search error : No X-ref for given Patient");
} }
return crossReferenceDBS; return crossReferenceDBS;
......
...@@ -2,9 +2,6 @@ package net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.serv ...@@ -2,9 +2,6 @@ package net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.serv
import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException; import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier; import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.GenderCode;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.converter.PatientConverter;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.GenderCodeDB; import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.GenderCodeDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.HierarchicDesignatorDB; import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.HierarchicDesignatorDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB; import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB;
...@@ -22,7 +19,6 @@ import org.junit.jupiter.api.TestInstance; ...@@ -22,7 +19,6 @@ import org.junit.jupiter.api.TestInstance;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.Persistence; import javax.persistence.Persistence;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -74,10 +70,10 @@ public class PatientCrossReferenceDAOImplTest { ...@@ -74,10 +70,10 @@ public class PatientCrossReferenceDAOImplTest {
entityManager.close(); entityManager.close();
} }
@Test @Test
void testNullEntityManager() { void testNullEntityManager() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new PatientCrossReferenceDAOImpl(null)); IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new PatientCrossReferenceDAOImpl(null));
assertEquals("EntityManager cannot be null", exception.getMessage()); assertEquals("EntityManager cannot be null", exception.getMessage());
} }
...@@ -109,12 +105,23 @@ public class PatientCrossReferenceDAOImplTest { ...@@ -109,12 +105,23 @@ public class PatientCrossReferenceDAOImplTest {
} }
@Test @Test
void testEmptyCrossReference() { void testEmptyCrossReference() throws SearchCrossReferenceException {
PatientDB patientDB = new PatientDB(); EntityIdentifier entityIdentifier = new EntityIdentifier();
patientDB.setUuid("1234"); entityIdentifier.setSystemIdentifier("3333");
entityIdentifier.setValue("7777");
PatientDB patientDB = patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier);
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB)); () -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("No PatientAliases found with given patient", exception.getMessage()); assertEquals("Search error : No X-ref for given Patient", exception.getMessage());
}
@Test
void testAllValid3() throws SearchCrossReferenceException {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("1111");
entityIdentifier.setValue("1235");
PatientDB patientDB = patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier);
patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB);
} }
@Test @Test
...@@ -190,17 +197,6 @@ public class PatientCrossReferenceDAOImplTest { ...@@ -190,17 +197,6 @@ public class PatientCrossReferenceDAOImplTest {
assertEquals("Patient not found with with corresponding PatientIdentifier", exception.getMessage()); assertEquals("Patient not found with with corresponding PatientIdentifier", exception.getMessage());
} }
@Test
void testAllValid() throws SearchCrossReferenceException {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("1111");
entityIdentifier.setValue("1235");
PatientDB patientDB = patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier);
System.out.println("test");
//TODO assert
}
private static void initializeDb(EntityManager entityManager) { private static void initializeDb(EntityManager entityManager) {
HierarchicDesignatorDB hierarchicDesignatorDB = new HierarchicDesignatorDB(); HierarchicDesignatorDB hierarchicDesignatorDB = new HierarchicDesignatorDB();
hierarchicDesignatorDB.setUniversalID("1111"); hierarchicDesignatorDB.setUniversalID("1111");
...@@ -227,7 +223,11 @@ public class PatientCrossReferenceDAOImplTest { ...@@ -227,7 +223,11 @@ public class PatientCrossReferenceDAOImplTest {
patientIdentifierDB2.setIdentifier("1236"); patientIdentifierDB2.setIdentifier("1236");
PatientIdentifierDB patientIdentifierDB2merged = entityManager.merge(patientIdentifierDB2); PatientIdentifierDB patientIdentifierDB2merged = entityManager.merge(patientIdentifierDB2);
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); PatientIdentifierDB patientIdentifierDB3 = new PatientIdentifierDB();
patientIdentifierDB3.setDomain(hierarchicDesignatorDB6);
patientIdentifierDB3.setIdentifier("7777");
PatientIdentifierDB patientIdentifierDB3merged = entityManager.merge(patientIdentifierDB3);
PatientDB patient1 = new PatientDB(); PatientDB patient1 = new PatientDB();
patient1.setUuid("1235"); patient1.setUuid("1235");
patient1.setStillActive(true); patient1.setStillActive(true);
...@@ -248,23 +248,42 @@ public class PatientCrossReferenceDAOImplTest { ...@@ -248,23 +248,42 @@ public class PatientCrossReferenceDAOImplTest {
patient2.setPatientIdentifiers(patientIdentifierDBS2); patient2.setPatientIdentifiers(patientIdentifierDBS2);
PatientDB patient2m = entityManager.merge(patient2); PatientDB patient2m = entityManager.merge(patient2);
Patient patient3 = new Patient(); PatientDB patient3 = new PatientDB();
patient3.setUuid("1111"); patient3.setUuid("7777");
patient3.setActive(false); patient3.setStillActive(false);
patient3.setGender(GenderCode.MALE); patient3.setGenderCode(GenderCodeDB.M);
PatientDB patient3m = entityManager.merge(PatientConverter.toPatientDB(patient3)); patient2.setLastName("Noah");
List<PatientIdentifierDB> patientIdentifierDBS3 = new ArrayList<>();
patientIdentifierDBS3.add(patientIdentifierDB3merged);
patient3.setPatientIdentifiers(patientIdentifierDBS3);
PatientDB patient3m = entityManager.merge(patient3);
List<PatientDB> patientDBS = new ArrayList<>(); List<PatientDB> patientDBS = new ArrayList<>();
patientDBS.add(patient1m); patientDBS.add(patient1m);
patientDBS.add(patient2m); patientDBS.add(patient2m);
patientDBS.add(patient3m);
CrossReferenceDB crossReferenceDB = new CrossReferenceDB(); CrossReferenceDB crossReferenceDB = new CrossReferenceDB();
crossReferenceDB.setLastModifier("fde"); crossReferenceDB.setLastModifier("fde");
crossReferenceDB.setPatients(patientDBS); crossReferenceDB.setPatients(patientDBS);
entityManager.persist(crossReferenceDB); entityManager.persist(crossReferenceDB);
CrossReferenceDB crossReferenceDBMerged = entityManager.merge(crossReferenceDB); CrossReferenceDB crossReferenceDBMerged = entityManager.merge(crossReferenceDB);
patient1m.setPixReference(crossReferenceDBMerged);
entityManager.merge(patient1m);
patient2m.setPixReference(crossReferenceDBMerged);
entityManager.merge(patient2m);
CrossReferenceDB crossReferenceDB2 = new CrossReferenceDB();
crossReferenceDB2.setLastModifier("mbr");
entityManager.persist(crossReferenceDB2);
entityManager.merge(crossReferenceDB2);
CrossReferenceDB crossReferenceDB3 = new CrossReferenceDB();
crossReferenceDB3.setLastModifier("mbr2");
crossReferenceDB3.setPatients(new ArrayList<>());
patient3m.setPixReference(crossReferenceDB3);
entityManager.merge(patient3m);
} }
} }
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