2018年12月24日 星期一

HL7 FHIR 資源格式篇 - XML

有了資源的結構定義後,重點還是在於交換時的內容到底是什麼。
HL7 FHIR 總共支援三種格式:XML、JSON與RDF(話說RDF很重要,但是我還是對他沒什麼感覺。)
這篇來說說XML。
講內容,得先講結構(講結構,得先懂UML)。假設我們有下列結構:
那XML的基本款(Template)長這樣子。
 <name xmlns="http://hl7.org/fhir" (attrA="value")>   doco
   <!-- from Resource: id, meta, implicitRules, and language -->
   <nameA><!-- ?? 1..1 TypeA description of content  --><nameA>
   <nameB[x]><!-- 0..1 TypeB|typeC description  --></nameB[x]>
   <nameC> <!--  1..* -->
     <nameD><!-- 1..1 TypeD>Relevant elements  --></nameD>
   </nameC>
 <name>
<name>是根元素,一定是某一個Resource的名稱。
第一個看到的子元素就是nameA,Card.是1..1,這是必要element。
接著是子元素nameB,但他是選擇性元素。實際上出現在XML的element名稱,是nameBType1或nameBType2的其中一個。兩者不會同時出現。
再來是子元素nameC。喔!他是BackboneElement,他是由外部類別以Composition黏過來的。然後,開始展開這個外部類別的子元素。
接著你要發出疑問,這些事element的名稱呀,那值要放在哪裡呢?
回想一下,所有的看到的「欄位」都是來自Element。Element有一條限制式,要嘛你有sub-Element,否則你就要有@value這個屬性。
剛剛那張圖,稱之為Template,而不是交換的內容值。
下面是Patient的XML Template,很複雜吧。是不是直接看Structure比較舒服一點。
<Patient xmlns="http://hl7.org/fhir"> doco
 <!-- from Resource: id, meta, implicitRules, and language -->
 <!-- from DomainResource: text, contained, extension, and modifierExtension -->
 <identifier><!-- 0..* Identifier An identifier for this patient --></identifier>
 <active value="[boolean]"/><!-- 0..1 Whether this patient's record is in active use -->
 <name><!-- 0..* HumanName A name associated with the patient --></name>
 <telecom><!-- 0..* ContactPoint A contact detail for the individual --></telecom>
 <gender value="[code]"/><!-- 0..1 male | female | other | unknown -->
 <birthDate value="[date]"/><!-- 0..1 The date of birth for the individual -->
 <deceased[x]><!-- 0..1 boolean|dateTime Indicates if the individual is deceased or not --></deceased[x]>
 <address><!-- 0..* Address An address for the individual --></address>
 <maritalStatus><!-- 0..1 CodeableConcept Marital (civil) status of a patient --></maritalStatus>
 <multipleBirth[x]><!-- 0..1 boolean|integer Whether patient is part of a multiple birth --></multipleBirth[x]>
 <photo><!-- 0..* Attachment Image of the patient --></photo>
 <contact>  <!-- 0..* A contact party (e.g. guardian, partner, friend) for the patient -->
  <relationship><!-- 0..* CodeableConcept The kind of relationship --></relationship>
  <name><!-- 0..1 HumanName A name associated with the contact person --></name>
  <telecom><!-- 0..* ContactPoint A contact detail for the person --></telecom>
  <address><!-- 0..1 Address Address for the contact person --></address>
  <gender value="[code]"/><!-- 0..1 male | female | other | unknown -->
  <organization><!-- ?? 0..1 Reference(Organization) Organization that is associated with the contact --></organization>
  <period><!-- 0..1 Period The period during which this contact person or organization is valid to be contacted relating to this patient --></period>
 </contact>
 <communication>  <!-- 0..* A language which may be used to communicate with the patient about his or her health -->
  <language><!-- 1..1 CodeableConcept The language which can be used to communicate with the patient about his or her health --></language>
  <preferred value="[boolean]"/><!-- 0..1 Language preference indicator -->
 </communication>
 <generalPractitioner><!-- 0..* Reference(Organization|Practitioner|
   PractitionerRole) Patient's nominated primary care provider --></generalPractitioner>
 <managingOrganization><!-- 0..1 Reference(Organization) Organization that is the custodian of the patient record --></managingOrganization>
 <link>  <!-- 0..* Link to another patient resource that concerns the same actual person -->
  <other><!-- 1..1 Reference(Patient|RelatedPerson) The other patient or related person resource that the link refers to --></other>
  <type value="[code]"/><!-- 1..1 replaced-by | replaces | refer | seealso -->
 </link>
</Patient>
這個Template還有很多隱含Element沒有列出來喔(都有寫在XML<!--註解裡-->)
實際交換的內容格式如下:
<?xml version="1.0" encoding="UTF-8"?>

<Patient xmlns="http://hl7.org/fhir">
  <id value="example"/> 
  <text> 
    <status value="generated"/> 
    <div xmlns="http://www.w3.org/1999/xhtml">
      <table> 
        <tbody> 
          <tr> 
            <td> Name</td> 
            <td> Peter James 
              <b> Chalmers</b>  (&quot;Jim&quot;)
            </td> 
          </tr> 
          <tr> 
            <td> Address</td> 
            <td> 534 Erewhon, Pleasantville, Vic, 3999</td> 
          </tr> 
          <tr> 
            <td> Contacts</td> 
            <td> Home: unknown. Work: (03) 5555 6473</td> 
          </tr> 
          <tr> 
            <td> Id</td> 
            <td> MRN: 12345 (Acme Healthcare)</td> 
          </tr> 
        </tbody> 
      </table> 
    </div> 
  </text> 
  <!--    MRN assigned by ACME healthcare on 6-May 2001    -->
  <identifier> 
    <use value="usual"/> 
    <type> 
      <coding> 
        <system value="http://terminology.hl7.org/CodeSystem/v2-0203"/> 
        <code value="MR"/> 
      </coding> 
    </type> 
    <system value="urn:oid:1.2.36.146.595.217.0.1"/> 
    <value value="12345"/> 
    <period> 
      <start value="2001-05-06"/> 
    </period> 
    <assigner> 
      <display value="Acme Healthcare"/> 
    </assigner> 
  </identifier> 
  <active value="true"/> 
  <!--    Peter James Chalmers, but called "Jim"    -->
  <name> 
    <use value="official"/> 
    <family value="Chalmers"/> 
    <given value="Peter"/> 
    <given value="James"/> 
  </name> 
  <name> 
    <use value="usual"/> 
    <given value="Jim"/> 
  </name> 
  <name> 
    <!--   Maiden names apply for anyone whose name changes as a result of marriage - irrespective
     of gender   -->
    <use value="maiden"/> 
    <family value="Windsor"/> 
    <given value="Peter"/> 
    <given value="James"/> 
    <period> 
      <end value="2002"/> 
    </period> 
  </name> 
  <telecom> 
    <use value="home"/> 
    <!--    home communication details aren't known    -->
  </telecom> 
  <telecom> 
    <system value="phone"/> 
    <value value="(03) 5555 6473"/> 
    <use value="work"/> 
    <rank value="1"/> 
  </telecom> 
  <telecom> 
    <system value="phone"/> 
    <value value="(03) 3410 5613"/> 
    <use value="mobile"/> 
    <rank value="2"/> 
  </telecom> 
  <telecom> 
    <system value="phone"/> 
    <value value="(03) 5555 8834"/> 
    <use value="old"/> 
    <period> 
      <end value="2014"/> 
    </period> 
  </telecom> 
  <!--    use FHIR code system for male / female    -->
  <gender value="male"/> 
  <birthDate value="1974-12-25">
    <extension url="http://hl7.org/fhir/StructureDefinition/patient-birthTime">
      <valueDateTime value="1974-12-25T14:35:45-05:00"/> 
    </extension> 
  </birthDate> 
  <deceasedBoolean value="false"/> 
  <address> 
    <use value="home"/> 
    <type value="both"/> 
    <text value="534 Erewhon St PeasantVille, Rainbow, Vic  3999"/> 
    <line value="534 Erewhon St"/> 
    <city value="PleasantVille"/> 
    <district value="Rainbow"/> 
    <state value="Vic"/> 
    <postalCode value="3999"/> 
    <period> 
      <start value="1974-12-25"/> 
    </period> 
  </address> 
  <contact> 
    <relationship> 
      <coding> 
        <system value="http://terminology.hl7.org/CodeSystem/v2-0131"/> 
        <code value="N"/> 
      </coding> 
    </relationship> 
    <name> 
      <family value="du Marché">
        <!--    the "du" part is a family name prefix (VV in iso 21090)    -->
        <extension url="http://hl7.org/fhir/StructureDefinition/humanname-own-prefix">
          <valueString value="VV"/> 
        </extension> 
      </family> 
      <given value="Bénédicte"/> 
    </name> 
    <telecom> 
      <system value="phone"/> 
      <value value="+33 (237) 998327"/> 
    </telecom> 
    <address> 
      <use value="home"/> 
      <type value="both"/> 
      <line value="534 Erewhon St"/> 
      <city value="PleasantVille"/> 
      <district value="Rainbow"/> 
      <state value="Vic"/> 
      <postalCode value="3999"/> 
      <period> 
        <start value="1974-12-25"/> 
      </period> 
    </address> 
    <gender value="female"/> 
    <period> 
      <!--    The contact relationship started in 2012    -->
      <start value="2012"/> 
    </period> 
  </contact> 
  <managingOrganization> 
    <reference value="Organization/1"/> 
  </managingOrganization> 
</Patient> 

花點精神對一對,就可以輕鬆看出端倪。
這個比HL7 v3的對應更直覺了。

沒有留言:

張貼留言