Ocean EhrGate - Composition Builder programming example
Introduction
In this example, the content of an openEHR Composition is created using a 'Template Data Object' (TDO), generated from an openEHR Template. The method set in the TDO corresponds to specific nodes and names within the template.
Example
An example is shown below illustrating how to get a CompositionBuilder instance and how to build a composition.
Example: build composition for a Lipid report.
Step 1: Ensure having the following archetypes and template:
- openEHR-EHR-COMPOSITION.report.v1
- openEHR-EHR-OBSERVATION.laboratory-lipids.v1
- template id: lab_report
Step 2: Get an EhrGate instance and log into ehrGate
Step 3: Finding and opening an EHR.
Step 4: Begin a contribution for the current EHR.
ehrGate.CreateContribution();
Step 5-a: Get a CompositionBuilder instance with the known composition archetype ID.
OpenEhrV1.Composition.ICompositionBuilder lipidCompositionBuilder = ehrGate.CreateComposition("openEHR-EHR-COMPOSITION.report.v1");
Step 5-b: Get a CompositionBuilder instance with the known template ID. If you want to create a composition from an existing template, then you can use the code below.
OpenEhrV1.Composition.ICompositionBuilder lipidCompositionBuilder = ehrGate.CreateComposition("Lipids");
Step 6: Set composition name (e.g. Lipid Report) and composer name (e.g. EhrGateUnit)
lipidCompositionBuilder.SetComposition("Lipid Report", "EhrGateUnit");
Step 7: Set composition context values. Note that the appropriate EHR path (e.g. "/context/other_context/items[at0002]/items[at0004]") is required to indicate where to set the value.
// set report time and health care facility name lipidCompositionBuilder.SetContext(new Iso8601DateTime(DateTime.Now), "Pathlab"); // Set requesting clinician name lipidCompositionBuilder.SetTextValue( "/context/other_context/items[at0002]/items[at0004]", "Sam Heard"); // Set report Id lipidCompositionBuilder.SetTextValue( "/context/other_context/items[at0006]/items[at0007]", "reportId"); // Set report status, "at0015" is an internal code, means "Final" lipidCompositionBuilder .SetCodedValue( "/context/other_context/items[at0006]/items[at0014]", "at0015"); // Set report issued date/time lipidCompositionBuilder .SetDateTimeValue( "/context/other_context/items[at0006]/items[at0013]", new Iso8601DateTime(DateTime.Now));
Step 8: Add an observation to the composition and the observation path is returned.
string observationPath = lipidCompositionBuilder .AddObservation ("/content","openEHR-EHR-OBSERVATION.laboratory-lipids.v1", "Lipids");
Step 9: Set total cholestrol value
// set total cholestrol value string totalCholestrolPath = observationPath + "/data[at0001]/events[at0002] and name/value='Any event'] /data[at0003]/items[at0013.1]"; lipidCompositionBuilder.SetQuantityValue(totalCholestrolPath, 5.2, "mmol/l");
Step 10: Set triglycerides value
// set triglycerides value string triglyceridesPath = observationPath + "/data[at0001]/events [at0002 and name/value='Any event']/data[t0003]/items[at0013.2]"; lipidCompositionBuilder.SetQuantityValue(triglyceridesPath, 2.2, "mmol/l");
Step 11: Set HDL value
// set HDL value string hdlPath = observationPath + " /data[at0001]/events[at0002 and name/value='Any event']/data[at0003]/items[at0011.1 and name/value='Fractions']/items[at0013.3 and name/value='HDL-Cholesterol']"; lipidCompositionBuilder.SetQuantityValue(hdlPath, 2.3, "mmol/l", hdlNormalRange);
Step 12: Set LDL value
// set LDL value string ldlPath = observationPath + "/data\[at0001]/events[at0002 and{color} name/value='Any event']/data[at0003]/items[at0011.1 and name/value='Fractions']/items[at0013.4 and name/value='LDL-Cholesterol']"; lipidCompositionBuilder .SetQuantityValue(ldlPath, 3.1, "mmol/l");
Step 13: Set ratio
// set ratio string ratioPath = observationPath + "/data[at0001]/events[at0002 and name/value='Any event']/data\[at0003]/items[at0011.1 and name/value='Fractions']/items[at0013.5]"; lipidCompositionBuilder .SetProportionValue( ratioPath, 4.0F, 1F, OceanEhr.OpenEhrV1.DataTypes.Quantity.ProportionKind.pkRatio, true, 0);
Step 14: Set protocol details
// set speciman details string dateTimeReceivedPath = observationPath + "/protocol[at0033]/items[at0039]/items[at0040]"; lipidCompositionBuilder .SetDateTimeValue(dateTimeReceivedPath, new Iso8601DateTime("20070202T103234+1030")); // Set the date and time value when the speciman was processed. string dateTimeProcessedPath = observationPath + "/protocol[at0033]/items[at0039]/items[at0041]"; lipidCompositionBuilder .SetDateTimeValue(dateTimeProcessedPath, new Iso8601DateTime("20070202T153234+1030"));