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.
- Setting the reference values for the contained resources.
- Contained resources are not present in generated XML message.
- 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();
}