Commit 93ce7b05 authored by Franck Desaize's avatar Franck Desaize
Browse files

TUs DAO

parent 6cfce0a5
Pipeline #262472 failed with stages
in 4 minutes and 23 seconds
......@@ -6,10 +6,7 @@ import net.ihe.gazelle.app.patientregistryapi.business.GenderCode;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryapi.business.PersonName;
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.HierarchicDesignatorDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientIdentifierDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.*;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.references.CrossReferenceDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.PatientCrossReferenceDAO;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.PatientCrossReferenceDAOImpl;
......@@ -33,9 +30,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
public class PatientCrossReferenceDAOImplTest {
private static final String PERSISTENCE_UNIT_NAME_CONST = "PersistenceUnitTest";
private static PatientCrossReferenceDAO patientCrossReferenceDAO;
private PatientCrossReferenceDAO patientCrossReferenceDAO;
private static EntityManager entityManager;
private EntityManager entityManager;
/**
* database init
......@@ -47,10 +44,12 @@ public class PatientCrossReferenceDAOImplTest {
}
@BeforeAll
public static void startup()throws ParseException {
public void startup() throws ParseException {
entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME_CONST).createEntityManager();
patientCrossReferenceDAO = new PatientCrossReferenceDAOImpl(entityManager);
System.out.println("initializeEntityManager");
addTestEntitiesToDB(entityManager);
System.out.println("addTestEntitiesToDB");
}
/**
......@@ -99,13 +98,13 @@ public class PatientCrossReferenceDAOImplTest {
//
// assertEquals("The source identifier is unknown", exception.getMessage());
// }
@Test
void testNoHierarchicDesignatorDB(){
void testNoHierarchicDesignatorDB() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceDAO.searchForPatientAliasesInSourceIdentifier(entityIdentifier));
}
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
}
@Test
public void testEntityManager() {
......@@ -136,7 +135,7 @@ public class PatientCrossReferenceDAOImplTest {
entityManager.merge(patientIdentifierDB);
}
private static void addTestEntitiesToDB(EntityManager entityManager) throws ParseException {
private void addTestEntitiesToDB(EntityManager entityManager) throws ParseException {
initializeDb(entityManager);
// List<Patient> patientObjects = generatePatient();
// List<PatientDB> patientDBObjects = convertPatientToPatientDB(patientObjects);
......@@ -249,75 +248,124 @@ public class PatientCrossReferenceDAOImplTest {
return crossReferenceDB;
}
private List<PatientDB> convertPatientToPatientDB(List<Patient> patients) {
List<PatientDB> patientDBObjects = new ArrayList<>();
for (Patient patient : patients) {
PatientDB patientDB = PatientConverter.toPatientDB(patient);
patientDBObjects.add(patientDB);
}
return patientDBObjects;
}
private void initializeDb(EntityManager entityManager) {
private static void initializeDb(EntityManager entityManager) {
// Create HierarchicDesignatorDB
HierarchicDesignatorDB hierarchicDesignatorDB = new HierarchicDesignatorDB();
hierarchicDesignatorDB.setUniversalID("test");
hierarchicDesignatorDB.setUniversalIDType("ISO");
hierarchicDesignatorDB.setUniversalID("systemIdentifier1");
hierarchicDesignatorDB.setNamespaceID("systemName1");
hierarchicDesignatorDB.setUsage(DesignatorTypeDB.PATIENT_ID);
HierarchicDesignatorDB hierarchicDesignatorDBMerged = entityManager.merge(hierarchicDesignatorDB);
HierarchicDesignatorDB hierarchicDesignatorDB2 = entityManager.merge(hierarchicDesignatorDB);
HierarchicDesignatorDB hierarchicDesignatorDB2 = new HierarchicDesignatorDB();
hierarchicDesignatorDB2.setUniversalID("systemIdentifier2");
hierarchicDesignatorDB2.setNamespaceID("systemName2");
hierarchicDesignatorDB2.setUsage(DesignatorTypeDB.PATIENT_ID);
HierarchicDesignatorDB hierarchicDesignatorDB2Merged = entityManager.merge(hierarchicDesignatorDB2);
HierarchicDesignatorDB hierarchicDesignatorDB3 = new HierarchicDesignatorDB();
hierarchicDesignatorDB.setUniversalID("test2");
hierarchicDesignatorDB.setUniversalIDType("ISO");
HierarchicDesignatorDB hierarchicDesignatorDB4 = entityManager.merge(hierarchicDesignatorDB3);
hierarchicDesignatorDB3.setUniversalID("systemIdentifier3");
hierarchicDesignatorDB3.setNamespaceID("systemName3");
hierarchicDesignatorDB3.setUsage(DesignatorTypeDB.PATIENT_ID);
HierarchicDesignatorDB hierarchicDesignatorDB3Merged = entityManager.merge(hierarchicDesignatorDB3);
HierarchicDesignatorDB hierarchicDesignatorDB4 = new HierarchicDesignatorDB();
hierarchicDesignatorDB4.setUniversalID("systemIdentifier4");
hierarchicDesignatorDB4.setNamespaceID("systemName4");
hierarchicDesignatorDB4.setUsage(DesignatorTypeDB.PATIENT_ID);
HierarchicDesignatorDB hierarchicDesignatorDB4Merged = entityManager.merge(hierarchicDesignatorDB4);
HierarchicDesignatorDB hierarchicDesignatorDB5 = new HierarchicDesignatorDB();
hierarchicDesignatorDB5.setUniversalID("systemIdentifier4");
hierarchicDesignatorDB5.setNamespaceID("systemName4");
hierarchicDesignatorDB5.setUsage(DesignatorTypeDB.PATIENT_ID);
HierarchicDesignatorDB hierarchicDesignatorDB5Merged = entityManager.merge(hierarchicDesignatorDB5);
// Create PatientIdentifier
PatientIdentifierDB patientIdentifierDB = new PatientIdentifierDB();
patientIdentifierDB.setDomain(hierarchicDesignatorDB2);
patientIdentifierDB.setIdentifier("1234");
patientIdentifierDB.setDomain(hierarchicDesignatorDBMerged);
patientIdentifierDB.setIdentifier("patientID");
PatientIdentifierDB patientIdentifierDBMerged = entityManager.merge(patientIdentifierDB);
PatientIdentifierDB patientIdentifierDBmerged = entityManager.merge(patientIdentifierDB);
PatientIdentifierDB patientIdentifierDB2 = new PatientIdentifierDB();
patientIdentifierDB.setDomain(hierarchicDesignatorDB4);
patientIdentifierDB.setIdentifier("1234");
patientIdentifierDB2.setDomain(hierarchicDesignatorDB2Merged);
patientIdentifierDB2.setIdentifier("patientID2");
PatientIdentifierDB patientIdentifierDB2Merged = entityManager.merge(patientIdentifierDB2);
PatientIdentifierDB patientIdentifierDB2merged = entityManager.merge(patientIdentifierDB2);
// Patient from Same System
PatientIdentifierDB patientIdentifierDB2bis = new PatientIdentifierDB();
patientIdentifierDB2bis.setDomain(hierarchicDesignatorDB2Merged);
patientIdentifierDB2bis.setIdentifier("patientID2Bis");
PatientIdentifierDB patientIdentifierDB2bisMerged = entityManager.merge(patientIdentifierDB2bis);
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
PatientDB patient1 = new PatientDB();
patient1.setUuid("testUuid1");
patient1.setStillActive(true);
patient1.setGenderCode(GenderCodeDB.F);
PersonName personName = new PersonName();
personName.setFamily("Dupont");
personName.addGiven("Marie");
patient1.setLastName("Dupont");
List<PatientIdentifierDB> patientIdentifierDBS = new ArrayList<>();
patientIdentifierDBS.add(patientIdentifierDBmerged);
patient1.setPatientIdentifiers(patientIdentifierDBS);
PatientDB patient1m = entityManager.merge(patient1);
PatientIdentifierDB patientIdentifierDB3 = new PatientIdentifierDB();
patientIdentifierDB3.setDomain(hierarchicDesignatorDB3Merged);
patientIdentifierDB3.setIdentifier("patientID3");
PatientIdentifierDB patientIdentifierDB3Merged = entityManager.merge(patientIdentifierDB3);
Patient patient2 = new Patient();
patient2.setUuid("testUuid2");
patient2.setActive(false);
patient2.setGender(GenderCode.MALE);
PersonName personName2 = new PersonName();
personName2.setFamily("Martin");
personName2.addGiven("Pierre");
patient2.addName(personName2);
PatientIdentifierDB patientIdentifierDB4 = new PatientIdentifierDB();
patientIdentifierDB4.setDomain(hierarchicDesignatorDB4Merged);
patientIdentifierDB4.setIdentifier("patientID4");
PatientIdentifierDB patientIdentifierDB4Merged = entityManager.merge(patientIdentifierDB4);
PatientIdentifierDB patientIdentifierDB5 = new PatientIdentifierDB();
patientIdentifierDB5.setDomain(hierarchicDesignatorDBMerged);
patientIdentifierDB5.setIdentifier("patientID5");
PatientIdentifierDB patientIdentifierDB5Merged = entityManager.merge(patientIdentifierDB5);
PatientDB patient2m = entityManager.merge(PatientConverter.toPatientDB(patient2));
List<PatientDB> patientDBS = new ArrayList<>();
patientDBS.add(patient1m);
patientDBS.add(patient2m);
// Create Patient Marie, no Cross ref but 2 systemIdentifier
PatientDB patientMarieSysA = new PatientDB();
patientMarieSysA.setUuid("testUuid1");
patientMarieSysA.setStillActive(true);
patientMarieSysA.setGenderCode(GenderCodeDB.F);
patientMarieSysA.setLastName("Dupont");
patientMarieSysA.setFirstName("Marie");
List<PatientIdentifierDB> patientIdentifierDBS = new ArrayList<>();
patientIdentifierDBS.add(patientIdentifierDBMerged);
patientIdentifierDBS.add(patientIdentifierDB2Merged);
patientMarieSysA.setPatientIdentifiers(patientIdentifierDBS);
PatientDB patientMarieSysAMerged = entityManager.merge(patientMarieSysA);
// Create Patient Pierre, 2 CrossRef but 1 systemIdentifier for each
PatientDB patientPierreSysB = new PatientDB();
patientPierreSysB.setUuid("testUuid2");
patientPierreSysB.setStillActive(true);
patientPierreSysB.setGenderCode(GenderCodeDB.M);
patientPierreSysB.setLastName("Dupont");
patientPierreSysB.setFirstName("Pierre");
patientIdentifierDBS = new ArrayList<>();
patientIdentifierDBS.add(patientIdentifierDB3Merged);
patientPierreSysB.setPatientIdentifiers(patientIdentifierDBS);
PatientDB patientPierreSysBMerged = entityManager.merge(patientPierreSysB);
PatientDB patientPierreSysC = new PatientDB();
patientPierreSysC.setUuid("testUuid3");
patientPierreSysC.setStillActive(true);
patientPierreSysC.setGenderCode(GenderCodeDB.M);
patientPierreSysC.setLastName("Dupont");
patientPierreSysC.setFirstName("Pierre");
patientIdentifierDBS = new ArrayList<>();
patientIdentifierDBS.add(patientIdentifierDB4Merged);
patientPierreSysC.setPatientIdentifiers(patientIdentifierDBS);
PatientDB patientPierreSysCMerged = entityManager.merge(patientPierreSysC);
List<PatientDB> patientDBSPierre = new ArrayList<>();
patientDBSPierre.add(patientPierreSysBMerged);
patientDBSPierre.add(patientPierreSysCMerged);
CrossReferenceDB crossReferenceDB = new CrossReferenceDB();
crossReferenceDB.setLastModifier("fde");
crossReferenceDB.setPatients(patientDBS);
crossReferenceDB.setPatients(patientDBSPierre);
entityManager.persist(crossReferenceDB);
}
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
}
}
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