<?xml version="1.0" encoding="UTF-8"?><Library xmlns="http://hl7.org/fhir">
  <id value="ExampleEventDefinitionLogic"/>
  <meta>
    <security>
      <system value="http://terminology.hl7.org/CodeSystem/v3-ActReason"/>
      <code value="HTEST"/>
      <display value="test health data"/>
    </security>
  </meta>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml">
      <p class="res-header-id">
        <b>Generated Narrative: Library ExampleEventDefinitionLogic</b>
      </p>
      <a name="ExampleEventDefinitionLogic"> </a>
      <a name="hcExampleEventDefinitionLogic"> </a>
      <h2>Contents</h2>
      <p>
        <code>text/cql</code>
      </p>
      <pre>
        <code class="language-sql">library ExampleEventDefinitionLogic

using FHIR

include FHIRHelpers

codesystem "LOINC": 'http://loinc.org'

code "LA6577-6|http://loinc.org": 'LA6577-6' from "LOINC"

valueset "Stick Test Codes": 'http://example.org/ValueSet/stick-test-codes'

context Patient

parameter %context Encounter

define StickTest:
  [Observation: "Stick Test Codes"] O
    where O.status in { 'final', 'amended', 'corrected' }

// These functions are all candidates for [FHIRCommon](https://hl7.org/fhir/uv/cql/Library-FHIRCommon.html)
// Or perhaps a FHIRCommonObservation library
define fluent function negative(observations List&lt;Observation&gt;):
  observations O
    where O.interpretation ~ "LA6577-6|http://loinc.org"

define fluent function during(observations List&lt;Observation&gt;, encounter Encounter):
  observations O
    where O.issued during minute of encounter.period

define fluent function within(observations List&lt;Observation&gt;, quantity Quantity):
  observations O
    where (O.issued + quantity) on or after minute of Now()

define fluent function consecutively(observations List&lt;Observation&gt;):
  observations O
    sort by issued

define fluent function consecutivelyAfter(observations List&lt;Observation&gt;, observation Observation):
  observations O
    where O.issued on or after observation.issued
    sort by issued</code>
      </pre>
    </div>
  </text>
  <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-wg">
    <valueCode value="cds"/>
  </extension>
  <url value="http://hl7.org/fhir/EventDefinition/ExampleEventDefinitionLogic"/>
  <version value="6.0.0-ballot3"/>
  <name value="ExampleEventDefinitionLogic"/>
  <title value="Example EventDefinition Logic"/>
  <status value="active"/>
  <experimental value="true"/>
  <type>
    <coding>
      <code value="logic-library"/>
    </coding>
  </type>
  <date value="2016-03-08"/>
  <publisher value="HL7 International / Clinical Decision Support"/>
  <contact>
    <telecom>
      <system value="url"/>
      <value value="http://www.hl7.org/Special/committees/dss"/>
    </telecom>
  </contact>
  <description value="Example EventDefinition Logic"/>
  <content>
    <contentType value="text/cql"/>
    <data value="bGlicmFyeSBFeGFtcGxlRXZlbnREZWZpbml0aW9uTG9naWMKCnVzaW5nIEZISVIKCmluY2x1ZGUgRkhJUkhlbHBlcnMKCmNvZGVzeXN0ZW0gIkxPSU5DIjogJ2h0dHA6Ly9sb2luYy5vcmcnCgpjb2RlICJMQTY1NzctNnxodHRwOi8vbG9pbmMub3JnIjogJ0xBNjU3Ny02JyBmcm9tICJMT0lOQyIKCnZhbHVlc2V0ICJTdGljayBUZXN0IENvZGVzIjogJ2h0dHA6Ly9leGFtcGxlLm9yZy9WYWx1ZVNldC9zdGljay10ZXN0LWNvZGVzJwoKY29udGV4dCBQYXRpZW50CgpwYXJhbWV0ZXIgJWNvbnRleHQgRW5jb3VudGVyCgpkZWZpbmUgU3RpY2tUZXN0OgogIFtPYnNlcnZhdGlvbjogIlN0aWNrIFRlc3QgQ29kZXMiXSBPCiAgICB3aGVyZSBPLnN0YXR1cyBpbiB7ICdmaW5hbCcsICdhbWVuZGVkJywgJ2NvcnJlY3RlZCcgfQoKLy8gVGhlc2UgZnVuY3Rpb25zIGFyZSBhbGwgY2FuZGlkYXRlcyBmb3IgW0ZISVJDb21tb25dKGh0dHBzOi8vaGw3Lm9yZy9maGlyL3V2L2NxbC9MaWJyYXJ5LUZISVJDb21tb24uaHRtbCkKLy8gT3IgcGVyaGFwcyBhIEZISVJDb21tb25PYnNlcnZhdGlvbiBsaWJyYXJ5CmRlZmluZSBmbHVlbnQgZnVuY3Rpb24gbmVnYXRpdmUob2JzZXJ2YXRpb25zIExpc3Q8T2JzZXJ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