-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Let's Build DevDays US 2020
This page contains instructions for the DevDays US 2020 Let's Build session. In this exercise we will take a few key features of the HAPI FHIR JPA Server for a spin.
First, check out the project here: https://github.com/hapifhir/hapi-fhir-jpaserver-starter (or if you already have, perform a git pull
to ensure you have the latest code.
You will also need a Java JDK with version 8 or 11 (others may work but we recommend one of these two as they are the focus of our testing). You can get JDK 11 here: https://adoptopenjdk.net/
Finally, you will need Apache Maven. You can get Maven here: https://maven.apache.org/download.cgi
Out of the box, HAPI FHIR JPA uses an embedded database called H2. H2 is a nice database for testing things, because it doesn't require you to install anything. We will use it for this session, but if you are building a server that you are going to put real data on you will definitely want to swap this for a production grade database such as Postgresql.
To start the JPA server, issue the following command:
mvn clean jetty:run
You will see some messages in the console while it starts. After a few moments, it should settle down and you'll see a message like this:
[INFO] Started ServerConnector@3f867060{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
[INFO] Started @17521ms
[INFO] Started Jetty Server
Let's add two patients to our server. First, we'll do a FHIR Update with Client Assigned ID to create a patient with the ID Patient/A
. This is a useful feature of FHIR that allows the client to pick the ID assigned to the resource:
- PUT the following contents to the URL: http://localhost:8080/hapi-fhir-jpaserver/fhir/Patient/A
{
"resourceType": "Patient",
"id": "A",
"identifier": [ {
"system": "http://springfieldhospital.edu/patient",
"value": "3894746"
} ],
"name": {
"family": "Simpson",
"given": [ "Homer", "J" ]
},
"gender": "male",
"birthDate": "1956-05-12"
}
Next, let's create a Patient/B
- PUT the following contents to the URL: http://localhost:8080/hapi-fhir-jpaserver/fhir/Patient/B
{
"resourceType": "Patient",
"id": "B",
"identifier": [ {
"system": "http://springfieldhospital.edu/patient",
"value": "1234567"
} ],
"name": {
"family": "Simpson",
"given": [ "Marge" ]
},
"gender": "female",
"birthDate": "1956-10-01"
}
Now, let's create a few Observations. We'll use a FHIR Transaction for this, in order to create several resources at the same time.
- POST the following contents to the URL: http://localhost:8080/hapi-fhir-jpaserver/fhir/
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"resource": {
"resourceType": "Observation",
"status": "final",
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "789-8",
"display": "Erythrocytes [#/volume] in Blood by Automated count"
}
]
},
"subject": {
"reference": "Patient/A"
},
"effectiveDateTime": "2020-06-16T12:00:00-04:00",
"valueQuantity": {
"value": 4.12,
"unit": "10 trillion/L",
"system": "http://unitsofmeasure.org",
"code": "10*12/L"
}
},
"request": {
"method": "POST",
"url": "Observation"
}
},
{
"resource": {
"resourceType": "Observation",
"status": "final",
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "11557-6",
"display": "Carbon dioxide in blood"
}
]
},
"subject": {
"reference": "Patient/B"
},
"valueQuantity": {
"value": 6.2,
"unit": "kPa",
"system": "http://unitsofmeasure.org",
"code": "kPa"
}
},
"request": {
"method": "POST",
"url": "Observation"
}
}
]
}
You may want to add some more data beyond what we are showing here.
Let's try a few searches for data. A couple of ideas are here, but you should play around and try others: