0

I am very new to hapi FHIR, I am trying to encode the request in following format.

   CoverageEligibilityRequest coverageEligibilityRequest =  new CoverageEligibilityRequest();
   Patient patient = new Patient().addIdentifier(new Identifier().setType(getPatientIdentifierCodeableConcept()).setSystem("http://www.abc.xyz").setValue("123"));
   coverageEligibilityRequest.setPatient(new Reference(patient));

Above code is java snippet for populating the patient in CoverageEligibilityRequest.

{
  "resourceType": "Bundle",
  "type": "batch",
  "entry": [ {
    "resource": {
      "resourceType": "CoverageEligibilityRequest",
      "id": "7890",
      "contained": [ {
        "resourceType": "Patient",
        "id": "1",
        "identifier": [ {
          "type": {
            "coding": [ {
             ...
             ...

}

But I want the request should be of following format

{
  "resourceType": "Bundle",
  "type": "batch",
  "entry": [ {
    "resource": {
      "resourceType": "CoverageEligibilityRequest",
      "id": "7890",
      "patient": {
        "type": "Patient",
        "identifier": {
          "type": {
            "coding": [ {
              ...
              ...

            } ]
          },

where I want to omit contained with actual string?

  • Be aware that 'contained' is only to be used when the object has no independent existence from the container. That would be very unusual for 'Patient' with respect to an EOB. 'contained' is *not* just a shortcut way of sending multiple resources in a single RESTful action. If the data comes in as contained, it's expected to *stay* contained - i.e. separate patient record for every single EOB, even if they're dealing with the same individual. – Lloyd McKenzie Nov 12 '20 at 15:25

1 Answers1

1

FHIR doesn't generally let you express an entire graph of objects as a single resource, so if you're trying to send a Patient resource as part of a CoverageEligibilityRequest resource, the only way you can do that is by setting the patient in the contained field. The CoverageEligibilityResource.patient field is defined as a Reference type and so can only contain the data allowed by a Reference data type and not arbitrary data.

It seems like what you actually want to do is to add a Patient to the HAPI FHIR server and a CoverageEligibilityRequest resource that references the patient. The right way to do this in FHIR is to construct a single batch or transaction bundle containing both of the resources. Basically, you want to construct a Bundle that looks something like this:

{
  "resourceType": "Bundle",
  "type": "batch",
  "entry": [ {
      "resource": {
        "resourceType": "Patient",
        "id": "1",
        "identifier": [ {
          "type": {
            "coding": [ {
             ...
      }
    }, {
      "resource": {
        "resourceType": "CoverageEligibilityRequest",
        "id": "7890",
        "patient": "Patient/1",
        ...

The easiest way to construct something similar in HAPI FHIR would be to use a transaction bundle like this:

IGenericClient client = ...
CoverageEligibilityRequest coverageEligibilityRequest =  new CoverageEligibilityRequest();
Patient patient = new Patient().addIdentifier(new Identifier().setType(getPatientIdentifierCodeableConcept()).setSystem("http://www.abc.xyz").setValue("123"));
coverageEligibilityRequest.setPatient(new Reference(patient));
client.transaction().withResources(patient, coverageEligibilityRequest);
ig0774
  • 39,669
  • 3
  • 55
  • 57