1

I am using Hapi FHIR DSTU2 HL7Org. In my application, I need to create a MedicationOrder and provide the possibility of updating/ deleting erroneous entries. I have the id, patientId, etc of the created MedicationOrder, but writing a code with where clause is pretty problematic. In all the examples I have seen, entries like

where(Patient.FAMILY.matches().value("duck") 

presents, but I get SP_PATIENT, SP_STATUS, etc.

FhirContext ctx = FhirContext.forDstu2Hl7Org();
IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");
Bundle bundle = client.search().forResource(MedicationOrder.class).where(MedicationOrder.SP_PATIENT.equals("patientId")).returnBundle(Bundle.class).encodedXml().prettyPrint().execute();

The above code does not compile saying "The method where(ICriterion) in the type IQuery is not applicable for the arguments (boolean)". I could not manage to create any IQuery object.

Can someone please instruct me how to proceed?

1 Answers1

1

This is a bit of a weird one- the DSTU2 HL7Org structures were created at a point where we hadn't yet brought all of the model features over from HAPI's structures into the HL7Org ones. Those "non-SP" criterion constants are one of the things we hadn't copied over.

The good news is that you can still use the ones from the DSTU2 or DSTU3 structures if you want, even if you are using the DSTU2-Hl7Org structures. You could do this with something like:

FhirContext ctx = FhirContext.forDstu2Hl7Org();
IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");
Bundle bundle = client.search().forResource(MedicationOrder.class).where(ca.uhn.fhir.model.dstu2.resource.MedicationOrder.PATIENT.matches().value("duck")).returnBundle(Bundle.class).encodedXml().prettyPrint().execute();
James Agnew
  • 701
  • 4
  • 3
  • Thanks @James Agnew. I thought the resource url is unique for a given resource, so if I update/delete a resource, the where clause should contain it. But I see there is nothing like this in available search parameters. Is there any workaround for this? – Nethanjalie Lelwala Jun 22 '16 at 04:49
  • Sorry, I'm not sure I follow. The code you show is for searching, not creating or deleting. You could take the results and delete them if you wanted. If you're trying to do a conditional delete, there is an example of this on our documentation page [here](http://hapifhir.io/doc_rest_client.html#Conditional_Deletes) and you could do the same type of where clause. – James Agnew Jun 22 '16 at 16:00
  • Hi, My application creates MedicationOrder resources in a remote FHIR server and the ability to delete a created resource should also be available. Since a patient can have multiple orders for different administer times, I thought a conditional delete using the idPart is the best here. Is this serving that purpose? `client.delete().resourceById("MedicationOrder", "").encodedXml().prettyPrint().execute();` – Nethanjalie Lelwala Jun 24 '16 at 06:09
  • That does sound like a conditional delete. Something like the following should do it: `client.delete() .resourceConditionalByType("MedicationOrder") .where(MedicationOrder.PATIENT.hasId("123")) .execute();` – James Agnew Jun 24 '16 at 12:40
  • We need it to be searched n deleted by the value we set for the identifier, not by the patient id, obviously a single patient can have many medication orders. MedicationOrder has only the search Parameters like SP_IDENTIFIER and such conditions give the same error as the original question – Nethanjalie Lelwala Nov 30 '16 at 08:47