Reputation: 77
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.
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();
}
Upvotes: 0
Views: 903
Reputation: 701
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();
Upvotes: 0
Reputation: 6803
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.)
Upvotes: 0