0

I am writing a java code for generating a POST request using MedicationOrder resource in HAPI - FHIR DSTU2 HL7. I have come across several troubles.

  1. Setting the reference values for the contained resources.
  2. Contained resources are not present in generated XML message.
  3. Operation outcome is HTTP/1.1 500 Internal Server Error with the message Expecting outer element called 'feed', found: MedicationOrder.

Can anyone familiar with MedicationOrder resource please help me?

below is the java code

public int sendMessage(MedicationOrder medicationOrder) throws   ClientProtocolException, IOException
{
  FhirContext ctx = FhirContext.forDstu2Hl7Org();
  IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");    
  HttpPost httpPost = new HttpPost("http://fhirtest.uhn.ca/baseDstu2");

  String message = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(medicationOrder);
  httpPost.setEntity((HttpEntity) new StringEntity(message, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));

  org.apache.http.HttpResponse response = client.getHttpClient().execute(httpPost);
  return response.getStatusLine().getStatusCode();
}
  • It is not clear what you are asking. Please include the Java code that you say you are writing - it is more helpful to include the Java code that generated these errors. Please have a look at some helpful tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) - asking a good question improves your chances of getting an answer. But it is also equally important that you search first and do some research before posting your question. Also include what you have tried and indicate the problem(s) you are experiencing. – ishmaelMakitla Jun 07 '16 at 09:54

2 Answers2

0

If the interface is complaining about "feed", then it sounds like you're using the DSTU 1 version of HAPI, not DSTU2. (Feed was changed to Bundle in DSTU 2.)

Lloyd McKenzie
  • 6,345
  • 1
  • 13
  • 10
0

It looks like you're mixing up HAPI's client with the Apache HTTP client layer (which is internal to HAPI's client, but you don't need in interact with directly).

Instead of creating the HttpPost object, just use HAPI's client to perform the create:

MethodOutcome outcome = client.create()
  .resource(medicationOrder)
  .prettyPrint()
  .encodedJson()
  .execute();
James Agnew
  • 701
  • 4
  • 3
  • I managed to overcome all the issues mentioned here. But now, there are duplicate 'contained' resources in the generated message. For example, there are 2 Location entries and 3 Organization entries. Do you have any idea? – Nethanjalie Lelwala Jun 09 '16 at 10:35