17.2.1Available Clients in SmileHarness

 

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.

17.2.1.1FHIR Clients

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.

17.2.1.1.1Standard FHIR Client

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.

17.2.1.1.1.1Variants:

  • By Port: getFhirClient(int thePort) - Get a FHIR client for a specific port
  • By Module ID: getFhirClient(String theModuleId) - Get a FHIR client for a specific module

17.2.1.1.2Superuser FHIR Client

IGenericClient 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.

17.2.1.1.2.1Variants:

  • By Port: getSuperuserFhirClient(int thePort) - Get a superuser FHIR client for a specific port
  • By Module ID: getSuperuserFhirClient(String theModuleId) - Get a superuser FHIR client for a specific module

17.2.1.1.3FHIR Client Capabilities

The 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:

  • Create: client.create().resource(resource).execute()
  • Read: client.read().resource(ResourceType.class).withId(id).execute()
  • Update: client.update().resource(resource).execute()
  • Delete: client.delete().resourceById(resourceType, id).execute()
  • Search: client.search().forResource(resourceType).where(criteria).execute()
  • Transaction: client.transaction().withBundle(bundle).execute()

For more information on using HAPI FHIR clients, see the HAPI FHIR documentation.

17.2.1.2Admin JSON Client

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();

17.2.1.2.0.1Variants:

  • By Port: getAdminJsonClient(int thePort) - Get an Admin JSON client for a specific port

17.2.1.2.1Admin JSON Client Capabilities

The AdminJsonRestClient provides methods for interacting with various aspects of the Smile CDR administrative API:

  • Node Configurations: adminClient.getNodeConfigurations()
  • Module Information: adminClient.getModuleInfo(moduleId)
  • Port Information: adminClient.getPortFromModule(moduleId)
  • User Management: Methods for creating, updating, and deleting users
  • Role Management: Methods for managing roles and permissions
  • System Status: Methods for checking system health and status

The Admin JSON client is particularly useful for:

  • Verifying configuration settings
  • Managing users and permissions
  • Monitoring system health
  • Performing administrative tasks

17.2.1.3HL7v2 REST Client

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();

17.2.1.3.0.1Variants:

  • By Port: getHL7V2RestClient(int thePort) - Get an HL7v2 REST client for a specific port
  • By Module ID: getHL7V2RestClient(String theModuleId) - Get an HL7v2 REST client for a specific module

17.2.1.3.1HL7v2 REST Client Capabilities

The HL7V2RestClient provides methods for sending HL7v2 messages to the Smile CDR server:

  • Send Message: hl7v2Client.sendMessage(message)
  • Send Message with Options: Methods for sending messages with specific options or headers

This client is particularly useful for testing HL7v2 integration scenarios, such as:

  • Sending ADT (Admission, Discharge, Transfer) messages
  • Testing HL7v2 to FHIR conversion
  • Verifying HL7v2 message processing

17.2.1.4FHIR Context

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();

17.2.1.4.0.1Variants:

  • By Module ID: getFhirContext(String moduleId) - Get the FHIR context for a specific module

17.2.1.4.1FHIR Context Capabilities

The FhirContext provides various utilities for working with FHIR resources:

  • Parsing: Convert between FHIR resources and their JSON/XML representations
  • Validation: Validate FHIR resources against the FHIR specification
  • Resource Creation: Create new FHIR resources programmatically
  • Client Creation: Create new FHIR clients

17.2.1.5Future Clients

The SmileHarness interface includes comments about potential future clients that may be added:

  • Camel Direct: For interacting with Camel routes
  • Broker Sender: For sending messages to the broker
  • Smile Log Consumer: For consuming logs from Smile CDR
  • CDA Tooling: For working with CDA documents
  • OpenTelemetry Integration: For working with OpenTelemetry
  • Data Seeding: For seeding test data
  • Subscription REST Hook Receiver: For receiving subscription notifications

These clients are not yet implemented but may be added in future versions of the library.

17.2.1.6Best Practices

When working with these clients, consider the following best practices:

  1. Reuse Clients: Create clients once and reuse them throughout your tests to avoid unnecessary overhead.
  2. Close Resources: Make sure to close any resources (like input streams) that you open.
  3. Handle Exceptions: Properly handle exceptions that may be thrown by client methods.
  4. Use Appropriate Authentication: Use the appropriate level of authentication for your tests.
  5. Clean Up: Clean up any resources you create during tests to avoid affecting other tests.

For more recommendations on effective testing with SmileCdrContainer and SmileHarness, see Best Practices.