Sample FormEntry XSLT


The following is an example of a default XSLT used to translate FormEntry data submissions from XML into a pipe-delimited HL7 message.

Download from here.

Changes in 1.9.5

  • Added support for subsections (observations can be one or two layers deep), allowing for forms to use subsections to better organize their observations.
The "obsList" changed from...
 <xsl:variable name="obsList" select="obs/*[(@openmrs_concept and value and 
   value/text() != ) or *[@openmrs_concept and text()='true']]"/>
to...
 <xsl:variable name="obsList" select="obs/*[(@openmrs_concept and value and 
   value/text() != ) or *[@openmrs_concept and text()='true']]|
   obs/*[not(@openmrs_concept)]/*[(@openmrs_concept and value and value/text() != ) 
   or *[@openmrs_concept and text()='true']]" />
and "obsGroupList" changed from...
 <xsl:variable name="obsGroupList" select="obs/*[@openmrs_concept and 
   not(date) and *[(@openmrs_concept and value and value/text() != ) or 
   *[@openmrs_concept and text()='true']]]"/>
to...
 <xsl:variable name="obsGroupList" select="obs/*[@openmrs_concept and 
   not(date) and *[(@openmrs_concept and value and value/text() != ) or 
   *[@openmrs_concept and text()='true']]]|obs/*[not(@openmrs_concept)]/*[@openmrs_concept 
   and not(date) and *[(@openmrs_concept and value and value/text() != ) or 
   *[@openmrs_concept and text()='true']]]" />

Changes in 1.9.4

  • Added support for unique id (/form/header/uid) for forms that transforms into HL7 control id
In MSH-10, we replaced...
<xsl:text>formentry-</xsl:text>
<xsl:call-template name="hl7Timestamp">
  <xsl:with-param name="date" select="current-dateTime()" />
</xsl:call-template>
with...
<xsl:choose>
  <xsl:when test="header/uid">
    <xsl:value-of select="header/uid" />
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="patient/patient.patient_id" />
    <xsl:call-template name="hl7Timestamp">
      <xsl:with-param name="date" select="current-dateTime()" />
    </xsl:call-template>
  </xsl:otherwise>
</xsl:choose>
  • The following was added to PV1-37 to fill HL7's Discharge To field with any value from /form/patient/patient.health_center. This is used during HL7 processing to update the patient's health center. Note: since all values entered from InfoPath's task pane currently use the format "123^Asthma" to emulate HL7 id & name separated by a circumflex (^), we strip only the first part — PV1-37 expects the 2nd component to be a date. We could consider translating the circumflex to a subcomponent delimiter (&) in the future if we want to preserve the location name.
<xsl:if test="patient/patient.health_center">
  <xsl:value-of select="replace(patient/patient.health_center,'\^','&')" />
</xsl:if>
  • To correct an error when encounter dates are manually entered in InfoPath (#265), lines of the form:
<xsl:with-param name="date" select="xs:date(encounter/encounter.encounter_datetime)" />
were replaced with...
<xsl:with-param name="date" select="encounter/encounter.encounter_datetime" />
  • To correct an error with rounding up tenths of seconds, the XPath floor() function was added around the seconds-from-dateTime() and seconds-from-time() methods, e.g.
seconds-from-dateTime($date)
became
floor(seconds-from-dateTime($date)
and
seconds-from-time($time)
became
floor(seconds-from-time($time))