Need FHIR2 encounter create and update calls

Hi @dkayiwa,

I added the latest FHIR2 module which is having the functionalities to create & update the encounters in the openmrs. I’ve a proper r4 Encounter bundle which I want to save in my openmrs table by using this module. What is the URL to the API call which will accept and save this r4 Encounter bundle to the openmrs ?

@chughrahul you can post your r4 Encounter bundle to some thing like http://localhost:"server port"/openmrs/ws/fhir2/R4/Encounter

Hi @gcliff ,

This POST url is working fine. Thanks. However, the documentation for fhir2 module is not updated with these calls, kindly have a look at it.

thanks for the heads-up on this ,

Do you mind dropping here the exact fhir documentation link you are talking about

Sure, https://wiki.openmrs.org/display/projects/Encounter+Resource

It is one of the resource and there are several others also.

Thanks ,this is something that @sashrika could look into ,

In the mean time have you have a chance to look at https://wiki.openmrs.org/display/projects/OpenMRS+FHIR+Module

Hi @gcliff @dkayiwa ,

I used the fhir POST encounter call to save encounter. It initially thrown me errors. I resolved some of them but still it is not able to save encounter. I also tried to use the test encounter JSON available at github but it still didn’t work for me.

I’m getting 422 & 500 error codes with the following response

@chughrahul could you try posting this

{
     "resourceType": "Encounter",
                "meta": {
                    "lastUpdated": "2021-01-14T12:22:58.000+00:00"
                },
                "text": {
                    "status": "generated",
                    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><table class=\"hapiPropertyTable\"><tbody><tr><td>Id:</td><td>195df5c8-ef0f-4335-b1cf-4958cdd3f015</td></tr><tr><td>Status:</td><td>UNKNOWN</td></tr><tr><td>Class:</td><td> (Details: http://terminology.hl7.org/CodeSystem/v3-ActCode ) </td></tr><tr><td>Subject:</td><td><a href=\"http://localhost:8080/openmrs/ws/fhir2/R4/Patient/8295eb5b-fba6-4e83-a5cb-2817b135cd27\">Paul Walker (OpenMRS ID: 10000X)</a></td></tr><tr><td>Location:</td><td><table class=\"subPropertyTable\"><tbody><tr><th>-</th><th>Location</th><th>Status</th><th>Physical Type</th><th>Period</th></tr><tr><td>1</td><td><a href=\"http://localhost:8080/openmrs/ws/fhir2/R4/Location/8d6c993e-c2cc-11de-8d13-0010c6dffd0f\">Unknown Location</a></td><td/><td/><td/></tr></tbody></table></td></tr><tr><td>Part Of:</td><td><a href=\"http://localhost:8080/openmrs/ws/fhir2/R4/Encounter/b0dc60c6-7d16-415f-af3f-90dcb538043f\">Encounter/b0dc60c6-7d16-415f-af3f-90dcb538043f</a></td></tr></tbody></table></div>"
                },
                "status": "unknown",
                "class": {
                    "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
                    "code": "AMB"
                },
                "subject": {
                    "reference": "Patient/8295eb5b-fba6-4e83-a5cb-2817b135cd27",
                    "type": "Patient",
                    "display": "Paul Walker (OpenMRS ID: 10000X)"
                },
                "location": [
                    {
                        "location": {
                            "reference": "Location/8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
                            "type": "Location",
                            "display": "Unknown Location"
                        }
                    }
                ],
                "partOf": {
                    "reference": "Encounter/b0dc60c6-7d16-415f-af3f-90dcb538043f",
                    "type": "Encounter"
                }
}

@gcliff I tried this json and got the following response with 400 Bad Request -

{
    "resourceType": "OperationOutcome",
    "text": {
        "status": "generated",
        "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">ERROR</td><td>[]</td><td><pre>Invalid type of request</pre></td>\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
    },
    "issue": [
        {
            "severity": "error",
            "code": "processing",
            "diagnostics": "Invalid type of request"
        }
    ]
}

@chughrahul you can fetch some encounters with GET http://localhost:"server-port"/openmrs/ws/fhir2/R4/Encounter and then get a glimpse of what kind of payload to POST

So note that creating an encounter through the FHIR2 API requires you to have the necessary data already setup in your OpenMRS instance, so, for instance, the Visit that this encounter is partOf needs to already exist, the patient the encounter is for needs to exist, the patient needs to exist, the practitioner referenced needs to exist and be a valid OMRS provider, the location of the encounter needs to exist in your instance, as does the encounterType. That’s probably the issue with the first request. (So, in the context where we actually use that sample request for a test, we have the data shown here loaded into the database).

Hi @gcliff , @ibacher

I tried to post encounter through the post call after all the required changes and it is working now. Thanks

However, whenever I’m trying to run openmrs with fhir2 module, most of the times I’m getting this error while starting openmrs - The following error occurred at startup:Unable to start OpenMRS. Error thrown - Pastebin.com

After deleting the lucene folder this error resolves, but is there any permanent solution for this ?

I can’t see why this has anything to do with the Lucene folder at all. The error you’re reporting there happens when there are two modules (e.g., the FHIR2 module and some other module) that both bundle hapi-fhir-base (either explicitly or implicitly) and where neither of the modules are aware of the other, causing OpenMRS to load two different versions of the same class in two different module class loaders.

The best long-term solution is if you can find whatever other module bundles hapi-fhir and change it so it instead depends on the FHIR2 module.

Hi @ibacher ,

I’m using FHIR2 module with one of my modules using dependency -

<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-r4</artifactId>
<version>5.1.0</version>

<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>5.1.0</version>

Which version should I use instead of 5.1.0 to get rid of this error ?

It’s not a matter of changing the dependency version. The thing to do would be to just make your module depend on the FHIR2 module, then you get those dependencies for free.

So in your POM.xml, you want something like this:

<!-- elsewhere -->
<properties>
	<fhir2Version>1.2.1</fhir2Version>
</properties>

<!--  with your other dependencies -->
<dependency>
	<groupId>org.openmrs.module</groupId>
	<artifactId>fhir2-api</artifactId>
	<version>${fhir2Version}</version>
	<scope>provided</scope>
</dependency>

And then in omod/src/main/resources/config.xml you need a line that looks like this:

<require_modules>
	<require_module version="${fhir2Version}">org.openmrs.module.fhir2</require_module>
</require_modules>

Hi @gcliff , @ibacher

I’ve looked into the available resources in the FHIR R4 structure. We’ve diagnosticReport, Prescription OPConsultation & dischargeSummary resource to save. I’m facing issues in saving the dischargeSummary through R4 call as it contains a documentReference and I’m confused in saving this with the help of FHIR module. Can you please guide me on this ? Sample dischargeSummary documentReference bundle -

{
      "fullUrl": "DocumentReference/6ae64896-2ec9-4c41-8aae-6731856d6a84",
      "resource": {
        "resourceType": "DocumentReference",
        "id": "6ae64896-2ec9-4c41-8aae-6731856d6a84",
        "meta": {
          "versionId": "1.0",
          "lastUpdated": "2021-03-15T15:29:57.000+05:30",
          "profile": [
            "https://nrces.in/ndhm/fhir/r4/StructureDefinition/DocumentReference"
          ]
        },
        "status": "current",
        "docStatus": "final",
        "type": {
          "coding": [
            {
              "system": "http://snomed.info/sct",
              "code": "373942005",
              "display": "Discharge summary"
            }
          ],
          "text": "Discharge summary"
        },
        "subject": {
          "reference": "Patient/b6926e3f-502e-fe0a-d62e-553cf8abfc51"
        },
        "content": [
          {
            "attachment": {
              "contentType": "application/pdf",
              "language": "en-IN",
              "data": "QUJDREU=",
              "title": "Discharge Summary Report",
              "creation": "2021-05-17T17:07:11+05:30"
            }
          }
        ]
      }
    }

@chughrahul currently we dont yet have the implementation of the Document reference resource in the fhir2 module, though we do cater for the diagnosticReport resource

Is there any plans for documentReference in coming future ?

yes ,sure :+1:

In the mean time feel free to open up an issue to track this activity by a volunteer dev :cowboy_hat_face:

Hi @gcliff , @ibacher @dkayiwa ,

I’m working on to posting some observations from the FHIR2 module using POST R4/Observation call. However, the observation that I’m getting from the external resource has a concept which is not available in openmrs database. Is FHIR2 able to make new concept in this case ?