Skip to content

Instantly share code, notes, and snippets.

@KevinMayfield
Last active June 20, 2017 14:10
Show Gist options
  • Save KevinMayfield/e841cf9ae2504d22e372ca51379f1160 to your computer and use it in GitHub Desktop.
Save KevinMayfield/e841cf9ae2504d22e372ca51379f1160 to your computer and use it in GitHub Desktop.
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt;
import ca.uhn.fhir.model.dstu2.resource.MedicationOrder;
import ca.uhn.fhir.model.dstu2.valueset.MedicationOrderStatusEnum;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.parser.IParser;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class ExampleMedicationOrderDb {
public static MedicationOrder buildCareConnectFHIRMedicationOrderBristol() {
FhirContext ctxFHIR = FhirContext.forDstu2();
IParser parser = ctxFHIR.newXmlParser();
MedicationOrder prescription = new MedicationOrder();
prescription.setId("6bf79485-cee5-4a20-8e4a-4bf13aba33e6");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<IdDt> profiles = new ArrayList<IdDt>();
profiles.add(new IdDt(CareConnectSystem.ProfileMedicationOrder));
ResourceMetadataKeyEnum.PROFILES.put(prescription, profiles);
ExtensionDt supplyType = new ExtensionDt();
supplyType.setUrl(CareConnectSystem.ExtUrlMedicationSupplyType);
CodeableConceptDt supplyCode = new CodeableConceptDt();
supplyCode.addCoding()
.setCode("394823007")
.setSystem(CareConnectSystem.SNOMEDCT)
.setDisplay("NHS Prescription"); // Field: Private=false
supplyType.setValue(supplyCode);
prescription.addUndeclaredExtension(supplyType);
prescription.setPatient(new ResourceReferenceDt("Patient/6a7d31db-0bb8-4afa-bf4c-c32d5d4b8487")); // Field: PatientId
prescription.getPatient().setDisplay("Karen Sansom");
Date issueDate;
try {
issueDate = dateFormat.parse("2017-05-25"); // Field: IssueDate
prescription.setDateWritten(new DateTimeDt(issueDate));
} catch (ParseException e) {
e.printStackTrace();
}
// The drug hasn't been cancelled so regarding it as active. This is a mandatory CareConnect element
prescription.setStatus(MedicationOrderStatusEnum.ACTIVE); // Field: Cancelled
prescription.setPrescriber(new ResourceReferenceDt("Practitioner/651dfe43-26d6-49b3-b493-8955415912c7")); // Field: PractitionerId
prescription.getPrescriber().setDisplay("Dr Kevin Swamp");
CodeableConceptDt drugCode = new CodeableConceptDt();
drugCode.addCoding()
.setCode("321153009") // Field: Drug Code (SNOMED CT)
.setSystem(CareConnectSystem.SNOMEDCT)
.setDisplay("Temazepam Tablets 20 mg"); // Field: Drug Name
prescription.setMedication(drugCode);
MedicationOrder.DosageInstruction dosage = prescription.addDosageInstruction();
dosage.setText("1on"); // Field: Dosage
SimpleQuantityDt quantity = new SimpleQuantityDt();
quantity.setValue(60); // Field: Quantity
quantity.setSystem(CareConnectSystem.SNOMEDCT);
quantity.setCode("428673006"); // This means tablets
quantity.setUnit("tablets"); // Field: Quantity Units
dosage.setDose(quantity);
System.out.println(parser.setPrettyPrint(true).encodeResourceToString(prescription));
return prescription;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment