Within the RESTful architecture of the FHIR specification, a FHIR client works with resources on the server through interactions. A FHIR client developed with InterSystems technology provides methods that correspond to these interactions, allowing your ObjectScript code to perform an interaction with a single method call.
While the FHIR client provides at least one method for every interaction, it provides a single method regardless of which operation you are performing on the FHIR server. For details on invoking this method to perform an operation, see Operation( )Opens in a new tab in the Class Reference.
Calling an Interaction Method
If your FHIR client is writing to the server with interactions like update, it must use the SetRequestFormat() method to specify the format of the payload being written to the server. Possible formats are JSON, XML, Form, XPatch, and JPatch. Similarly, your FHIR client can specify the preferred format of the resources returned by the FHIR server using the SetResponseFormat. Possible formats are JSON and XML.
Unless the request and response formats change for individual interactions, your application can set them once and have them applied to all interaction methods. For example, a standalone FHIR client sending requests to a FHIR server over HTTP might set the request and response formats immediately after instantiating the client.
Set clientObj = ##class(HS.FHIRServer.RestClient.HTTP).CreateInstance("MyFHIR.HTTP.Service")
Do clientObj.SetRequestFormat("JSON")
Do clientObj.SetResponseFormat("JSON")
Once the FHIR client class has been instantiated and the request and response formats set, the application can call methods that correspond to the FHIR interactions they want to perform on the server. To explore the FHIR interaction methods, including signatures, that are available to a FHIR client, refer to HS.FHIRServer.RestClient.BaseOpens in a new tab in the Class Reference. Note that FHIR interactions that allow conditional actions have two different methods. For example, your application can call Update() or ConditionalUpdate() depending on whether the update interaction is conditional.
The data type of the payload that is passed as an argument is determined by the type of FHIR client that has been instantiated.
-
For clients accessing a FHIR server over HTTP, the payload argument can be a string or stream.
-
For clients accessing an InterSystems FHIR server in the local namespace, the payload argument can be a string, stream, or dynamic object.
The following is an example of instantiating a FHIR client and performing a read interaction on the external FHIR server:
Set clientObj = ##class(HS.FHIRServer.RestClient.HTTP).CreateInstance("MyFHIR.HTTP.Service")
Do clientObj.SetResponseFormat("JSON")
Set clientResponseObj = clientObj.Read("GET", "Patient", "123")