Skip to content

Commit

Permalink
[HIE-2] change fhir client search implementation, add initial pass (p…
Browse files Browse the repository at this point in the history
…un intended) at parsing
  • Loading branch information
pmanko2 committed Feb 7, 2023
1 parent 009e0f8 commit d5f3880
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getClientRegistryGetPatientEndpoint() {
.getGlobalProperty(ClientRegistryConstants.GP_FHIR_CLIENT_REGISTRY_GET_PATIENT_ENDPOINT);

// default to Patient/$ihe-pix if patient endpoint is not defined in config
return globalPropPatientEndpoint == null || globalPropPatientEndpoint.isEmpty() ? String.format("Patient/%s",
return (globalPropPatientEndpoint == null || globalPropPatientEndpoint.isEmpty()) ? String.format("Patient/%s",
FhirCRConstants.IHE_PIX_OPERATION) : globalPropPatientEndpoint;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class ClientRegistryConstants {

public static final String GP_CLIENT_REGISTRY_SERVER_URL = "clientregistry.serverUrl";
public static final String GP_CLIENT_REGISTRY_SERVER_URL = "clientregistry.clientRegistryServerUrl";

public static final String GP_FHIR_CLIENT_REGISTRY_GET_PATIENT_ENDPOINT = "clientregistry.fhirGetPatientEndpoint";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.net.URL;
import java.util.List;

@Component
Expand All @@ -25,24 +27,28 @@ public class FhirCRPatientServiceImpl implements CRPatientService {

@Override
public Patient getCRPatient(String sourceIdentifier, String sourceIdentifierSystem, List<String> extraTargetSystems) {
String fullGetCRPatientUrl = String.format("%s/%s", config.getClientRegistryServerUrl(),
config.getClientRegistryGetPatientEndpoint());

// construct and send request to external client registry
IQuery<IBaseBundle> crRequest = fhirClient
.search()
.byUrl(config.getClientRegistryGetPatientEndpoint())
.byUrl(fullGetCRPatientUrl)
.where(
FhirCRConstants.SOURCE_IDENTIFIER_PARAM.exactly().systemAndIdentifier(sourceIdentifierSystem,
sourceIdentifier));

if (!extraTargetSystems.isEmpty()) {
crRequest.and(FhirCRConstants.TARGET_SYSTEM_PARAM.matches().values(extraTargetSystems));
}

Bundle results = crRequest.returnBundle(Bundle.class).execute();

// TODO implement parsing

return new Patient();


Bundle patientBundle = crRequest.returnBundle(Bundle.class).execute();

return patientBundle.getEntry()
.stream()
.findFirst()
.map(e -> (Patient) e.getResource())
.orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
package org.openmrs.module.clientregistry.api.providers.r4;

import ca.uhn.fhir.model.valueset.BundleTypeEnum;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException;
import lombok.AccessLevel;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import lombok.Setter;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Patient;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import org.openmrs.module.clientregistry.ClientRegistryConfig;
import org.openmrs.module.clientregistry.api.ClientRegistryManager;
import org.openmrs.module.clientregistry.api.providers.FhirCRConstants;
import org.openmrs.module.fhir2.api.annotations.R4Provider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Component
import static lombok.AccessLevel.PACKAGE;

@Component("crPatientFhirR4ResourceProvider")
@R4Provider
@Setter(AccessLevel.PACKAGE)
@Setter(PACKAGE)
public class FhirCRPatientResourceProvider implements IResourceProvider {

@Autowired
Expand All @@ -39,8 +44,8 @@ public Class<? extends IBaseResource> getResourceType() {
}

/**
* FHIR endpoint to get Patient references from external client registry Example request:
* [base]/Patient/$ihe-pix?sourceIdentifier=1234[&targetSystem=system1,system2]
* FHIR endpoint to get Patient references from external client registry Example request: GET
* [fhirbase]/Patient/$ihe-pix?sourceIdentifier=1234[&targetSystem=system1,system2]
*
* @param sourceIdentifierParam patient identifier
* @param targetSystemsParam (optional) Patient assigning authorities (ie systems) from which
Expand All @@ -49,7 +54,7 @@ public Class<? extends IBaseResource> getResourceType() {
* @return Patient corresponding to identifier (TODO this might change to a list of identifier
* references returned by CR)
*/
@Operation(name = FhirCRConstants.IHE_PIX_OPERATION, type = Patient.class, bundleType = BundleTypeEnum.SEARCHSET)
@Operation(name = FhirCRConstants.IHE_PIX_OPERATION, idempotent=true, type = Patient.class, bundleType = BundleTypeEnum.SEARCHSET)
public Patient getCRPatientById(
@OperationParam(name = FhirCRConstants.SOURCE_IDENTIFIER) StringParam sourceIdentifierParam,
@OperationParam(name = FhirCRConstants.TARGET_SYSTEM) StringOrListParam targetSystemsParam
Expand All @@ -59,25 +64,32 @@ public Patient getCRPatientById(
throw new InvalidRequestException("sourceIdentifier must be specified");
}

List<String> targetSystems = targetSystemsParam
.getValuesAsQueryTokens()
.stream()
.filter(Objects::nonNull)
.map(StringParam::getValue)
.collect(Collectors.toList());
List<String> targetSystems = targetSystemsParam == null
? Collections.emptyList()
: targetSystemsParam.getValuesAsQueryTokens().stream().filter(Objects::nonNull).map(StringParam::getValue).collect(Collectors.toList());

// If no targetSystem provided, use config defined default. Otherwise, take first targetSystem provided and
// include in sourceIdentifier token. Remaining targetSystems included in targetSystem param passed to CR
String sourceIdentifierSystem;
if (targetSystems.size() == 0) {
if (targetSystems.isEmpty()) {
sourceIdentifierSystem = config.getClientRegistryDefaultPatientIdentifierSystem();
} else {
sourceIdentifierSystem = targetSystems.get(0);
targetSystems.remove(0);
}

if (sourceIdentifierSystem == null || sourceIdentifierSystem.isEmpty()) {
throw new InvalidRequestException("Clientregistry module does not have a default target system set. At last one targetSystem must be provided in the request");
throw new InvalidRequestException("ClientRegistry module does not have a default target system assigned " +
"via the defaultPatientIdentifierSystem property. At least one targetSystem must be provided in " +
"the request");
}

Patient patient = clientRegistryManager.getPatientService().getCRPatient(
sourceIdentifierParam.getValue(), sourceIdentifierSystem, targetSystems
);

if (patient == null) {
throw new ResourceNotFoundException(String.format("Count not find patient with sourceIdentifier %s", sourceIdentifierParam.getValue()));
}

return clientRegistryManager.getPatientService().getCRPatient(
Expand Down
4 changes: 2 additions & 2 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<!-- Required Global Properties -->
<globalProperty>
<property>@MODULE_ID@.serverUrl</property>
<property>@MODULE_ID@.clientRegistryServerUrl</property>
<defaultValue>http://localhost:5001/CR/fhir</defaultValue>
<description>
Base URL for the Client Registry Server
Expand All @@ -44,7 +44,7 @@

<globalProperty>
<property>@[email protected]</property>
<defaultValue>/Patient/$ihe-pix</defaultValue>
<defaultValue>Patient/$ihe-pix</defaultValue>
<description>
Client registry endpoint implementing the Patient identifier cross-reference transaction (ITI-83)
</description>
Expand Down

0 comments on commit d5f3880

Please sign in to comment.