1 / 54

SCHEMATRON 技術說明

SCHEMATRON 技術說明. 99 年度電子病歷標準維護暨推廣案 教育訓練系列課程 B CDA R2 元素結構詳論. 本投影片參考來源: 1. 行政院衛生署 97 及 98 年度電子病歷推動案之專案成果. 大綱. Schematron 簡介 取得資源 語法結構 範例解析. 甚麼是 SCHEMATRON. 他是用來斷定某樣式 (pattern) 是否出現或沒有出現在被驗證的 XML 文件內。 其功能包含: Business rules validation Data reporting General validation

ornice
Télécharger la présentation

SCHEMATRON 技術說明

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SCHEMATRON技術說明 99年度電子病歷標準維護暨推廣案 教育訓練系列課程 BCDA R2元素結構詳論 本投影片參考來源: 1. 行政院衛生署97及98年度電子病歷推動案之專案成果

  2. 大綱 • Schematron簡介 • 取得資源 • 語法結構 • 範例解析

  3. 甚麼是SCHEMATRON • 他是用來斷定某樣式(pattern)是否出現或沒有出現在被驗證的XML文件內。 • 其功能包含: • Business rules validation • Data reporting • General validation • Quality control • Quality assurance • Constraint checking

  4. 驗證模式 • 有兩種驗證模式 • Grammar-based schema languages • Rule-based schema languages 資料來源:http://www.xfront.com/schematron/Two-types-of-XML-Schema-Language.html

  5. SCHEMATRON的版本 • Schematron 1.5 • http://xml.ascc.net/schematron/ • 由中央研究院所發展 • 僅支援XSLT1.0 • Schematron 1.6 • 介於Schematron 1.5與 ISO Schematron使用不多。 • ISO Schematron

  6. 取得資源

  7. 標準書 • 免費標準書下載網址: • http://standards.iso.org/ittf/PubliclyAvailableStandards/index.html • 編號:ISO/IEC19757-3:2006 • 文件名稱:Information technology -- Document Schema Definition Language (DSDL) -- Part 3: Rule-based validation -- Schematron

  8. 電子書 • Schematron • 出版社:O’REILLY • 2007.3 出版 • 共51頁 • 價格:$9.99 • Google Preview:http://oreilly.com/catalog/9780596527716/preview.html (寫的並不好)

  9. 線上教材 • Schematron Tutorial • 網址1: • http://www.zvon.org/xxl/SchematronTutorial/General/contents.html • 網址2: • http://www.xfront.com/schematron/index.html • 網址3: • http://www.dpawson.co.uk/schematron/index.html • Schematron wiki • 網址 • http://en.wikipedia.org/wiki/Schematron(資料仍不完備)

  10. 重要資源網站 • http://www.schematron.com/ • http://xml.ascc.net/schematron/ • http://www.topologi.com/

  11. 支援SCHEMATRON的XML編輯器 • XMLBlueprint XML Editor : • http://www.xmlblueprint.com/ • <oXygen/> XML Editor: • http://www.oxygenxml.com/

  12. 背景知識 • XSLT • XSLT1.0規格書 • http://www.w3.org/TR/xslt • XSLT2.0規格書 • http://www.w3.org/TR/xslt20/ • 線上教學 • http://www.w3schools.com/xsl/default.asp • XPath • XPath 1.0規格書: • http://www.w3.org/TR/xpath • XPath 2.0規格書: • http://www.w3.org/TR/xpath20/ • 線上教學 • http://www.w3schools.com/xpath/default.asp

  13. 語法結構

  14. 基礎宣告 • Namespace • http://purl.oclc.org/dsdl/schematron <?xml version=“1.0”?> <sch:schema xmlns:sch=http://purl.oclc.org/dsdl/schematron> … </sch:schema>

  15. 基本觀念 -RULES • Rules是Schematron語法結構中最基礎區塊 • 簡單結構 <rule context="book"> <!-- Insert tests to be done on "book" elements here --> .../... </rule> • 補充說明 • Context指的是被驗證XML檔中的可能元件。可用Xpath加以定義。

  16. 基本觀念-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 theISBN number with a prefix "b"</assert> </rule>

  17. 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位置。內容值則可是豐富文字內容,用以表達此報告的敘述。

  18. 補充元素 –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>

  19. 補充元素 –DIAGNOSTICS、DIAGNOSTIC • 目的:提供更豐富的錯誤訊息報告。 • 結構 • 同一個assert或report可以有好幾個diagnostic。(例如不同的語言) • 用此架構時,在assert或report元素中,要用diagnostics屬性。 • 範例 <diagnostics> <diagnostic id=“來自assert/report的定義”>訊息內容</diagnostic> <diagnostic id=“來自assert/report的定義”>訊息內容</diagnostic> </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>

  20. 補充元素 – 其他 • let:設定變數之用。 • include:引入其他schematron檔。 • name:用以代表現在節點名稱。(ISO版廢) • param:設定key-value。 • emph:用在敘述文件區塊內。 • p:定義一段文章(與HTML同)。

  21. 範例解析

  22. 範例1

  23. 範例2

  24. 範例3

  25. 範例4

  26. 範例5 驗證字串是否包含字元@

  27. 範例6

  28. 完整範例 <?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 bethe 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>

  29. 用於CDAR2

  30. 基本說明 -1 • 配合實作指引標準書的規則建立Schematron。 • 每一份實作指引標準書會宣告TemplateId,此元素為OID編碼。一個OID碼就是一個驗證檔。 • 此編碼須向HL7 Taiwan註冊使用之。 • 此編碼可能的定義模式: • 所有驗證條件式在同一個檔案。 • 分成Level 1、Level 2與Level 3三個檔案。因標準制定之層次讀取驗證檔。 • 每一個驗證條件式就指定一個OID碼(就是一個驗證條件式一個檔案)。

  31. 基本說明 -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之驗證檔)

  32. 驗證範例一 <!-- 驗證元素 --> <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為根元素 部分內容 此部分在實作指引標準書中屬一般限制式

  33. 驗證範例二 部分內容 <!-- 驗證屬性值是否為某個值 --> <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> 驗證測試條件 錯誤之詳細訊息內容 (可由實作指引書複製) 實作指引標準書之內容

  34. 驗證範例三 部分內容 <!-- 驗證屬性值是否符合編碼規範 以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"]/code[@value = current()/@code]'> /ClinicalDocument/code/@code的值需來自LOINC適當之編碼。 </sch:assert> CodeSet對照表

  35. 實務做法 • 純以XSLT技術,將所有驗證條件式寫在一個SCH檔案中。可參考CRS(Care Record Summary)範本。 • 採HL7 Template技術架構,為每一個Template建立一個SCH檔案。可參考CCD(Continuity of Care Document)範例。

  36. CRS範例說明

  37. CRS範例說明 - PHASE

  38. CRS範例說明 - PATTERM

  39. CRS範例說明 - RULE

  40. CRS範例說明 - DIAGNOSTICS

  41. CCD範例說明

  42. 補充說明-TEMPLATE Level 1 Level 2 Level 3

  43. CCD範例說明 – 主檔

  44. CCD範例說明 – ROOT ENT SCH

  45. CCD範例說明 – TEMPLATEID

  46. 工具使用 編輯階段 驗證階段

  47. 編輯階段 • Schematron符合XML規範,任何編輯器皆可編輯。但就方便性而言,應慎選XML編輯器。 • 本教材利用XMLBlueprint。

  48. 目前僅支援ISO版,所以,Namespace須為:http://purl.oclc.org/dsdl/schematron目前僅支援ISO版,所以,Namespace須為:http://purl.oclc.org/dsdl/schematron

More Related