This is a simple fhir client in java to practice with fhir resources and CRUD requests to a fhir server.
Note that for the most part auto-completion is activated.
Already installed in the container :
Hapi Fhir model and client
Clone/git pull the repo into any local directory e.g. like it is shown below:
$ git clone https://github.com/LucasEnard/fhir-client-java.git
Open the terminal in this directory and run:
$ docker build .
This repository is ready for VS Code.
Open the locally-cloned
fhir-client-java folder in VS Code.
If prompted (bottom right corner), install the recommended extensions.
You can be inside the container before coding.
For this, docker must be on before opening VSCode.
Then, inside VSCode, when prompted (in the right bottom corner), reopen the folder inside the container so you will be able to use the python components within it.
The first time you do this it may take several minutes while the container is readied.
If you don't have this option, you can click in the bottom left corner and
press reopen in container then select
By opening the folder remote you enable VS Code and any terminals you open within it to use the java components within the container.
To complete this walktrough you will need a FHIR server.
You can either use your own or go to InterSystems free FHIR trial and follow the next few steps to set it up.
Using our free trial, just create an account and start a deployement, then in the
Overview tab you will get acces to an endpoint like
https://fhir.000000000.static-test-account.isccloud.io that we will use later.
Then, by going to the
Credentials tab, create an api key and save it somewhere.
Now you are all done, you have you own fhir server holding up to 20GB of data with a 8GB memory.
Complete walkthrough of the client situated at
The code is separated in multiple parts, and we will cover each of them below.
In this part we connect our client to our server using Fhir.Rest.
In order to connect to your server you need to change the line :
Header header = new BasicHeader("x-api-key", "api-key");
And this line :
IGenericClient client = ctx.newRestfulGenericClient("url");
'url' is an endpoint while the
"api-key" is the api key to access your server.
Note that if you are not using an InterSystems server you may want to check how to authorize your acces if needed.
Just like that, we have a FHIR client capable of direct exchange with our server.
In this part we create a Patient using Fhir.Model and we fill it with a HumanName, following the FHIR convention,
family are string and
given is a list of string. The same way, a Patient can have multiple HumanNames so we have to put our HumanName in a list before puting it into our newly created Patient.
After that, we need to save our new Patient in our server using our client.
Note that if you start
Client.java multiple times, multiple Patients having the name we choosed will be created.
This is because, following the FHIR convention you can have multiple Patient with the same name, only the
id is unique on the server.
Check the doc for more information.
Therefore we advise to comment the line after the first launch.
In this part we get a client searching for a Patient named after the one we created earlier.
Once we found him, we add a phone number to his profile and we change his given name to another.
Now we can use the update function of our client to update our patient in the server.
In this part we want to create an observation for our Patient from earlier, to do this we need his id, which is his unique identifier.
From here we fill our observation and add as the subject, the id of our Patient.
Then, we register using the create function our observation.
If you have followed this walkthrough you now know exactly what Client.cs does, you can start it and check in your server your newly created Patient and Observation.
To start it, open a VSCode terminal and enter :
You should see some information on the Patient we created and his observation.
If you are using an Intersystems server, go to
API Deployement, authorize yourself with the api key and from here you can GET by id the patient and the observation we just created.
This repository is ready to code in VSCode with InterSystems plugins.
Client.java to start coding or using the autocompletion.
A dockerfile to create a dot net env for you to work on.
docker build . to build and reopen your file in the container to work inside of it.
Config file if you want to debug