Clients
The SmileHarness
interface provides access to various clients that can be used to interact with different aspects of a Smile CDR instance. This document provides detailed information about these clients, their capabilities, and how to use them effectively.
FHIR clients are used to interact with FHIR resources on the Smile CDR server. The SmileHarness
interface provides several methods to obtain FHIR clients with different configurations.
IGenericClient fhirClient = harness.getFhirClient();
This method returns a standard FHIR client that can be used to interact with the FHIR endpoint. By default, this client does not include any authentication, so you may need to add an interceptor for authenticated requests.
getFhirClient(int thePort)
- Get a FHIR client for a specific portgetFhirClient(String theModuleId)
- Get a FHIR client for a specific moduleIGenericClient superuserFhirClient = harness.getSuperuserFhirClient();
This method returns a FHIR client with superuser (admin) credentials already configured. This is useful for administrative tasks or tests that require elevated privileges.
getSuperuserFhirClient(int thePort)
- Get a superuser FHIR client for a specific portgetSuperuserFhirClient(String theModuleId)
- Get a superuser FHIR client for a specific moduleThe FHIR clients returned by these methods are instances of HAPI FHIR's IGenericClient
, which provides a comprehensive API for interacting with FHIR resources. Some common operations include:
client.create().resource(resource).execute()
client.read().resource(ResourceType.class).withId(id).execute()
client.update().resource(resource).execute()
client.delete().resourceById(resourceType, id).execute()
client.search().forResource(resourceType).where(criteria).execute()
client.transaction().withBundle(bundle).execute()
For more information on using HAPI FHIR clients, see the HAPI FHIR documentation.
The Admin JSON client is used to interact with the Smile CDR administrative API, which provides access to configuration, monitoring, and management functions.
AdminJsonRestClient adminClient = harness.getAdminJsonClient();
getAdminJsonClient(int thePort)
- Get an Admin JSON client for a specific portThe AdminJsonRestClient
provides methods for interacting with various aspects of the Smile CDR administrative API:
adminClient.getNodeConfigurations()
adminClient.getModuleInfo(moduleId)
adminClient.getPortFromModule(moduleId)
The Admin JSON client is particularly useful for:
The HL7v2 REST client is used to interact with the Smile CDR HL7v2 endpoint, which allows sending and receiving HL7v2 messages.
HL7V2RestClient hl7v2Client = harness.getHL7V2RestClient();
getHL7V2RestClient(int thePort)
- Get an HL7v2 REST client for a specific portgetHL7V2RestClient(String theModuleId)
- Get an HL7v2 REST client for a specific moduleThe HL7V2RestClient
provides methods for sending HL7v2 messages to the Smile CDR server:
hl7v2Client.sendMessage(message)
This client is particularly useful for testing HL7v2 integration scenarios, such as:
While not a client per se, the SmileHarness
also provides access to the FHIR context, which is useful for working with FHIR resources programmatically.
FhirContext fhirContext = harness.getFhirContext();
getFhirContext(String moduleId)
- Get the FHIR context for a specific moduleThe FhirContext
provides various utilities for working with FHIR resources:
The SmileHarness
interface includes comments about potential future clients that may be added:
These clients are not yet implemented but may be added in future versions of the library.
When working with these clients, consider the following best practices:
For more recommendations on effective testing with SmileCdrContainer
and SmileHarness
, see Best Practices.
You are about to leave the Smile Digital Health documentation and navigate to the Open Source HAPI-FHIR Documentation.