How can I bind FHIR Patient resources and binary data in to DocumentReference resource in Java

827 views
Skip to first unread message

Hareesh G

unread,
Oct 10, 2014, 3:15:57 AM10/10/14
to hapi...@googlegroups.com
Hi,
     I'm new to FHIR. I am trying to send DocumentReference from a Java restfull service. In addition I need to  embed actual Patient resource object to DocumentReference resource.
     Also i need to embed Binary data(Custom resources object) in  to DocumentReference resource.
 
   I saw that ResourceReference of Patient resource can be attached to the Subject attribute of DocumentReference as URL. But i want to know how to bind the actual object of Patient resource and Binary data in DocumentReference resource, insted of binding ResourceReference URL of Patient in to Subject attribute of DocumentReference.
 

My intention is to set Patient object and some binary data(Custom object) along with DocumentReference object and convert it to Jason format and send it as a response for a ReST service call.

 

 

Kevin Mayfield

unread,
Oct 10, 2014, 3:29:35 AM10/10/14
to Hareesh G, hapi...@googlegroups.com
I've not looked at this in HAPI yet but the way I've done this (on other systems) is to create atom feed which would contain these resources:

DocumentReference
Patient
Binary 

I think this is what I based the above on http://www.hl7.org/implement/standards/fhir/xds-profile.html 
and when I last looked the IHE-MHD was going along the same lines.



--
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/2143cf54-3959-4b57-a031-6bfbaed7af12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hareesh G

unread,
Oct 10, 2014, 5:16:27 AM10/10/14
to hapi...@googlegroups.com, harees...@gmail.com
 
can you please explain litte more on atom feed, how can we embed Patient object with identifier, adderess and other patient details to the DocumentReference resource?
 
I have available only the 'fhir-0.0.82-Java-0.81' source code and i'm tring with this.
 
thanks,
Hareesh

david hay

unread,
Oct 10, 2014, 10:23:21 AM10/10/14
to hapi...@googlegroups.com
Hi hareesh, if you're new to FHIR, I've got a blog at fhirblog.com that might have some articles of interest. In particular there's a series on xds at http://fhirblog.com/category/xds/

Cheers...

Kevin Mayfield

unread,
Dec 23, 2014, 10:08:24 AM12/23/14
to hapi...@googlegroups.com
Haressh,

How far did you get? I've just started looking myself.

So far have found this which matches what I posted earlier 




Kevin Mayfield

unread,
Jan 28, 2015, 11:27:53 AM1/28/15
to hapi...@googlegroups.com
Have got this working now. Doubt it's correct java (Pretty sure it's my first Java program) but it working for me.

This feeds a FHIR server with a word document (Binary resource) and associated metadata (in DocumentReference resource). I've posted the bundle/rss to a Mailbox on the server. 
May not contain all the mandatory fields - the metadata I'm working with would be less than I've included here. 

package uk.nhs.jorvik.algiz;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;

import java.util.List;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dev.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu.composite.PeriodDt;
import ca.uhn.fhir.model.dev.resource.DocumentReference;
import ca.uhn.fhir.model.dev.resource.Patient;
import ca.uhn.fhir.model.dev.resource.Practitioner;
import ca.uhn.fhir.model.dev.valueset.DocumentReferenceStatusEnum;
import ca.uhn.fhir.model.dstu.composite.ContainedDt;
import ca.uhn.fhir.model.dev.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.Binary;
import ca.uhn.fhir.model.dstu.resource.Encounter;
import ca.uhn.fhir.model.primitive.DateDt;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.client.IGenericClient;


public class DocumentReferenceExample {
 
 
  public static void main(String[] args) throws IOException {
 
     // Create a client factory
 FhirContext ctx  = new FhirContext();
 
     // Create the client
     String serverBase = "http://jorvik-tiedev:49999/Mailbox";
       
     IGenericClient client = ctx.newRestfulGenericClient(serverBase);
  
     DocumentReference DocRef = new DocumentReference();
     DocRef.setId("000040_A00551189-6687378-1_02-12-2010_08-44-13_B1960_GP.doc");
     DocRef
      .addIdentifier()
      .setValue("000040_A00551189-6687378-1_02-12-2010_08-44-13_B1960_GP.doc");
     
     ResourceReferenceDt PatRef = new ResourceReferenceDt("Patient/pat1");
     DocRef.setSubject(PatRef);
     
     List<ResourceReferenceDt> AuthList = new ArrayList<ResourceReferenceDt>();
     ResourceReferenceDt PracRef = new ResourceReferenceDt("Practitioner/prac1");
     AuthList.add(PracRef);
     DocRef.setAuthor(AuthList);
     
     DateTimeDt Created = new DateTimeDt("2014-08-01T00:23:00Z");
     DocRef.setCreated(Created);
     
     ZonedDateTime now = ZonedDateTime.now( ZoneOffset.UTC );
     InstantDt Indexed = new InstantDt(now.toString());
     DocRef.setIndexed(Indexed);
     
     DocRef.setStatus(DocumentReferenceStatusEnum.CURRENT);
     DocRef.setMimeType("application/msword");
     
     CodeableConceptDt docType = new CodeableConceptDt();
     docType
      .addCoding()
      .setCode("823701000000103")
      .setDisplay("Discharge letter (record artifact)")
      .setSystem("http://snomed.info/sct");
     DocRef.setType(docType);
     
     ContainedDt Con1 = new ContainedDt();
     List<IResource> res1 = new ArrayList<IResource>();
     
     // Add Patient metadata
     Patient Pat = new Patient();
     Pat.setId("Patient/pat1");
     Pat
      .addIdentifier()
      .setSystem("urn:oid:2.16.840.1.113883.2.1.4.1")
      .setValue("9990276579");
     Pat
      .addIdentifier()
      .setValue("6687378");
     Pat
      .addIdentifier()
      .setValue("A00551189");
     Pat
      .addName()
      .addFamily("XXTESTPATIENTREAH")
      .addGiven("nic-qtp-donnotuse");
     DateDt birthDate = new DateDt("1997-07-10");
     Pat.setBirthDate(birthDate);
     
     ResourceReferenceDt DrRef = new ResourceReferenceDt("urn:oid:2.16.840.1.113883.2.1.4.4|B1960");
     Pat.setManagingOrganization(DrRef);
     res1.add(Pat);
     
     
     // Add consultant metadata
     Practitioner Consultant = new Practitioner();
     Consultant
      .addIdentifier()
      .setSystem("urn:oid:2.16.840.1.113883.2.1.4.4")
      .setValue("C9999998");
     Consultant
      .addIdentifier()
      .setValue("436");
     HumanNameDt ConsultantName = new HumanNameDt();
     ConsultantName.addFamily("DR UNKNOWN");
     
     Consultant.setName(ConsultantName);
     
     res1.add(Consultant);
     
     // DSTU1 
     Encounter Enc = new Encounter();
     Enc
      .addIdentifier()
      .setSystem("http://fhir.jorvik.nhs.uk/HSI/")
      .setValue("376579-1");
     
     DateTimeDt Started = new DateTimeDt("2014-08-01T00:15:00Z");
     
     PeriodDt period = new PeriodDt();
     period.setStart(Started);
     period.setEnd(Started);
     Enc.setPeriod(period);
     res1.add(Enc);
     
     Con1.setContainedResources(res1);
     DocRef.setContained(Con1);
     
     
     // using DSTU1 
     Binary Document = new Binary();
     Document.setId("000040_A00551189-6687378-1_02-12-2010_08-44-13_B1960_GP.doc");
     Document.setContentType("application/msword");
     
     // Read letter in byte array
     Path path = Paths.get("C:\\Apache\\Gold_standard_clinic_letter.doc");
     byte[] data = Files.readAllBytes(path);
     Document.setContent(data);
     
     List<IResource> resources = new ArrayList<IResource>();
     resources.add(DocRef);
     resources.add(Document);
      
     // Create a bundle with both
     Bundle b = Bundle.withResources(resources, ctx, "");
           
     client.transaction().withBundle(b).execute();
     
     
     
  }
 
}


Reply all
Reply to author
Forward
0 new messages