Commit 92188425 authored by Franck Desaize's avatar Franck Desaize
Browse files

Fix issues with targetDomain in the case of empty list

parent 57c8ffae
Pipeline #267534 failed with stages
in 7 minutes and 1 second
......@@ -20,26 +20,28 @@ public class PatientAliasesConverter {
}
/**
* @param patientaliases
* @return
* Method to convert Patient Aliases to CrossReferenceDB
* @param patientAliases Xref object to be converted
* @return CrossReferenceDB
*/
public static CrossReferenceDB toCrossReferenceDB(PatientAliases patientaliases) {
public static CrossReferenceDB toCrossReferenceDB(PatientAliases patientAliases) {
CrossReferenceDB crossReferenceDB = new CrossReferenceDB();
List<PatientDB> patientDB = new ArrayList<>();
for (Patient patient : patientaliases.getMembers()) {
for (Patient patient : patientAliases.getMembers()) {
patientDB.add(PatientConverter.toPatientDB(patient));
}
crossReferenceDB.setPatients(patientDB);
crossReferenceDB.setLastModifier(patientaliases.getLastModifier());
crossReferenceDB.setLastChanged(patientaliases.getLastModifierDateTime());
crossReferenceDB.setLastModifier(patientAliases.getLastModifier());
crossReferenceDB.setLastChanged(patientAliases.getLastModifierDateTime());
return crossReferenceDB;
}
/**
* @param crossReferenceDB
* @return
* Method to convert CrossReferenceDB to Patient Aliases
* @param crossReferenceDB to be converted
* @return PatientAliases
*/
public static PatientAliases toPatientAliases(CrossReferenceDB crossReferenceDB) {
PatientAliases patientaliases = new PatientAliases();
......@@ -55,6 +57,11 @@ public class PatientAliasesConverter {
return patientaliases;
}
/**
* Convert a list of PatientAliases
* @param crossReferenceDBS list to convert
* @return List<PatientAliases>
*/
public static List<PatientAliases> toListOfPatientAliases(List<CrossReferenceDB> crossReferenceDBS){
List<PatientAliases> patientAliases = new ArrayList<>();
crossReferenceDBS.forEach(crossReference -> {
......
......@@ -2,9 +2,7 @@ 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.PatientAliases;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.EntityManagerProducer;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.converter.PatientAliasesConverter;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.DesignatorTypeDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.HierarchicDesignatorDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB;
......@@ -15,9 +13,7 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.TypedQuery;
import java.util.ArrayList;
import java.util.List;
@Named("PatientCrossReferenceDAO")
......@@ -47,8 +43,8 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
* The request need to go through HierarchicDesignatorDB => PatientIdentifierDB => PatientDB
*
* @param entityIdentifier
* @return
* @throws SearchCrossReferenceException
* @return PatientDB
* @throws SearchCrossReferenceException if an error occurred during the search
*/
@Override
public PatientDB searchForPatientDBWithSourceIdentifier(EntityIdentifier entityIdentifier) throws SearchCrossReferenceException {
......@@ -60,16 +56,16 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
PatientIdentifierDB patientIdentifier = searchForPatientIdentifier(hierarchicDesignatorDB, idNumber);
PatientDB patientDB = searchforPatient(patientIdentifier);
PatientDB patientDB = searchForPatient(patientIdentifier);
return patientDB;
}
/**
* Search for a list of patientAliases by its patient cross reference id
*
* @param patientDB
* @return
* @throws SearchCrossReferenceException
* @param patientDB retrieve a list of XREf matching with a patient
* @return List<CrossReferenceDB>
* @throws SearchCrossReferenceException if an error occurred during the search
*/
@Override
public List<CrossReferenceDB> searchForPatientAliasesWithPatientDB(PatientDB patientDB) throws SearchCrossReferenceException {
......@@ -97,8 +93,8 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
* - has mandatory variables missing
* - is unknown
*
* @param entityIdentifier
* @throws SearchCrossReferenceException
* @param entityIdentifier Check the content of the sourceIdentifier
* @throws SearchCrossReferenceException if an error occurred
*/
private void checkSourceIdentifier(EntityIdentifier entityIdentifier) throws SearchCrossReferenceException {
if (entityIdentifier == null) {
......@@ -117,9 +113,9 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
/**
* Search for a HierarchicDesignatorDB given a system identifier
*
* @param systemIdentifier
* @return
* @throws SearchCrossReferenceException
* @param systemIdentifier to be check
* @return HierarchicDesignatorDB matching to the systemIdentifier
* @throws SearchCrossReferenceException if an error occurred during the search
*/
private HierarchicDesignatorDB searchForHierarchicDesignator(String systemIdentifier) throws SearchCrossReferenceException {
try {
......@@ -136,10 +132,10 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
/**
* search for a PatientIdentifierDB given its HierarchicDesignatorDB and its id_number
*
* @param hierarchicDesignatorDB
* @param idNumber
* @return
* @throws SearchCrossReferenceException
* @param hierarchicDesignatorDB to check and retrieve
* @param idNumber of the patient in the system
* @return PatientIdentifierDB
* @throws SearchCrossReferenceException if an error occurred during the search
*/
private PatientIdentifierDB searchForPatientIdentifier(HierarchicDesignatorDB hierarchicDesignatorDB, String idNumber) throws SearchCrossReferenceException {
try {
......@@ -155,11 +151,11 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
/**
* Search for a PatientDB given its PatientIdentifierDB
*
* @param patientIdentifier
* @return
* @throws SearchCrossReferenceException
* @param patientIdentifier of the target patient
* @return PatientDB matching the patient identifier
* @throws SearchCrossReferenceException if an error occurred during the search
*/
private PatientDB searchforPatient(PatientIdentifierDB patientIdentifier) throws SearchCrossReferenceException {
private PatientDB searchForPatient(PatientIdentifierDB patientIdentifier) throws SearchCrossReferenceException {
try {
String patient_identifier = patientIdentifier.getIdentifier();
TypedQuery<PatientDB> queryForAPatient = entityManager.createNamedQuery("PatientDB.findByPatientIdentifier", PatientDB.class);
......
......@@ -37,8 +37,8 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
* Any patient from that patient alias that do not match the list of target domain will be deleted
*
* @param sourceIdentifier the search key
* @return
* @throws SearchCrossReferenceException
* @return PatientAliases corresponding to the given parameters
* @throws SearchCrossReferenceException if an error occurred during the search
*/
@Override
public PatientAliases search(EntityIdentifier sourceIdentifier, List<String> targetDomains) throws SearchCrossReferenceException {
......@@ -62,6 +62,8 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
throw new SearchCrossReferenceException("Error in the sourceIdentifier : it does not match any Patient");
case "Search error : No X-ref for given Patient":
return convertPatientDBToPatientAliases(patientDB);
default:
throw searchCrossReferenceException;
}
} catch (Exception exception) {
throw new SearchCrossReferenceException("An error occurred during CrossReference Search", exception);
......@@ -80,9 +82,9 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
/**
* Delete every patient (of a patient aliases) where its uuid does not match the system identifier of any target domain currently in the list
*
* @param patientAlias
* @param targetDomains
* @return
* @param patientAlias to be filtered by target system
* @param targetDomains to filter
* @return filtered PatientAliases matching target domains
*/
private PatientAliases removePatientFromPatientAliasWithNonMatchingTargetDomain(PatientAliases patientAlias, List<String> targetDomains) {
......@@ -102,9 +104,9 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
* Check if the list of target domain contains the current source identifier
* Return true if the list is not empty, false otherwise
*
* @param targetDomains
* @retur usableTargetDomains
* @throws SearchCrossReferenceException
* @param targetDomains to be check
* @return usableTargetDomains
* @throws SearchCrossReferenceException if an error occurred
*/
private boolean checkTargetDomains(List<String> targetDomains) throws SearchCrossReferenceException {
if (targetDomains == null || targetDomains.isEmpty()) {
......@@ -126,8 +128,8 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
* - has mandatory variables missing
* - is unknown
*
* @param sourceIdentifier
* @throws SearchCrossReferenceException
* @param sourceIdentifier to check its content
* @throws SearchCrossReferenceException if source identifier doesn't contain mandatory field
*/
private void checkSourceIdentifier(EntityIdentifier sourceIdentifier) throws SearchCrossReferenceException {
if (sourceIdentifier == null) {
......@@ -144,9 +146,9 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
}
/**
* @param crossReferenceDBS
* @param patientDB
* @return PatientAliases
* @param crossReferenceDBS XRef list return by DAO
* @param patientDB Patient matching the source identifier
* @return PatientAliases filtered patientAliases
*/
private PatientAliases processingOnResult(List<CrossReferenceDB> crossReferenceDBS, PatientDB patientDB) {
List<CrossReferenceDB> cleanListOfXRef = deleteKnownPatientInCrossReference(patientDB, crossReferenceDBS);
......@@ -164,10 +166,10 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
}
/**
* Convert
* Convert patient DB in case of no matching X-ref
*
* @param patientDB
* @return
* @param patientDB from DB
* @return result from DB in a PatientAliases
*/
private PatientAliases convertPatientDBToPatientAliases(PatientDB patientDB) {
PatientAliases patientAliases = new PatientAliases();
......
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