B33_13_Schematron技術說明

Download Report

Transcript B33_13_Schematron技術說明

SCHEMATRON技術說明
99年度電子病歷標準維護暨推廣案
教育訓練系列課程 B CDA R2元素結構詳論
本投影片參考來源:
1. 行政院衛生署97及98年度電子病歷推動案之專案成果
大綱
Schematron簡介
 取得資源
 語法結構
 範例解析

甚麼是SCHEMATRON
他是用來斷定某樣式(pattern)是否出現或沒有出現在
被驗證的XML文件內。
 其功能包含:







Business rules validation
Data reporting
General validation
Quality control
Quality assurance
Constraint checking
驗證模式

有兩種驗證模式
Grammar-based schema languages
 Rule-based schema languages

資料來源:http://www.xfront.com/schematron/Two-types-ofXML-Schema-Language.html
SCHEMATRON的版本

Schematron 1.5
http://xml.ascc.net/schematron/
 由中央研究院所發展
 僅支援XSLT 1.0


Schematron 1.6


介於Schematron 1.5與 ISO Schematron使用不多。
ISO Schematron
取得資源
標準書

免費標準書下載網址:
http://standards.iso.org/ittf/PubliclyAvailableStandards/index.
html
 編號:ISO/IEC 19757-3:2006
 文件名稱:Information technology -- Document Schema
Definition Language (DSDL) -- Part 3: Rule-based validation
-- Schematron

電子書

Schematron





出版社:O’REILLY
2007.3 出版
共51頁
價格:$9.99
Google Preview:
http://oreilly.com/catalog/9780596527716/preview.ht
ml
(寫的並不好)
線上教材

Schematron Tutorial

網址1:


網址2:


http://www.xfront.com/schematron/index.html
網址3:


http://www.zvon.org/xxl/SchematronTutorial/General/contents.html
http://www.dpawson.co.uk/schematron/index.html
Schematron wiki

網址

http://en.wikipedia.org/wiki/Schematron (資料仍不完備)
重要資源網站
http://www.schematron.com/
 http://xml.ascc.net/schematron/
 http://www.topologi.com/

支援SCHEMATRON的XML編輯器

XMLBlueprint XML Editor :


http://www.xmlblueprint.com/
<oXygen/> XML Editor :

http://www.oxygenxml.com/
背景知識

XSLT

XSLT 1.0規格書


XSLT 2.0規格書


http://www.w3.org/TR/xslt20
/
線上教學


http://www.w3.org/TR/xslt
http://www.w3schools.com/x
sl/default.asp
XPath

XPath 1.0規格書:


http://www.w3.org/TR/xpath
XPath 2.0規格書:


http://www.w3.org/TR/xpath
20/
線上教學

http://www.w3schools.com/x
path/default.asp
語法結構
基礎宣告

Namespace

http://purl.oclc.org/dsdl/schematron
<?xml version=“1.0”?>
<sch:schema xmlns:sch=http://purl.oclc.org/dsdl/schematron>
…
</sch:schema>
基本觀念 - RULES
Rules是Schematron語法結構中最基礎區塊
 簡單結構

<rule context="book">
<!-Insert tests to be done on "book" elements here
-->
.../...
</rule>

補充說明
 Context指的是被驗證XML檔中的可能元件。可用Xpath
加以定義。
基本觀念- TESTING
定義規則區塊後,接著要說此規則的測試條件。
 測試方式有兩種:

assert:當條件不符合時,警示訊息。一定有錯。
 report:當條件符合時,報告資訊。不一定有錯。


範例
<rule context="book">
<assert test="@id">Missing "id" attribute.</assert>
<assert test="isbn">Missing "isbn" element.</assert>
<assert test=“@id = concat(‘b’, isbn)”>The “id” attribute should be the ISBN
number with a prefix "b"</assert>
</rule>
SCHEMATRON 最簡結構

<schema xmlns=“http://purl.oclc.org/dsdl/schematron”>
包含



[0..1]<title> 之後
[0..n] <ns prefix=“???” uri=“???” /> 用來定義namespaces與
prefixes, 如 Xpaths等其他的標準,之後
[1..n] <pattern>,包含

[1..n]<rule context=“???”> 式中context屬性內容是一個XSLT 的
表達式,包含


<assert test=“???”> 式中test屬性內容是一個Xpath位置。內容值則可是
豐富文字內容,用以表達此警示的敘述。
<report test=“???”>式中test屬性內容是一個Xpath位置。內容值則可是
豐富文字內容,用以表達此報告的敘述。
補充元素 – PHASE、 ACTIVE
 這兩個元素配合起來可宣告不同等級的驗證。
例如說,可以規劃成error、 warning、 manual
三種不同【嚴重度】之驗證規則。
 phase以屬性id名稱作辨識。
 active用屬性patterm作辨識。注意,此patterm
的屬性值要與patterm元素的id屬性相對應。
 範例
<phase id='errors'>
<active pattern='ClinicalDocument'/>
<active pattern='ClinicalDocument_General_Constraints'/>
…
</phase>
<phase id='warning'>
<active pattern='ClinicalDocument_General_Constraints_Warnings'/>
<active pattern='recordTarget_warnings'/>
…
</phase>
<phase id='manual'>
<active pattern='Body_manual'/>
<active pattern='ClinicalDocument_code_manual'/>
</phase>
補充元素 – DIAGNOSTICS、DIAGNOSTIC
目的:提供更豐富的錯誤訊息報告。
<diagnostics>
 結構
<diagnostic id=“來自assert/report的定義”>訊息內容</diagnostic>

<diagnostic id=“來自assert/report的定義”>訊息內容</diagnostic>
</diagnostics>
同一個assert或report可以有好幾個diagnostic。(例如不同的
語言)
 用此架構時,在assert或report元素中,要用diagnostics屬性。
 範例

<rule context="*[@id]">
<report test=“preceding::*/@id = @id” diagnostics=“idAttribute ”>Duplicated id attribute in a
"<name/>" element.</report>
</rule>
.../...
<diagnostic id="idAttribute"> The value of the duplicated id attribute
is "<value-of select="@id"/>".</diagnostic>
補充元素 – 其他
let:設定變數之用。
 include:引入其他schematron檔。
 name:用以代表現在節點名稱。(ISO版廢)
 param:設定key-value。
 emph:用在敘述文件區塊內。
 p:定義一段文章(與HTML同)。

範例解析
範例1
範例2
範例3
範例4
範例5
驗證字串是否包含字元@
範例6
完整範例
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.ascc.net/xml/schematron">
<pattern name="main">
<rule context="book">
<assert test="@id">Missing "id" attribute.</assert>
<assert test="isbn">Missing "isbn" element.</assert>
<assert test=“@id = concat(‘b’, isbn)”>The “id” attribute should be the ISBN number with a prefix “b”
</assert>
</rule>
<rule context="*[@id]">
<report test=“preceding::*/@id = @id” diagnostics="idAttribute-en idAttribute-fr "/>
</rule>
</pattern>
<diagnostics>
<diagnostic id=“idAttribute-en” xml:lang=“en”>The id attribute “<value-of select=”@id“/>” is duplicated in
element "<value-of select="name()"/>".</diagnostic>
<diagnostic id=“idAttribute-fr” xml:lang=“fr”>L‘attribut id “<value-of select=”@id“/>” de l’élément "<value-of
select="name()"/> est dupliqué".</diagnostic>
</diagnostics>
</schema>
用於CDA R2
基本說明 - 1
配合實作指引標準書的規則建立Schematron。
 每一份實作指引標準書會宣告TemplateId,此元素為
OID編碼。一個OID碼就是一個驗證檔。



此編碼須向HL7 Taiwan註冊使用之。
此編碼可能的定義模式:
所有驗證條件式在同一個檔案。
 分成Level 1、Level 2與Level 3三個檔案。因標準制定之層次讀
取驗證檔。
 每一個驗證條件式就指定一個OID碼(就是一個驗證條件式一個
檔案)。

基本說明 - 2

在實作指引標準書中
<ClinicalDocument xmlns='urn:hl7-org:v3'>
…
<templateId extension='IMPL_CDAR2_LEVEL1' root='2.16.840.1.113883.10.1'/>
<templateId extension=‘IMPL_CDAR2_LEVEL2’ root=‘2.16.840.1.113883.10.2’/>
…
…
 驗證檔案
</ ClinicalDocument>
(此為CCD之驗證檔)
驗證範例一
<!-- 驗證元素 -->
<sch:pattern name="ClinicalDocument" id="ClinicalDocument">
<sch:p>驗證是否為CDA R2之臨床文件</sch:p>
<sch:rule id="cda-root" context="/*">
<sch:assert test="self::cda:ClinicalDocument">
錯誤:出院病歷摘要必須要有於 urn:hl7-org-v3命名空間的
ClinicalDocument元素。</sch:assert>
</sch:rule>
</sch:pattern>
測此文件是否以
部分內容
ClinicalDocument為根元素
此部分在實作指引
標準書中屬一般限
制式
驗證範例二
部分內容
<!-- 驗證屬性值是否為某個值 -->
<sch:pattern name="ClinicalDocument_typeId"
id="ClinicalDocument_typeId">
<sch:rule id='cda-typeid' context="/cda:ClinicalDocument/cda:typeId">
<sch:assert id='typeId-extension' diagnostics='L1-1' test='@extension
= "POCD_HD000040"'/>
</sch:rule>
驗證測試條件
錯誤之詳細訊息內容
</sch:pattern>
(可由實作指引書複製)
<sch:diagnostic id="L1-1">
錯誤: typeId元素中extension屬性必須是POCD_HD000040
</sch:diagnostic>
實作指引標
準書之內容
驗證範例三
部分內容
<!-- 驗證屬性值是否符合編碼規範 以voc.xml來驗證之。-->
<sch:pattern name="ClinicalDocument_code"
id="ClinicalDocument_code">
<sch:rule id="cda-code" context="/cda:ClinicalDocument/cda:code">
<sch:assert diagnostics='L1-7‘
test='document("voc.xml")/systems/system[@codeSystemName="LOINC"]/co
de[@value = current()/@code]'>
/ClinicalDocument/code/@code的值需來自LOINC適當之編碼。
</sch:assert>
Code Set對照表
實務做法
純以XSLT技術,將所有驗證條件式寫在一個SCH檔
案中。可參考CRS (Care Record Summary)範本。
 採HL7 Template技術架構,為每一個Template建立一
個SCH檔案。可參考CCD (Continuity of Care
Document)範例。

CRS範例說明
CRS範例說明 - PHASE
CRS範例說明 - PATTERM
CRS範例說明 - RULE
CRS範例說明 - DIAGNOSTICS
CCD範例說明
補充說明-TEMPLATE
Level 1
Level 2
Level 3
CCD範例說明 – 主檔
CCD範例說明 – ROOT
SCH
ENT
CCD範例說明 – TEMPLATEID
工具使用
編輯階段
驗證階段
編輯階段
Schematron符合XML規範,任何編輯器皆可編輯。但
就方便性而言,應慎選XML編輯器。
 本教材利用XMLBlueprint。

目前僅支援ISO版,所以,Namespace須為:
http://purl.oclc.org/dsdl/schematron
1. 此驗證是指針對此SCH檔案是否符合
SCHEMATRON規範的驗證,而非
CDA R2 XML檔案之驗證。
2. 目前支援之驗證工具有Jing、Libxml2、
MSV。
驗證階段

驗證方式有
透過有支援Schematron的XML編輯器
 採用Schematron Validator (目前不支援中文)
 XSLT設計模式 (有點複雜。抱歉!目前我尚未測試成功)

使用編輯器驗證 - XMLBLUEPRINT
使用編輯器驗證 – OXYGEN XML