From f97c51009dd976f3dc172d20ac02a5f60ac9ed60 Mon Sep 17 00:00:00 2001
From: fde <franck.desaize@kereval.com>
Date: Thu, 9 Sep 2021 16:07:38 +0200
Subject: [PATCH] Fix small issues during qualif

---
 .../provider/ChPatientResourceProvider.java   |  18 +-
 .../provider/IhePatientResourceProvider.java  | 312 +++++++++---------
 .../application/PatientFeedClientTest.java    |  51 ---
 .../ChPatientResourceProviderTest.java        |  49 ++-
 .../IhePatientResourceProviderTest.java       |  41 ++-
 5 files changed, 226 insertions(+), 245 deletions(-)

diff --git a/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java b/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java
index 76f53fc..8d6a2e3 100644
--- a/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java
+++ b/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java
@@ -2,10 +2,7 @@ package net.ihe.gazelle.business.provider;
 
 import ca.uhn.fhir.rest.annotation.*;
 import ca.uhn.fhir.rest.api.MethodOutcome;
-import ca.uhn.fhir.rest.param.StringAndListParam;
-import ca.uhn.fhir.rest.param.StringOrListParam;
-import ca.uhn.fhir.rest.param.StringParam;
-import ca.uhn.fhir.rest.param.TokenParam;
+import ca.uhn.fhir.rest.param.*;
 import ca.uhn.fhir.rest.server.IResourceProvider;
 import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
 import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@@ -210,7 +207,7 @@ public class ChPatientResourceProvider implements IResourceProvider {
      * @return a Parameter element composed of a list of target identifier for every Patient found, and an url to the Patient in the server.
      */
     @Operation(name = "$ihe-pix", idempotent = true)
-    public Parameters findPatientsByIdentifier(@OperationParam(name = "sourceIdentifier", min = 1, max = 1) TokenParam sourceIdentifierParam,
+    public Parameters findPatientsByIdentifier(@OperationParam(name = "sourceIdentifier", min = 1, max = 1) TokenAndListParam sourceIdentifierParam,
                                                @OperationParam(name = "targetSystem", min = 1, max = 2) StringAndListParam targetSystemParam) {
 
         EntityIdentifier sourceIdentifier = createEntityIdentifierFromSourceIdentifier(sourceIdentifierParam);
@@ -230,12 +227,15 @@ public class ChPatientResourceProvider implements IResourceProvider {
      * @param sourceIdentifier : the source Identifier to convert
      * @return An Entity Identifier understood by Patient Registry.
      */
-    private EntityIdentifier createEntityIdentifierFromSourceIdentifier(TokenParam sourceIdentifier) {
-        if (sourceIdentifier == null) {
+    private EntityIdentifier createEntityIdentifierFromSourceIdentifier(TokenAndListParam sourceIdentifier) {
+        if (sourceIdentifier == null || sourceIdentifier.size()==0 || sourceIdentifier.size()>1) {
             throw new InvalidRequestException(SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND);
         }
-        String sourceIdentifierSystem = sourceIdentifier.getSystem();
-        String sourceIdentifierValue = sourceIdentifier.getValue();
+        TokenOrListParam tokenOrListParams = sourceIdentifier.getValuesAsQueryTokens().get(0);
+        TokenParam source = tokenOrListParams.getValuesAsQueryTokens().get(0);
+
+        String sourceIdentifierSystem = source.getSystem();
+        String sourceIdentifierValue = source.getValue();
         if (sourceIdentifierSystem == null) {
             patientLogger.error(INVALID_REQUEST_BAD_SOURCE_IDENTIFIER + " null system");
             throw new InvalidRequestException(SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND);
diff --git a/src/main/java/net/ihe/gazelle/business/provider/IhePatientResourceProvider.java b/src/main/java/net/ihe/gazelle/business/provider/IhePatientResourceProvider.java
index 64d33cb..554e006 100644
--- a/src/main/java/net/ihe/gazelle/business/provider/IhePatientResourceProvider.java
+++ b/src/main/java/net/ihe/gazelle/business/provider/IhePatientResourceProvider.java
@@ -1,27 +1,10 @@
 package net.ihe.gazelle.business.provider;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.apache.commons.lang3.StringUtils;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-import org.hl7.fhir.r4.model.IdType;
-import org.hl7.fhir.r4.model.Parameters;
-import org.hl7.fhir.r4.model.Patient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import ca.uhn.fhir.rest.annotation.IdParam;
 import ca.uhn.fhir.rest.annotation.Operation;
 import ca.uhn.fhir.rest.annotation.OperationParam;
 import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.param.StringAndListParam;
-import ca.uhn.fhir.rest.param.StringOrListParam;
-import ca.uhn.fhir.rest.param.StringParam;
-import ca.uhn.fhir.rest.param.TokenParam;
+import ca.uhn.fhir.rest.param.*;
 import ca.uhn.fhir.rest.server.IResourceProvider;
 import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
 import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@@ -33,6 +16,18 @@ import net.ihe.gazelle.application.PatientRegistrySearchClient;
 import net.ihe.gazelle.application.PatientRegistryXRefSearchClient;
 import net.ihe.gazelle.lib.annotations.Package;
 import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
+import org.apache.commons.lang3.StringUtils;
+import org.hl7.fhir.instance.model.api.IBaseResource;
+import org.hl7.fhir.r4.model.IdType;
+import org.hl7.fhir.r4.model.Parameters;
+import org.hl7.fhir.r4.model.Patient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * This is a resource provider which stores Patient resources in memory using a HashMap. This is obviously not a production-ready solution for many
@@ -41,144 +36,147 @@ import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
  */
 @Named("ihePatientResourceProvider")
 public class IhePatientResourceProvider implements IResourceProvider {
-	private static final String URN_OID = "urn:oid:";
-	public static final String INVALID_REQUEST_BAD_SOURCE_IDENTIFIER = "Invalid request : bad sourceIdentifier";
-	private static final Logger patientLogger = LoggerFactory.getLogger(IhePatientResourceProvider.class);
-	public static final String SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND = "sourceIdentifier Patient Identifier not found";
-	public static final String SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND = "sourceIdentifier Assigning Authority not found";
-	public static final String TARGET_SYSTEM_NOT_FOUND = "targetSystem not found";
-	public static final String NO_ID_PROVIDED = "No ID provided";
-
-	@Inject
-	private PatientRegistryXRefSearchClient patientRegistryXRefSearchClient;
-
-	@Inject
-	private PatientRegistrySearchClient patientRegistrySearchClient;
-
-	/**
-	 * The getResourceType method comes from IResourceProvider, and must be overridden to indicate what type of resource this provider supplies.
-	 */
-	@Override
-	public Class<? extends IBaseResource> getResourceType() {
-		return Patient.class;
-	}
-
-	public IhePatientResourceProvider() {
-	}
-
-	@Package
-	public IhePatientResourceProvider(PatientRegistryXRefSearchClient client) {
-		this.patientRegistryXRefSearchClient = client;
-	}
-
-	@Package
-	public IhePatientResourceProvider(PatientRegistrySearchClient client) {
-		this.patientRegistrySearchClient = client;
-	}
-
-	/**
-	 * Method to read a Patient through its uuid in the patient Manager database
-	 *
-	 * @param theId : Id Type given in the url. represents the uuid of the searched patient
-	 * @return One patient corresponding to the uuid given in entry. If many Patients are found, we consider it as an error and won't return ANY
-	 * patient.
-	 */
-	@Read
-	public Patient read(@IdParam IdType theId) {
-		if (StringUtils.isBlank(theId.getIdPart())) {
-			patientLogger.error(NO_ID_PROVIDED);
-			throw new InvalidRequestException(NO_ID_PROVIDED);
-		}
-		String uuid = theId.getIdPart();
-		try {
-			Patient retrievedPatient = patientRegistrySearchClient.searchPatient(uuid);
-			patientLogger.info("Patient Successfully found");
-			return retrievedPatient;
-		} catch (SearchException e) {
-			throw new InternalErrorException("Patient could not be retrieved", e);
-		}
-
-	}
-
-	/**
-	 * Search method for a Patient using the source identifier required parameter
-	 * and an optional list of target system
-	 *
-	 * @param sourceIdentifierParam : the source identifier of the patient, should be formatted "urn:oid:x.x.x.x.x.x.x.x.x.x|value"
-	 * @param targetSystemParam:    the target System(s) we want to find the Patient on, should be formatted "urn:oid:x.x.x.x.x.x.x.x.x.x,
-	 * 								urn:oid:x.x.x.x.x.x.x.x.x.x"
-	 * @return a Parameters element composed of a list of target identifier for every Patient found, and an url to the Patient in the server.
-	 */
-	@Operation(name = "$ihe-pix", idempotent = true)
-	public Parameters findPatientsByIdentifier(@OperationParam(name = "sourceIdentifier", min = 1, max = 1) TokenParam sourceIdentifierParam,
-			@OperationParam(name = "targetSystem") StringAndListParam targetSystemParam) {
-
-		EntityIdentifier sourceIdentifier = createEntityIdentifierFromSourceIdentifier(sourceIdentifierParam);
-		List<String> targetSystemList = createTargetSystemListFromParam(targetSystemParam);
-
-		Parameters parametersResults;
-		try {
-			parametersResults = patientRegistryXRefSearchClient.process(sourceIdentifier, targetSystemList);
-		} catch (SearchCrossReferenceException e) {
-			throw new InternalErrorException(e);
-		}
-
-		return parametersResults;
-	}
-
-	private EntityIdentifier createEntityIdentifierFromSourceIdentifier(TokenParam sourceIdentifier) {
-		if (sourceIdentifier == null) {
-			throw new InvalidRequestException(SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND);
-		}
-		String sourceIdentifierSystem = sourceIdentifier.getSystem();
-		String sourceIdentifierValue = sourceIdentifier.getValue();
-		if (sourceIdentifierSystem == null) {
-			patientLogger.error(INVALID_REQUEST_BAD_SOURCE_IDENTIFIER + " null system");
-			throw new InvalidRequestException(SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND);
-		}
-		if (sourceIdentifierValue == null) {
-			patientLogger.error(INVALID_REQUEST_BAD_SOURCE_IDENTIFIER + " null value");
-			throw new InvalidRequestException(SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND);
-		}
-		if (StringUtils.isBlank(sourceIdentifierSystem) || StringUtils.isBlank(sourceIdentifierValue)) {
-			patientLogger.error(INVALID_REQUEST_BAD_SOURCE_IDENTIFIER + " empty system or value");
-			throw new InvalidRequestException(SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND);
-		}
-		patientLogger.info("Searching Patient with given sourceIdentifier");
-
-		EntityIdentifier wellFormedEntityIdentifier = new EntityIdentifier();
-		if (sourceIdentifierSystem.contains(URN_OID)) {
-			wellFormedEntityIdentifier.setSystemIdentifier(sourceIdentifierSystem.replace(URN_OID, ""));
-			wellFormedEntityIdentifier.setType("ISO");
-			wellFormedEntityIdentifier.setValue(sourceIdentifierValue);
-		} else if (sourceIdentifierSystem.contains("http")) {
-			wellFormedEntityIdentifier.setSystemIdentifier(sourceIdentifierSystem);
-			wellFormedEntityIdentifier.setType("ISO");
-			wellFormedEntityIdentifier.setValue(sourceIdentifierValue);
-		} else {
-			throw new ResourceNotFoundException(SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND);
-		}
-		return wellFormedEntityIdentifier;
-	}
-
-	private List<String> createTargetSystemListFromParam(StringAndListParam targetSystemParam) {
-		List<String> targetSystemList = new ArrayList<>();
-		if (targetSystemParam != null) {
-			for (StringOrListParam listParam : targetSystemParam.getValuesAsQueryTokens()) {
-				List<StringParam> queryStrings = listParam.getValuesAsQueryTokens();
-				for (StringParam singleParam : queryStrings) {
-					String singleParamValue = singleParam.getValue();
-					if (singleParamValue.contains(URN_OID)) {
-						singleParamValue = singleParamValue.replace(URN_OID, "");
-					}
-					if (singleParamValue.equals("")) {
-						throw new ForbiddenOperationException(TARGET_SYSTEM_NOT_FOUND);
-					}
-					targetSystemList.add(singleParamValue);
-				}
-			}
-		}
-		return targetSystemList;
-	}
+    private static final String URN_OID = "urn:oid:";
+    public static final String INVALID_REQUEST_BAD_SOURCE_IDENTIFIER = "Invalid request : bad sourceIdentifier";
+    private static final Logger patientLogger = LoggerFactory.getLogger(IhePatientResourceProvider.class);
+    public static final String SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND = "sourceIdentifier Patient Identifier not found";
+    public static final String SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND = "sourceIdentifier Assigning Authority not found";
+    public static final String TARGET_SYSTEM_NOT_FOUND = "targetSystem not found";
+    public static final String NO_ID_PROVIDED = "No ID provided";
+
+    @Inject
+    private PatientRegistryXRefSearchClient patientRegistryXRefSearchClient;
+
+    @Inject
+    private PatientRegistrySearchClient patientRegistrySearchClient;
+
+    /**
+     * The getResourceType method comes from IResourceProvider, and must be overridden to indicate what type of resource this provider supplies.
+     */
+    @Override
+    public Class<? extends IBaseResource> getResourceType() {
+        return Patient.class;
+    }
+
+    public IhePatientResourceProvider() {
+    }
+
+    @Package
+    public IhePatientResourceProvider(PatientRegistryXRefSearchClient client) {
+        this.patientRegistryXRefSearchClient = client;
+    }
+
+    @Package
+    public IhePatientResourceProvider(PatientRegistrySearchClient client) {
+        this.patientRegistrySearchClient = client;
+    }
+
+    /**
+     * Method to read a Patient through its uuid in the patient Manager database
+     *
+     * @param theId : Id Type given in the url. represents the uuid of the searched patient
+     * @return One patient corresponding to the uuid given in entry. If many Patients are found, we consider it as an error and won't return ANY
+     * patient.
+     */
+    @Read
+    public Patient read(@IdParam IdType theId) {
+        if (StringUtils.isBlank(theId.getIdPart())) {
+            patientLogger.error(NO_ID_PROVIDED);
+            throw new InvalidRequestException(NO_ID_PROVIDED);
+        }
+        String uuid = theId.getIdPart();
+        try {
+            Patient retrievedPatient = patientRegistrySearchClient.searchPatient(uuid);
+            patientLogger.info("Patient Successfully found");
+            return retrievedPatient;
+        } catch (SearchException e) {
+            throw new InternalErrorException("Patient could not be retrieved", e);
+        }
+
+    }
+
+    /**
+     * Search method for a Patient using the source identifier required parameter
+     * and an optional list of target system
+     *
+     * @param sourceIdentifierParam : the source identifier of the patient, should be formatted "urn:oid:x.x.x.x.x.x.x.x.x.x|value"
+     * @param targetSystemParam:    the target System(s) we want to find the Patient on, should be formatted "urn:oid:x.x.x.x.x.x.x.x.x.x,
+     *                              urn:oid:x.x.x.x.x.x.x.x.x.x"
+     * @return a Parameters element composed of a list of target identifier for every Patient found, and an url to the Patient in the server.
+     */
+    @Operation(name = "$ihe-pix", idempotent = true)
+    public Parameters findPatientsByIdentifier(@OperationParam(name = "sourceIdentifier", min = 1, max = 1) TokenAndListParam sourceIdentifierParam,
+                                               @OperationParam(name = "targetSystem") StringAndListParam targetSystemParam) {
+
+        EntityIdentifier sourceIdentifier = createEntityIdentifierFromSourceIdentifier(sourceIdentifierParam);
+        List<String> targetSystemList = createTargetSystemListFromParam(targetSystemParam);
+
+        Parameters parametersResults;
+        try {
+            parametersResults = patientRegistryXRefSearchClient.process(sourceIdentifier, targetSystemList);
+        } catch (SearchCrossReferenceException e) {
+            throw new InternalErrorException(e);
+        }
+
+        return parametersResults;
+    }
+
+    private EntityIdentifier createEntityIdentifierFromSourceIdentifier(TokenAndListParam sourceIdentifier) {
+        if (sourceIdentifier == null || sourceIdentifier.size() == 0 || sourceIdentifier.size() > 1) {
+            throw new InvalidRequestException(SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND);
+        }
+        TokenOrListParam tokenOrListParams = sourceIdentifier.getValuesAsQueryTokens().get(0);
+        TokenParam source = tokenOrListParams.getValuesAsQueryTokens().get(0);
+
+        String sourceIdentifierSystem = source.getSystem();
+        String sourceIdentifierValue = source.getValue();
+        if (sourceIdentifierSystem == null) {
+            patientLogger.error(INVALID_REQUEST_BAD_SOURCE_IDENTIFIER + " null system");
+            throw new InvalidRequestException(SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND);
+        }
+        if (sourceIdentifierValue == null) {
+            patientLogger.error(INVALID_REQUEST_BAD_SOURCE_IDENTIFIER + " null value");
+            throw new InvalidRequestException(SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND);
+        }
+        if (StringUtils.isBlank(sourceIdentifierSystem) || StringUtils.isBlank(sourceIdentifierValue)) {
+            patientLogger.error(INVALID_REQUEST_BAD_SOURCE_IDENTIFIER + " empty system or value");
+            throw new InvalidRequestException(SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND);
+        }
+        patientLogger.info("Searching Patient with given sourceIdentifier");
+
+        EntityIdentifier wellFormedEntityIdentifier = new EntityIdentifier();
+        if (sourceIdentifierSystem.contains(URN_OID)) {
+            wellFormedEntityIdentifier.setSystemIdentifier(sourceIdentifierSystem.replace(URN_OID, ""));
+            wellFormedEntityIdentifier.setType("ISO");
+            wellFormedEntityIdentifier.setValue(sourceIdentifierValue);
+        } else if (sourceIdentifierSystem.contains("http")) {
+            wellFormedEntityIdentifier.setSystemIdentifier(sourceIdentifierSystem);
+            wellFormedEntityIdentifier.setType("ISO");
+            wellFormedEntityIdentifier.setValue(sourceIdentifierValue);
+        } else {
+            throw new ResourceNotFoundException(SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND);
+        }
+        return wellFormedEntityIdentifier;
+    }
+
+    private List<String> createTargetSystemListFromParam(StringAndListParam targetSystemParam) {
+        List<String> targetSystemList = new ArrayList<>();
+        if (targetSystemParam != null) {
+            for (StringOrListParam listParam : targetSystemParam.getValuesAsQueryTokens()) {
+                List<StringParam> queryStrings = listParam.getValuesAsQueryTokens();
+                for (StringParam singleParam : queryStrings) {
+                    String singleParamValue = singleParam.getValue();
+                    if (singleParamValue.contains(URN_OID)) {
+                        singleParamValue = singleParamValue.replace(URN_OID, "");
+                    }
+                    if (singleParamValue.equals("")) {
+                        throw new ForbiddenOperationException(TARGET_SYSTEM_NOT_FOUND);
+                    }
+                    targetSystemList.add(singleParamValue);
+                }
+            }
+        }
+        return targetSystemList;
+    }
 
 }
diff --git a/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java b/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java
index 0622b41..6467fe8 100644
--- a/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java
+++ b/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java
@@ -263,61 +263,10 @@ public class PatientFeedClientTest {
 		}
 	}
 
-	@Test
-	@Description("Test on create, for particular exceptions returned from PatientFeedApplication")
-	@Severity(SeverityLevel.CRITICAL)
-	@Story("create")
-	void TestFeedBlankNameOnCreation() throws PreferenceException, NamespaceException, PatientFeedException {
 
-		Patient patient = createPatient("","name",LocalDate.of(1990, 06, 19), GenderCode.MALE);
 
-		patientRegistryFeedClient = new PatientRegistryFeedClient();
-		patientRegistryFeedClient.setClient(patientFeedClientMock);
 
-		assertThrows(InvalidRequestException.class, () -> patientRegistryFeedClient.createPatient(patient));
-		try {
-			patientRegistryFeedClient.createPatient(patient);
-		} catch (InvalidRequestException e) {
-			assertEquals("Mandatory fields are missing", e.getMessage());
-		}
-	}
-
-	@Test
-	@Description("Test on create, for particular exceptions returned from PatientFeedApplication")
-	@Severity(SeverityLevel.CRITICAL)
-	@Story("create")
-	void TestFeedBlankGenderOnCreation() throws PreferenceException, NamespaceException, PatientFeedException {
-
-		Patient patient = createPatient("name","name",LocalDate.of(1990, 06, 19), null);
-
-		patientRegistryFeedClient = new PatientRegistryFeedClient();
-		patientRegistryFeedClient.setClient(patientFeedClientMock);
 
-		assertThrows(InvalidRequestException.class, () -> patientRegistryFeedClient.createPatient(patient));
-		try {
-			patientRegistryFeedClient.createPatient(patient);
-		} catch (InvalidRequestException e) {
-			assertEquals("Mandatory fields are missing", e.getMessage());
-		}
-	}
-
-
-	@Test
-	@Description("Test on update, when feeding basic request")
-	@Severity(SeverityLevel.CRITICAL)
-	@Story("update")
-	void TestFeedUpdateNominalCase() throws PreferenceException, NamespaceException, PatientFeedException {
-
-		String uuid = TEST_UUID;
-		Patient patient = createPatient("","",LocalDate.of(1990, 06, 19), GenderCode.MALE);
-
-		patientRegistryFeedClient = new PatientRegistryFeedClient();
-		patientRegistryFeedClient.setClient(patientFeedClientMock);
-
-		Mockito.doReturn(patient).when(patientFeedClientMock).updatePatient(anyObject());
-		assertEquals(uuid, patientRegistryFeedClient.updatePatient(patient, uuid).getEntry().get(0).getResource().getId());
-
-	}
 
 	@Test
 	@Description("Test on update, exception thrown when no Patient is given")
diff --git a/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java b/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java
index 33c9c29..9ff5dee 100644
--- a/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java
+++ b/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java
@@ -1,10 +1,7 @@
 package net.ihe.gazelle.business.provider;
 
 import ca.uhn.fhir.rest.api.MethodOutcome;
-import ca.uhn.fhir.rest.param.StringAndListParam;
-import ca.uhn.fhir.rest.param.StringOrListParam;
-import ca.uhn.fhir.rest.param.StringParam;
-import ca.uhn.fhir.rest.param.TokenParam;
+import ca.uhn.fhir.rest.param.*;
 import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
 import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
 import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@@ -40,12 +37,14 @@ class ChPatientResourceProviderTest {
 	@Story("ihe_pix operation")
 	void testOkPatient() {
 		TokenParam sourceId = new TokenParam("urn:oid:1", "69420");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam("urn:oid:2"));
 		targetDomains.addAnd(stringParam);
 
-		Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
+		Parameters response = provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		ParametersParameterComponent singleResponse = response.getParameter().get(0);
 		Identifier r4 = (Identifier) singleResponse.getValue();
 		assertEquals(PatientRegistryXRefSearchClientMock.URN_OK, r4.getValue());
@@ -59,12 +58,14 @@ class ChPatientResourceProviderTest {
 	@Story("ihe_pix operation")
 	void testOkPatientHttp() {
 		TokenParam sourceId = new TokenParam("http://1", "69420");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam("http://2"));
 		targetDomains.addAnd(stringParam);
 
-		Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
+		Parameters response = provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		ParametersParameterComponent singleResponse = response.getParameter().get(0);
 		Identifier r4 = (Identifier) singleResponse.getValue();
 		assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getValue());
@@ -78,13 +79,15 @@ class ChPatientResourceProviderTest {
 	@Story("ihe_pix operation")
 	void testOkPatientTwoTargetSystem() {
 		TokenParam sourceId = new TokenParam("http://1", "69420");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam("http://2"));
 		stringParam.add(new StringParam("http://3"));
 		targetDomains.addAnd(stringParam);
 
-		Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
+		Parameters response = provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		ParametersParameterComponent singleResponse = response.getParameter().get(0);
 		Identifier r4 = (Identifier) singleResponse.getValue();
 		assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getValue());
@@ -98,13 +101,15 @@ class ChPatientResourceProviderTest {
 	@Story("ihe_pix operation")
 	void testSourceIdentifierNull() {
 		TokenParam sourceId = new TokenParam();
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam("http://2"));
 		targetDomains.addAnd(stringParam);
 
 		try {
-			provider.findPatientsByIdentifier(sourceId, targetDomains);
+			provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		} catch (InvalidRequestException e) {
 			assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
 		}
@@ -118,13 +123,15 @@ class ChPatientResourceProviderTest {
 	void testSourceIdentifierSystemNull() {
 		TokenParam sourceId = new TokenParam();
 		sourceId.setValue("69420");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam("http://2"));
 		targetDomains.addAnd(stringParam);
 
 		try {
-			provider.findPatientsByIdentifier(sourceId, targetDomains);
+			provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		} catch (InvalidRequestException e) {
 			assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
 		}
@@ -138,13 +145,15 @@ class ChPatientResourceProviderTest {
 	void testSourceIdentifierValueNull() {
 		TokenParam sourceId = new TokenParam();
 		sourceId.setSystem("http://1");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam("http://2"));
 		targetDomains.addAnd(stringParam);
 
 		try {
-			provider.findPatientsByIdentifier(sourceId, targetDomains);
+			provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		} catch (InvalidRequestException e) {
 			assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND, e.getMessage());
 		}
@@ -157,13 +166,15 @@ class ChPatientResourceProviderTest {
 	@Story("ihe_pix operation")
 	void testSourceIdentifierSystemBlank() {
 		TokenParam sourceId = new TokenParam("", "69420");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam("http://2"));
 		targetDomains.addAnd(stringParam);
 
 		try {
-			provider.findPatientsByIdentifier(sourceId, targetDomains);
+			provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		} catch (InvalidRequestException e) {
 			assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND, e.getMessage());
 		}
@@ -176,13 +187,15 @@ class ChPatientResourceProviderTest {
 	@Story("ihe_pix operation")
 	void testMalformedSystemIdentifier() {
 		TokenParam sourceId = new TokenParam("1:2:3", "69420");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam("http://2"));
 		targetDomains.addAnd(stringParam);
 
 		try {
-			provider.findPatientsByIdentifier(sourceId, targetDomains);
+			provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		} catch (ResourceNotFoundException e) {
 			assertEquals(ChPatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
 		}
@@ -195,13 +208,15 @@ class ChPatientResourceProviderTest {
 	@Story("ihe_pix operation")
 	void testTargetIdentifierBlank() {
 		TokenParam sourceId = new TokenParam("http::/1", "69420");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam(""));
 		targetDomains.addAnd(stringParam);
 
 		try {
-			provider.findPatientsByIdentifier(sourceId, targetDomains);
+			provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		} catch (ForbiddenOperationException e) {
 			assertEquals(ChPatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
 		}
@@ -213,12 +228,14 @@ class ChPatientResourceProviderTest {
 	@Story("ihe_pix operation")
 	void testTargetIdentifierNull() {
 		TokenParam sourceId = new TokenParam("http::/1", "69420");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		targetDomains.addAnd(stringParam);
 
 		try {
-			provider.findPatientsByIdentifier(sourceId, targetDomains);
+			provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		} catch (ForbiddenOperationException e) {
 			assertEquals(ChPatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
 		}
@@ -230,6 +247,8 @@ class ChPatientResourceProviderTest {
 	@Story("ihe_pix operation")
 	void testTargetIdentifierMoreThanTwo() {
 		TokenParam sourceId = new TokenParam("http::/1", "69420");
+		TokenAndListParam tokenAndListParam = new TokenAndListParam();
+		tokenAndListParam.addAnd(sourceId);
 		StringAndListParam targetDomains = new StringAndListParam();
 		StringOrListParam stringParam = new StringOrListParam();
 		stringParam.add(new StringParam("http://2"));
@@ -238,7 +257,7 @@ class ChPatientResourceProviderTest {
 		targetDomains.addAnd(stringParam);
 
 		try {
-			provider.findPatientsByIdentifier(sourceId, targetDomains);
+			provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
 		} catch (ForbiddenOperationException e) {
 			assertEquals(ChPatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
 		}
diff --git a/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java b/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java
index 285d141..ad50c47 100644
--- a/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java
+++ b/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java
@@ -1,9 +1,6 @@
 package net.ihe.gazelle.business.provider;
 
-import ca.uhn.fhir.rest.param.StringAndListParam;
-import ca.uhn.fhir.rest.param.StringOrListParam;
-import ca.uhn.fhir.rest.param.StringParam;
-import ca.uhn.fhir.rest.param.TokenParam;
+import ca.uhn.fhir.rest.param.*;
 import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
 import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
 import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@@ -38,12 +35,14 @@ class IhePatientResourceProviderTest {
     @Story("ihe_pix operation")
     void testOkPatient() {
         TokenParam sourceId = new TokenParam("urn:oid:1", "69420");
+        TokenAndListParam tokenAndListParam = new TokenAndListParam();
+        tokenAndListParam.addAnd(sourceId);
         StringAndListParam targetDomains = new StringAndListParam();
         StringOrListParam stringParam = new StringOrListParam();
         stringParam.add(new StringParam("urn:oid:2"));
         targetDomains.addAnd(stringParam);
 
-        Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
+        Parameters response = provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
         ParametersParameterComponent singleResponse = response.getParameter().get(0);
         Identifier r4 = (Identifier) singleResponse.getValue();
         assertEquals(PatientRegistryXRefSearchClientMock.URN_OK, r4.getValue());
@@ -57,12 +56,14 @@ class IhePatientResourceProviderTest {
     @Story("ihe_pix operation")
     void testOkPatientHttp() {
         TokenParam sourceId = new TokenParam("http://1", "69420");
+        TokenAndListParam tokenAndListParam = new TokenAndListParam();
+        tokenAndListParam.addAnd(sourceId);
         StringAndListParam targetDomains = new StringAndListParam();
         StringOrListParam stringParam = new StringOrListParam();
         stringParam.add(new StringParam("http://2"));
         targetDomains.addAnd(stringParam);
 
-        Parameters response = provider.findPatientsByIdentifier(sourceId, targetDomains);
+        Parameters response = provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
         ParametersParameterComponent singleResponse = response.getParameter().get(0);
         Identifier r4 = (Identifier) singleResponse.getValue();
         assertEquals(PatientRegistryXRefSearchClientMock.HTTP_OK, r4.getValue());
@@ -76,13 +77,15 @@ class IhePatientResourceProviderTest {
     @Story("ihe_pix operation")
     void testSourceIdentifierNull() {
         TokenParam sourceId = new TokenParam();
+        TokenAndListParam tokenAndListParam = new TokenAndListParam();
+        tokenAndListParam.addAnd(sourceId);
         StringAndListParam targetDomains = new StringAndListParam();
         StringOrListParam stringParam = new StringOrListParam();
         stringParam.add(new StringParam("http://2"));
         targetDomains.addAnd(stringParam);
 
         try {
-            provider.findPatientsByIdentifier(sourceId, targetDomains);
+            provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
         } catch (InvalidRequestException e) {
             assertEquals(IhePatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
         }
@@ -96,13 +99,15 @@ class IhePatientResourceProviderTest {
     void testSourceIdentifierSystemNull() {
         TokenParam sourceId = new TokenParam();
         sourceId.setValue("69420");
+        TokenAndListParam tokenAndListParam = new TokenAndListParam();
+        tokenAndListParam.addAnd(sourceId);
         StringAndListParam targetDomains = new StringAndListParam();
         StringOrListParam stringParam = new StringOrListParam();
         stringParam.add(new StringParam("http://2"));
         targetDomains.addAnd(stringParam);
 
         try {
-            provider.findPatientsByIdentifier(sourceId, targetDomains);
+            provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
         } catch (InvalidRequestException e) {
             assertEquals(IhePatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
         }
@@ -116,13 +121,15 @@ class IhePatientResourceProviderTest {
     void testSourceIdentifierValueNull() {
         TokenParam sourceId = new TokenParam();
         sourceId.setSystem("http://1");
+        TokenAndListParam tokenAndListParam = new TokenAndListParam();
+        tokenAndListParam.addAnd(sourceId);
         StringAndListParam targetDomains = new StringAndListParam();
         StringOrListParam stringParam = new StringOrListParam();
         stringParam.add(new StringParam("http://2"));
         targetDomains.addAnd(stringParam);
 
         try {
-            provider.findPatientsByIdentifier(sourceId, targetDomains);
+            provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
         } catch (InvalidRequestException e) {
             assertEquals(IhePatientResourceProvider.SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND, e.getMessage());
         }
@@ -135,13 +142,15 @@ class IhePatientResourceProviderTest {
     @Story("ihe_pix operation")
     void testSourceIdentifierSystemBlank() {
         TokenParam sourceId = new TokenParam("", "69420");
+        TokenAndListParam tokenAndListParam = new TokenAndListParam();
+        tokenAndListParam.addAnd(sourceId);
         StringAndListParam targetDomains = new StringAndListParam();
         StringOrListParam stringParam = new StringOrListParam();
         stringParam.add(new StringParam("http://2"));
         targetDomains.addAnd(stringParam);
 
         try {
-            provider.findPatientsByIdentifier(sourceId, targetDomains);
+            provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
         } catch (InvalidRequestException e) {
             assertEquals(IhePatientResourceProvider.SOURCE_IDENTIFIER_ASSIGNING_AUTHORITY_NOT_FOUND, e.getMessage());
         }
@@ -154,13 +163,15 @@ class IhePatientResourceProviderTest {
     @Story("ihe_pix operation")
     void testMalformedSystemIdentifier() {
         TokenParam sourceId = new TokenParam("1:2:3", "69420");
+        TokenAndListParam tokenAndListParam = new TokenAndListParam();
+        tokenAndListParam.addAnd(sourceId);
         StringAndListParam targetDomains = new StringAndListParam();
         StringOrListParam stringParam = new StringOrListParam();
         stringParam.add(new StringParam("http://2"));
         targetDomains.addAnd(stringParam);
 
         try {
-            provider.findPatientsByIdentifier(sourceId, targetDomains);
+            provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
         } catch (ResourceNotFoundException e) {
             assertEquals(IhePatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage());
         }
@@ -173,13 +184,15 @@ class IhePatientResourceProviderTest {
     @Story("ihe_pix operation")
     void testTargetIdentifierBlank() {
         TokenParam sourceId = new TokenParam("http::/1", "69420");
+        TokenAndListParam tokenAndListParam = new TokenAndListParam();
+        tokenAndListParam.addAnd(sourceId);
         StringAndListParam targetDomains = new StringAndListParam();
         StringOrListParam stringParam = new StringOrListParam();
         stringParam.add(new StringParam(""));
         targetDomains.addAnd(stringParam);
 
         try {
-            provider.findPatientsByIdentifier(sourceId, targetDomains);
+            provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
         } catch (ForbiddenOperationException e) {
             assertEquals(IhePatientResourceProvider.TARGET_SYSTEM_NOT_FOUND, e.getMessage());
         }
@@ -211,13 +224,15 @@ class IhePatientResourceProviderTest {
     @Story("ihe_pix operation")
     void testCrossRefException() {
         TokenParam sourceId = new TokenParam("urn:oid:3", "69420");
+        TokenAndListParam tokenAndListParam = new TokenAndListParam();
+        tokenAndListParam.addAnd(sourceId);
         StringAndListParam targetDomains = new StringAndListParam();
         StringOrListParam stringParam = new StringOrListParam();
         stringParam.add(new StringParam("urn:oid:3"));
         targetDomains.addAnd(stringParam);
 
         try {
-            provider.findPatientsByIdentifier(sourceId, targetDomains);
+            provider.findPatientsByIdentifier(tokenAndListParam, targetDomains);
         } catch (InternalErrorException e) {
             assertEquals("net.ihe.gazelle.business.provider.PatientResourceProviderException: One of the target domain does not exist", e.getMessage());
         }
-- 
GitLab