xml/s echma /xslt 技術 1. 大綱 電子病歷標準制定過程 cda r2 實作問題 xml...
TRANSCRIPT
XML/SECHMA/XSLT 技術
1
2
大綱 電子病歷標準制定過程 CDA R2 實作問題 XML 技術簡介 XML Schema 技術 XSLT 技術 XSLT 語法 XPATH 語法 編寫技巧
電子病歷標準制定過程
背景說明 為什麼醫療院所需要知道電子病歷標準制定流程?
108 張夠用嗎? 不夠?那到底要幾張? 那弄 2000 張好了? 誰來定,誰付錢? 就算衛生署買單,那你買帳嗎?
需求
規則
電子病歷標準設計流程
紙本病歷 欄位需求清單xls/doc
實作指引標準書doc/PDF
整理 定義
規範
結構定義檔xsd
內容驗證檔sch
設計
字彙控制檔xml
病歷呈現樣式檔html
XML 範例xml
欄位變數對應檔xsl
比照
呈現樣式轉換檔xsl
複製
匯入
參照
XPath驗證用編碼
呈現用編碼
除錯
紙本病歷
1. 由需求單位提出
欄位需求清單xls/doc
1. 由病歷管理單位整理2. 並經電子病歷委員會
認可
實作指引標準書doc/PDF
1. 由標準管理單位編寫2. 若是全國通用,則可
至電子病歷標準管理系統下載。
病歷呈現樣式檔html
1. 由實作執行單位與病歷管理單位共同合作編寫
結構定義檔xsd
1. 此為 CDA R2 標準文件。
2. 由實作執行單位從電子病歷標準管理系統下載取得。
XML 範例xml
1. 由標準管理單位與實作執行單位共同編輯設計。
欄位變數對應檔xsl
1. 由下列三個單位共同設計:• 病歷管理單位• 標準管理單位• 實作執行單位
呈現樣式轉換檔xsl
1. 可由電子病歷標準管理系統下載參考。
2. 實作執行單位編輯設計。
字彙控制檔xml
1. 可經由電子病歷標準管理系統取得。
2. 由標準管理單位負責維護。
3. 由實作執行單位負責編輯。
內容驗證檔sch
1. 由實作執行單位依據實作指引標準書之內容編輯。
2. 若為全國通用者,則可至電子病歷標準管理系統下載。
最後成果
電子病歷實作問題
實踐電子病歷之問題所在
電子病歷設計管理
電子病歷文件管理
電子病歷應用管理
電子病歷流程管理
專注在「產生」電子病歷文件
19
實作可能模式 XML 編輯器
軟體有:微軟 XML Notepad 2007 、 Altova XML SPY 、oXygenXML 等。
對終端使用者不友善。 電子表單軟體
軟體有:微軟 InfoPath 、 Adobe 等 可設計符合使用者介面之資料輸入介面。
SOA/EAI 工具 軟體工具很多。微軟 BizTalk 。 須從系統流程整合角度切入使用。
程式設計 可配合實際需求撰寫。 需要程式設計開發人員。
20
技術簡述 – 標準類 臨床類:
LOINC :文件類型與區段代碼。 SNOMED :區段內容代碼。 ICD :區段內容代碼。 其他:如藥品等,區段內容代碼。
技術類: XHTML :臨床文件呈現格式 CSS : XHTML 呈現樣式 XML :臨床文件儲存格式 SCHEMA : XML 結構驗證 SCHEMATRON : XML 內容驗證 XSLT : XML 轉成 XHTML XPATH :定義 XML 各元素之位置( XSLT 與 Schematron 中會
用到) HL7 類:
RIM 、 DataType 、 Vocabulary 、 RMIM 、 CDA
POCD_MT000040.xsd
CDA.xsd
NarrativeBlock.xsd
datatypes.xsddatatypes-
base.xsd
voc.xsd
entries
narrative
header
namespaces
body區段
21
CDA R2 與資料來源的關係
資料來源
資料庫
表單
檔案
訊息
資料來源
1. 固定值:由 CDA R2 決定。只要是實作 CDA R2 就是這個碼。如 typeID
3. 系統值:由 CDA R2 程式所產生。如文件產生時間。
2. 預設值:由實作指引標準書決定。只要實作哪份單張就會決定碼。如 code
4. 不變值:資料來源是如何就如何。如姓名。
5. 限定值:資料來源需經過轉碼。如性別。
基本概念
CDA XSLT HTML
XML 技術簡介
24
什麼是 XML
XML 是指 eXtensible Markup Language 。 XML 是設計用來攜帶資料,不是顯示資料之用。 XML 的標籤 ( tag) 並未事先定義,你必須設計定義自己的標籤。
XML被設計為可以自我描述內容。 XML 是 W3C 所推薦標準。
25
簡單的 XML 範例
<note> <to> 同學 </to> <from>老師 </from> <heading> 注意事項 </heading> <body> 下週二小考 </body></note>
注意:1. XML沒有特殊規範,只是一個文字檔。2. 你可以自行創造各種標籤名稱。3. 他提供了一種與軟體、硬體獨立的交換情境。
26
XML衍生之應用
在網際網路上,因為 XML而擴展之應用 XHTML the latest version of HTML WSDL for describing available web services WAP and WML as markup languages for handheld devices RSS languages for news feeds RDF and OWL for describing resources and ontology SMIL for describing multimedia for the web
27
XML 在產業的應用
http://www.oasis-open.org/cover/xml.html#applications Web Servers: apacheXML parsers, XSL, web publishing Travel: openTravel information for airlines, hotels, and car
rental places News: NewsML creation, transfer and delivery of news Voice: VoxML markup language for voice applications Wireless: WAP (Wireless Application Protocol) wireless
devices on the World Wide Web Weather: OMF Weather Observation Markup Format (
simulation) Healthcare: HL7 DTDs for prescriptions, policies &
procedures, clinical trials Math: MathML (Mathematical Markup Language)
28
術語說明
element type
character content
element
Empty element
<bibliography>
<paper ID="object-fusion"> <authors> <author>Y.Papakonstantinou</author> <author>S. Abiteboul</author> <author>H. Garcia-Molina</author> </authors> <fullPaper source="fusion"/> <title>Object Fusion in Mediator Systems</title> <booktitle>VLDB 96</booktitle> </paper>
</bibliography>
element content
Root element type
Attribute(name,value)
29
XML 之規則
All XML Elements Must Have a Closing Tag
XML Tags are Case Sensitive
XML Elements Must be Properly Nested
<p>This is a paragraph</p><p>This is another paragraph</p>
<Message>This is incorrect</message><message>This is correct</message>
<b><i>This text is bold and italic</i></b>
30
XML 之規則
4. XML Documents Must Have a Root Element
5. XML Attribute Values Must be Quoted
6. Entity References
<root> <child> <subchild>.....</subchild> </child></root>
<note date="12/11/2007"> <to>Tove</to> <from>Jani</from></note>
< < less than > > greater than & & ampersand ' ' apostrophe " “ quotation mark
31
XML 之規則
7. Comments in XML
8. White-space is Preserved in XML
9. XML Stores New Line as LF
<!-- This is a comment -->
32
XML 之驗證
Well Formed XML Documents XML documents must have a root element XML elements must have a closing tag XML tags are case sensitive XML elements must be properly nested XML attribute values must be quoted
Valid XML Documents 符合 DTD 規範或 XML Schema
XML Namespaces identify your vocabulary
33
XML SCHEMA 技術
34
為什麼需要 XML SCHEMA
35
36
XML 與 SCHEMA
37
建立 SCHEMA 檔
Xml 文件宣告 <?xml version=“1.0”?>
建立 root element <xs:schema >
宣告 namespace http://www.w3.org/2001/XMLSchema
38
XML 檔案之引用
39
XML SCHEMA 的註解
透過 xml 編輯器,可以將此段文字顯示出來。有即時說明的作用。
40
定義簡易型態元素
41
正確
錯誤
簡易型態42
固定值與預設值
43
Valid
No valid
Valid
Valid
Valid
Valid
自定簡易型態
44
在元素中定義 可重複使用
限定範圍值 ─ 列舉
45
複雜型態46
基本說明
Xml 的元素可以分成簡單型態與複雜型態屬於複雜型態的元素,可以有子元素與屬性。 簡單型態不行有子元素與屬性。
複雜型態又可以在分成簡單內容與複雜內容 簡單內容就只能放字串。 複雜內容則可以有子元素。
Xml 範例
47
定義子元素
In order
48
定義子元素
In any order
49
定義子元素
Choices
50
參照全域變數
51
控制次數
52
定義屬性
53
XSLT 技術54
什麼是 XSLT
eXtensible Stylesheet Language for Transformations
Language for transforming XML documents
A programming language for XML documents
A functional language, based on value substitution
Augmented with pattern matching
And also template substitution to construct output (based on namespaces
Uses XML syntax
常見應用
XML to HTML— for old browsers XML to LaTeX—for TeX layout XML to SVG—graphs, charts, trees XML to tab-delimited—for db/stat packages XML to plain-text—occasionally useful XML to FO—XSL formatting objects
簡單範例
File data.xml: <?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="render.xsl"?><message>Howdy!</message>
File render.xsl: <?xml version="1.0"?>
<xsl:stylesheet version="1.0” xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- one rule, to transform the input root (/) --> <xsl:template match="/">
<html><body> <h1><xsl:value-of select="message"/></h1>
</body></html> </xsl:template></xsl:stylesheet>
XSLT 語法
THE .XSL FILE
An XSLT document has the .xsl extension The XSLT document begins with:
<?xml version="1.0"?> <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/ XSL/Transform">
Contains one or more templates, such as: <xsl:template match="/"> ... </xsl:template>
And ends with: </xsl:stylesheet>
FINDING THE MESSAGE TEXT
The template <xsl:template match="/"> says to select the entire file You can think of this as selecting the root node of the XML
tree Inside this template,
<xsl:value-of select="message"/> selects the message child Alternative Xpath expressions that would also work:
./message /message/text() (text() is an XPath function) ./message/text()
PUTTING IT TOGETHER
The XSL was: <xsl:template match="/">
<html><body> <h1><xsl:value-of select="message"/></h1>
</body></html> </xsl:template>
The <xsl:template match="/"> chooses the root The <html><body> <h1> is written to the output file The contents of message is written to the output file The </h1> </body></html> is written to the output file
The resultant file looks like: <html><body> <h1>Howdy!</h1> </body></html>
HOW XSLT WORKS
The XML text document is read in and stored as a tree of nodes
The <xsl:template match="/"> template is used to select the entire tree
The rules within the template are applied to the matching nodes, thus changing the structure of the XML tree If there are other templates, they must be called explicitly
from the main template Unmatched parts of the XML tree are not changed After the template is applied, the tree is written out again
as a text document
WHERE XSLT CAN BE USED
With an appropriate program, such as Xerces, XSLT can be used to read and write files
A server can use XSLT to change XML files into HTML files before sending them to the client
A modern browser can use XSLT to change XML into HTML on the client side This is what we will mostly be doing in this class
Most users seldom update their browsers If you want “everyone” to see your pages, do any XSL
processing on the server side Otherwise, think about what best fits your situation
MODERN BROWSERS
Internet Explorer 6 best supports XML Netscape 6 supports some of XML Internet Explorer 5.x supports an obsolete version of
XML IE5 is not good enough for this course If you must use IE5, the initial PI is different (you can look it
up if you ever need it)
XSL:VALUE-OF
<xsl:value-of select="XPath expression"/> selects the contents of an element and adds it to the output stream The select attribute is required Notice that xsl:value-of is not a container, hence it needs to
end with a slash
Example (from an earlier slide): <h1> <xsl:value-of select="message"/> </h1>
XSL:FOR-EACH
xsl:for-each is a kind of loop statement The syntax is
<xsl:for-each select="XPath expression"> Text to insert and rules to apply </xsl:for-each>
Example: to select every book (//book) and make an unordered list (<ul>) of their titles (title), use: <ul> <xsl:for-each select="//book"> <li> <xsl:value-of select="title"/> </li> </xsl:for-each> </ul>
FILTERING OUTPUT
You can filter (restrict) output by adding a criterion to the select attribute’s value: <ul> <xsl:for-each select="//book"> <li> <xsl:value-of select="title[../author='Terry Pratchett']"/> </li> </xsl:for-each> </ul>
This will select book titles by Terry Pratchett
FILTER DETAILS
Here is the filter we just used: <xsl:value-of select="title[../author='Terry Pratchett'"]/>
author is a sibling of title, so from title we have to go up to its parent, book, then back down to author
This filter requires a quote within a quote, so we need both single quotes and double quotes
Legal filter operators are: = != < > Numbers should be quoted, but apparently don’t have to be
BUT IT DOESN’T WORK RIGHT!
Here’s what we did: <xsl:for-each select="//book"> <li> <xsl:value-of select="title[../author='Terry Pratchett']"/> </li> </xsl:for-each>
This will output <li> and </li> for every book, so we will get empty bullets for authors other than Terry Pratchett
There is no obvious way to solve this with just xsl:value-of
XSL:IF
xsl:if allows us to include content if a given condition (in the test attribute) is true
Example: <xsl:for-each select=“//book”> <xsl:if test=“author=‘Terry Pratchett’”> <li><xsi:text> 作者 </xsi:text> <xsl:value-of select="title"/> </li> </xsl:if> </xsl:for-each>
This does work correctly!
XSL:CHOOSE
The xsl:choose ... xsl:when ... xsl:otherwise construct is XML’s equivalent of Java’s switch ... case ... default statement
The syntax is:<xsl:choose> <xsl:when test="some condition"> ... some code ... </xsl:when> <xsl:otherwise> ... some code ... </xsl:otherwise></xsl:choose>
• xsl:choose is often used within an xsl:for-each loop
XSL:SORT
You can place an xsl:sort inside an xsl:for-each The attribute of the sort tells what field to sort on Example:
<ul> <xsl:for-each select="//book"> <xsl:sort select="author"/> <li> <xsl:value-of select="title"/> by <xsl:value-of select="author"> </li> </xsl:for-each> </ul> This example creates a list of titles and authors, sorted by
author
XSL:TEXT
<xsl:text>...</xsl:text> helps deal with two common problems: XSL isn’t very careful with whitespace in the document
This doesn’t matter much for HTML, which collapses all whitespace anyway (though the HTML source may look ugly)
<xsl:text> gives you much better control over whitespace; it acts like the <pre> element in HTML
Since XML defines only five entities, you cannot readily put other entities (such as ) in your XSL &nbsp; almost works, but is visible on the page Here’s the secret formula for entities:
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
XPATH 技術
WHAT IS XPATH?
XPath is a syntax used for selecting parts of an XML document
The way XPath describes paths to elements is similar to the way an operating system describes paths to files
XPath is almost a small programming language; it has functions, tests, and expressions
XPath is a W3C standard XPath is not itself written as XML, but is used heavily in
XSLT
重要術語
<library> <book>
<chapter> </chapter>
<chapter> <section> <paragraph/> <paragraph/> </section> </chapter>
</book></library>
library is the parent of book; book is the
parent of the two chapters
The two chapters are the children of book,
and the section is the child of the second
chapter
The two chapters of the book are siblings
(they have the same parent)
library, book, and the second chapter are
the ancestors of the section
The two chapters, the section, and the
two paragraphs are the descendents of the
book
路徑描述
Operating system: XPath:
/ = the root directory /library = the root element (if named library )
/users/dave/foo = the file named foo in dave in users
/library/book/chapter/section = every section element in a chapter in every book in the library
. = the current directory . = the current element
.. = the parent directory .. = parent of the current element
/users/dave/* = all the files in /users/dave
/library/book/chapter/* = all the elements in /library/book/chapter
foo = the file named foo in the current directory
section = every section element that is a child of the current element
斜線應用
A path that begins with a / represents an absolute path, starting from the top of the document Example: /email/message/header/from Note that even an absolute path can select more than one
element A slash by itself means “the whole document”
A path that does not begin with a / represents a path starting from the current element Example: header/from
A path that begins with // can start from anywhere in the document Example: //header/from selects every element from that is a
child of an element header This can be expensive, since it involves searching the entire
document
中括弧與 LAST()函數
A number in brackets selects a particular matching child (counting starts from 1, except in Internet Explorer) Example: /library/book[1] selects the first book of the library Example: //chapter/section[2] selects the second section of
every chapter in the XML document Example: //book/chapter[1]/section[2] Only matching elements are counted; for example, if a book has
both sections and exercises, the latter are ignored when counting sections
The function last() in brackets selects the last matching child Example: /library/book/chapter[last()]
You can even do simple arithmetic Example: /library/book/chapter[last()-1]
星號應用
A star, or asterisk, is a “wild card”--it means “all the elements at this level” Example: /library/book/chapter/* selects every child of
every chapter of every book in the library Example: //book/* selects every child of every book
(chapters, tableOfContents, index, etc.) Example: /*/*/*/paragraph selects every paragraph that
has exactly three ancestors Example: //* selects every element in the entire document
取屬性 I
You can select attributes by themselves, or elements that have certain attributes Remember: an attribute consists of a name-value pair, for
example in <chapter num="5">, the attribute is named num
To choose the attribute itself, prefix the name with @ Example: @num will choose every attribute named num Example: //@* will choose every attribute, everywhere in the
document
To choose elements that have a given attribute, put the attribute name in square brackets Example: //chapter[@num] will select every chapter
element (anywhere in the document) that has an attribute named num
取屬性 II
//chapter[@num] selects every chapter element with an attribute num
//chapter[not(@num)] selects every chapter element that does not have a num attribute
//chapter[@*] selects every chapter element that has any attribute
//chapter[not(@*)] selects every chapter element with no attributes
屬性值
//chapter[@num='3'] selects every chapter element with an attribute num with value 3
//chapter[not(@num)] selects every chapter element that does not have a num attribute
//chapter[@*] selects every chapter element that has any attribute
//chapter[not(@*)] selects every chapter element with no attributes
The normalize-space() function can be used to remove leading and trailing spaces from a value before comparison Example: //chapter[normalize-space(@num)="3"]
軸 (AXIS) 的概念
An axis (plural axes) is a set of nodes relative to a given node; X::Y means “choose Y from the X axis” self:: is the set of current nodes (not too useful)
self::node() is the current node child:: is the default, so /child::X is the same as /X parent:: is the parent of the current node ancestor:: is all ancestors of the current node, up to and
including the root descendant:: is all descendants of the current node
(Note: never contains attribute or namespace nodes) preceding:: is everything before the current node in the entire
XML document following:: is everything after the current node in the entire
XML document
軸範例
Starting from a given node, the self, preceding, following, ancestor, and descendant axes form a partition of all the nodes (if we ignore attribute and namespace nodes)
<library> <book> <chapter/> <chapter> <section> <paragraph/> <paragraph/> </section> </chapter> <chapter/> </book> <book/></library>
//chapter[2]/self::*
//chapter[2]/preceding::*
//chapter[2]/following::*
//chapter[2]/ancestor::*
//chapter[2]/
descendant::*
算數式
+ add - subtract * multiply div (not /) divide mod modulo (remainder)
等式測試
= “equals” (Notice it’s not ==) != “not equals” But it’s not that simple!
value = node-set will be true if the node-set contains any node with a value that matches value
value != node-set will be true if the node-set contains any node with a value that does not match value
Hence, value = node-set and value != node-set may both be true at
the same time!
其他布林運算子
and (infix operator) or (infix operator)
Example: count = 0 or count = 1 not() (function)
The following are used for numerical comparisons only: < “less than” Some places may require < <= “less than Some places may require <=
or equal to” > “greater than” Some places may require > >= “greater than Some places may require >=
or equal to”
感 謝 聆 聽
電子病歷是一門學問 不是一項技術