Not able to add Patient resource in Appointment resource

289 views
Skip to first unread message

Sahil Bhanot

unread,
Aug 2, 2018, 10:45:23 AM8/2/18
to HAPI FHIR
Hi All,
As per the requirement in the project, need to add the patient resource in Appointment before sending it to the FHIR server.  In FHIR we can send any resource in a resource.
When i am serializing a patient resource in an Appointment, it is getting added but when i am deserializing it, the patient resouce is lost and only appointment is left.
I am using the HAPI FHIR(hapi-fhir-structures-dstu3 version:2.5 and hapi-fhir-base version:2.3).

Could anyone help in this regard or there is any other way to implement this solution. Any pointers would be appreciated.

Thanks and Regards,
Sahil Bhanot

James Agnew

unread,
Aug 2, 2018, 11:32:15 AM8/2/18
to bhanot...@gmail.com, HAPI FHIR
Hi Sahil,

A couple of points:

* You should not mix versions of HAPI FHIR between the modules, that is almost guaranteed to cause issues. You should also use the latest version, as you are using a version that is over a year old.
* If you can create a *very brief* code snippet that shows how to reproduce your issue, that will improve your chances of finding a solution. If your issue is with deserialization, a simple code block showing a parse of a string version of your resource would be a good example of such a snippet. Please see our wiki for tips on this.

Cheers,
James


--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/4d02698d-8835-4031-9bd1-b2e76c57220c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sahil Bhanot

unread,
Aug 3, 2018, 7:34:22 AM8/3/18
to HAPI FHIR
Dear James,
Thanks a lot for your quick response.
I have tried with the latest version of HAPI FHIR i.e. 3.4.0 but still facing the same situation. I would explain the whole scenario, you could explain me better where I am committing the mistake or misinterpreting the thing.

To an Appointment resource, I am adding the Patient resource by addContained function illustrated as below:
Appointment appointmentFhir = new Appointment();
appointmentFhir.addContained(fhirPatient);

When I am debugging the code, I could see it clearly that in contained(ArrayList) in Appointment object contains the Patient resource, but when I am parsing the Appointment resource to String with the FHIR JSON parser, no patient resource is present:

String appointment = ctx.newJsonParser().encodeResourceToString(appointmentFhir);

I have booked an Appointment in the public FHIR server "http://hapi.fhir.org/baseDstu3" and the Appointment ID is "4649900". When I am searching the Appointment on the server, It also doesn't contain the Patient resource.
Call to the FHIR server is made:
outcome = client.create().resource(appointmentFhir).encodedJson().execute();

Alternate way is that I have added an extension and put the patient resource in String format, but it is not an appropriate way to achieve this. 

Kindly let me know, where I am missing. It is a showstopper for me. Help would be really appreciated.
Let me know, if anything else is required for understanding the issue.

Thanks and Regards,
Sahil Bhanot

Kevin Mayfield

unread,
Aug 3, 2018, 8:14:55 AM8/3/18
to hapi...@googlegroups.com

Are you adding the patient to the actual appointment e.g. something like this

appointment.addParticipant().setActorTarget(fhirPatient);

Not sure if that works but you would need to point the appointment to the contained patient.

James Agnew

unread,
Aug 3, 2018, 9:34:35 AM8/3/18
to bhanot...@gmail.com, HAPI FHIR
Contained resources are not valid unless there is a reference to them from the outer resource. That is why they are being dropped by HAPI FHIR.

There are some examples here on how to use contained resources: http://hapifhir.io/doc_resource_references.html#Contained_Resources

Cheers,
James

Sahil Bhanot

unread,
Aug 3, 2018, 9:45:11 PM8/3/18
to HAPI FHIR
Dear Kevin,
I am adding the patient resource as "appointmentFhir.addContained(fhirPatient);". But there is no reference to Patient resource from Appointment, it is not working.
Could you help me in provided how to provide a reference as studying from "http://hapifhir.io/doc_resource_references.html#Contained_Resources", I am able to add Appointment in Patient but my requirement is to add Patient in Appointment resource.

Thanks in advance,
Sahil

Sahil Bhanot

unread,
Aug 3, 2018, 9:49:22 PM8/3/18
to HAPI FHIR
Thanks James for the reference link. But unfortunately from the link, I understood to add any resource in Patient.
Unfortunately, I am  not able to add the Patient in Appointment(not able to provide the reference). I tried putting patient reference via extension in Appointment but it didn't work.
Could you help me, how I can provide a reference for the inner resource(Patient) to the outer one(Appointment).

Thanks and Regards,
Sahil

Kevin Mayfield

unread,
Aug 4, 2018, 4:11:37 AM8/4/18
to Sahil Bhanot, HAPI FHIR
This works.

Appointment appointment = new Appointment();
patient.setId("#1");
appointment.addContained(patient);
appointment.addParticipant().setActor(new Reference("#1"));
System.out.println(parser.setPrettyPrint(true).encodeResourceToString(appointment));

The patient is a participant in the Appointment. 

However this depends what your use case is It’s not likely you are going to use a contained Patient resource in a patient. (The reasoning behind this: contained resources are normally incomplete resources), if you have complete resource then it should be a separate resource and the appointment references it). For a messaging system, this means the Patient and Appointment would be in the same Bundle and may look like this:

Bundle bundle = new Bundle();

patient.setId("#1");
Appointment appointment = new Appointment();
appointment.addParticipant().setActor(new Reference("#1"));
bundle.addEntry().setResource(appointment);

bundle.addEntry().setResource(patient);

System.out.println(parser.setPrettyPrint(true).encodeResourceToString(bundle));
Which results in:
Notice neither the Patient or Appointment uses contained resources. (if you want to see these try this reference implementation: http://yellow.testlab.nhs.uk/ccri/


<Bundle xmlns="http://hl7.org/fhir">
   <entry>
      <resource>
         <Appointment xmlns="http://hl7.org/fhir">
            <participant>
               <actor>
                  <reference value="#1"></reference>
               </actor>
            </participant>
         </Appointment>
      </resource>
   </entry>
   <entry>
      <resource>
         <Patient xmlns="http://hl7.org/fhir">
            <id value="#1"></id>
            <meta>
               <lastUpdated value="2018-07-27T12:09:55.280+00:00"></lastUpdated>
               <profile value="https://fhir.hl7.org.uk/STU3/StructureDefinition/CareConnect-Patient-1"></profile>
            </meta>
               <valueCodeableConcept>
                  <coding>
                     <system value="https://fhir.hl7.org.uk/STU3/CodeSystem/CareConnect-EthnicCategory-1"></system>
                     <code value="A"></code>
                     <display value="British, Mixed British"></display>
                  </coding>
               </valueCodeableConcept>
            </extension>
            <identifier>
                  <valueCodeableConcept>
                     <coding>
                        <system value="https://fhir.hl7.org.uk/STU3/CodeSystem/CareConnect-NHSNumberVerificationStatus-1"></system>
                        <code value="01"></code>
                        <display value="Number present and verified"></display>
                     </coding>
                  </valueCodeableConcept>
               </extension>
               <system value="https://fhir.nhs.uk/Id/nhs-number"></system>
               <value value="9876543210"></value>
            </identifier>
            <identifier>
               <system value="https://fhir.leedsth.nhs.uk/Id/pas-number"></system>
               <value value="ABC8650149"></value>
            </identifier>
            <identifier>
               <system value="https://fhir.leedsth.nhs.uk/Id/PPMIdentifier"></system>
               <value value="1"></value>
            </identifier>
            <active value="true"></active>
            <name>
               <use value="official"></use>
               <family value="Kanfeld"></family>
               <given value="Bernie"></given>
               <prefix value="Miss"></prefix>
            </name>
            <telecom>
               <system value="phone"></system>
               <value value="0115 9737320"></value>
               <use value="home"></use>
            </telecom>
            <telecom>
               <system value="email"></system>
               <value value="bernie....@nhsdigital.nhs.uk"></value>
               <use value="home"></use>
            </telecom>
            <gender value="female"></gender>
            <birthDate value="1998-03-13"></birthDate>
            <address>
               <use value="work"></use>
               <type value="both"></type>
               <line value="Field Jardin"></line>
               <line value="Long Eaton"></line>
               <city value="Nottingham"></city>
               <district value="Derbyshire"></district>
               <postalCode value="NG10 1ZZ"></postalCode>
            </address>
            <address>
               <use value="work"></use>
               <type value="both"></type>
               <line value="Field Jardin"></line>
               <line value="Long Eaton"></line>
               <city value="Nottingham"></city>
               <district value="Derbyshire"></district>
               <postalCode value="NG10 1ZZ"></postalCode>
            </address>
            <address>
               <use value="work"></use>
               <type value="both"></type>
               <line value="Field Jardin"></line>
               <line value="Long Eaton"></line>
               <city value="Nottingham"></city>
               <district value="Derbyshire"></district>
               <postalCode value="NG10 1ZZ"></postalCode>
            </address>
            <address>
               <use value="work"></use>
               <type value="both"></type>
               <line value="Field Jardin"></line>
               <line value="Long Eaton"></line>
               <city value="Nottingham"></city>
               <district value="Derbyshire"></district>
               <postalCode value="NG10 1ZZ"></postalCode>
            </address>
            <address>
               <use value="work"></use>
               <type value="both"></type>
               <line value="Field Jardin"></line>
               <line value="Long Eaton"></line>
               <city value="Nottingham"></city>
               <district value="Derbyshire"></district>
               <postalCode value="NG10 1ZZ"></postalCode>
            </address>
            <maritalStatus>
               <coding>
                  <system value="http://hl7.org/fhir/v3/MaritalStatus"></system>
                  <code value="S"></code>
                  <display value="Never Married"></display>
               </coding>
            </maritalStatus>
            <generalPractitioner>
               <reference value="Practitioner/1"></reference>
               <display value="Dr AA Bhatia"></display>
            </generalPractitioner>
            <managingOrganization>
               <reference value="Organization/1"></reference>
               <display value="The Moir Medical Centre"></display>
            </managingOrganization>
         </Patient>
      </resource>
   </entry>
</Bundle>

You’ll notice the Appointment references the Patient.

if this is on a RESTful API then the code becomes 

appointment = new Appointment();
appointment.setId("1");
appointment.addParticipant().setActor(new Reference("Patient/1"));

System.out.println(parser.setPrettyPrint(true).encodeResourceToString(appointment));

and the appointment looks like this:

<Appointment xmlns="http://hl7.org/fhir">
   <id value="1"></id>
   <participant>
      <actor>
         <reference value="Patient/1"></reference>
      </actor>
   </participant>
</Appointment>




. If your trying to send a message then  if the Patient is a complete resource (not a partial patient resource), I would rewrite it this way:





--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.

Sahil Bhanot

unread,
Aug 9, 2018, 5:13:11 AM8/9/18
to HAPI FHIR
Dear Kevin,

Thanks a lot . I was just missing the # in the id, while creating the reference to the resource.
My requirement was to send the Patient data along with the Appointment and this contained placeholder is best suited for this requirement.

Again Thanks for desired help. 

Cheers,
Sahil 
Reply all
Reply to author
Forward
0 new messages