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 {
throw new IllegalArgumentException("The uuid of patientDB shall not be null");
}
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());
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");
}
return crossReferenceDBS;
......
......@@ -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.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.HierarchicDesignatorDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB;
......@@ -22,7 +19,6 @@ import org.junit.jupiter.api.TestInstance;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
......@@ -74,10 +70,10 @@ public class PatientCrossReferenceDAOImplTest {
entityManager.close();
}
@Test
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());
}
......@@ -109,12 +105,23 @@ public class PatientCrossReferenceDAOImplTest {
}
@Test
void testEmptyCrossReference() {
PatientDB patientDB = new PatientDB();
patientDB.setUuid("1234");
void testEmptyCrossReference() throws SearchCrossReferenceException {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("3333");
entityIdentifier.setValue("7777");
PatientDB patientDB = patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier);
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> 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
......@@ -190,17 +197,6 @@ public class PatientCrossReferenceDAOImplTest {
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) {
HierarchicDesignatorDB hierarchicDesignatorDB = new HierarchicDesignatorDB();
hierarchicDesignatorDB.setUniversalID("1111");
......@@ -227,7 +223,11 @@ public class PatientCrossReferenceDAOImplTest {
patientIdentifierDB2.setIdentifier("1236");
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();
patient1.setUuid("1235");
patient1.setStillActive(true);
......@@ -248,23 +248,42 @@ public class PatientCrossReferenceDAOImplTest {
patient2.setPatientIdentifiers(patientIdentifierDBS2);
PatientDB patient2m = entityManager.merge(patient2);
Patient patient3 = new Patient();
patient3.setUuid("1111");
patient3.setActive(false);
patient3.setGender(GenderCode.MALE);
PatientDB patient3m = entityManager.merge(PatientConverter.toPatientDB(patient3));
PatientDB patient3 = new PatientDB();
patient3.setUuid("7777");
patient3.setStillActive(false);
patient3.setGenderCode(GenderCodeDB.M);
patient2.setLastName("Noah");
List<PatientIdentifierDB> patientIdentifierDBS3 = new ArrayList<>();
patientIdentifierDBS3.add(patientIdentifierDB3merged);
patient3.setPatientIdentifiers(patientIdentifierDBS3);
PatientDB patient3m = entityManager.merge(patient3);
List<PatientDB> patientDBS = new ArrayList<>();
patientDBS.add(patient1m);
patientDBS.add(patient2m);
patientDBS.add(patient3m);
CrossReferenceDB crossReferenceDB = new CrossReferenceDB();
crossReferenceDB.setLastModifier("fde");
crossReferenceDB.setPatients(patientDBS);
entityManager.persist(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