電子カルテ情報共有 導入記

 

FHIRの疑問

(2) JSON オブジェクトと配列


JSON 配列はArray というそうですが, [ ]であらわします。以下の様な JSONでは 配列の意味はなんとなく理解できます。

{

"name":"John",

"age":30,

"cars":["Ford", "BMW", "Fiat"]

}



しかし, 例えば以下のサイトにも載っていますが,( 一部 空白 削除)

https://qiita.com/kamome_susume/items/4b2ee1fb141e87ecc2d6

{

  "users": [

    {

      "id": "1234",

      "name": "taro",

      "frends": [ {

          "id": "2222",

          "name": "ziro"

        } ]

    },

    {

      "id": "4444",

      "name": "hana",

      "frends": [ {

          "id": "6666",

          "name": "ken"

        } ]

    }

  ]

}



の場合, 赤字の [ ]は削除しても JSON 文法としては エラーになりません.

そもそも 配列ですから, 複数, 例えば

[ {  }, { } ] のように記載するならわかりますが,

[ { } ] というのは 無意味な 配列表記に 思えるのですが,意味があるのでしょうか?

データの統一性を持たせる, という意味があるのかなと想像します。


FHIR では, 上記のような 無意味と思われる?  [ {  } ] たくさん出てきます.

診療情報提供書サンプル JSONでは( Bundle-Bundle-CLINS-Referral-NoEntry-Example-01.json )

(  45 - 51 行)

      "category" : [{

        "coding" : [{

          "system" : "http://jpfhir.jp/fhir/Common/CodeSystem/doc-subtypecodes",

          "code" : "OUTPATIENT",

          "display" : "外来文書"

        }]

      }],



その 無意味と思われる [  ] (赤字)を削除するとJSONでは エラーにはなりませんが,

日本医療情報学会-Validatorでは 以下のような エラー メッセージが返されます.

*FAILURE*: 1 errors, 0 warnings, 0 notes

Error @ Bundle.entry[0].resource.type.coding (line 39, col10): プロパティcodingJSON配列でなければならず、an ObjectではありませんBundle.entry[0].resource.type)



もっと単純な例としてAllergyIntolerance のサンプルJSONでは

( https://jpfhir.jp/fhir/clins/igv1/AllergyIntolerance-Example-JP-Allergy-eCS-01.json.html )

(24 -26 行)

"type" : "allergy",

  "category" : [“food”],

  "criticality" : "unable-to-assess",



上記の[“food”] [ ] をとると

JSONはエラーにはなりませんが, これをValidatorでcheckすると

*FAILURE*: 1 errors, 0 warnings, 0 notes

  Error @ AllergyIntolerance.category (line 25, col22): プロパティcategoryJSON配列でなければならずa Primitive propertyではありません(AllergyIntoleranceで)



となります。  つまりFHIRでは『 category = 配列』というルールがあるわけです。


逆に  "type" : "allergy", を   "type" : [“allergy”], とすると

"type" : ["allergy"],

  "category" : [“food”],

  "criticality" : "unable-to-assess",



JSONはエラーにはなりませんが, これをValidatorでcheckすると

*FAILURE*: 1 errors, 0 warnings, 0 notes

  Error @ AllergyIntolerance.type (line 24, col23): このプロパティは単純な値でなければならずan Arrayではありません(typeAllergyIntolerance.typeで)



つまり 各 項目(property) でObjectにすべきところ, array にすべきところが決まっているように見えます。


先の “AllergyIntolerance-Example-JP-Allergy-eCS-01.json” で arrayに してあるところを調べると

"profile"

"identifier"

"category"

"note"



Bundle-Bundle-CLINS-Referral-NoEntry-Example-01.json  では

"entry"

"extension"

"author"

"event"

"section"  

"name"

"address"

"contact"

"type"

"telecom"

“coding”

“code”



以上の項目は 配列にする, と理解すればいいのですが,


code”に関しては

(1) “AllergyIntolerance-Example-JP-Allergy-eCS-01.json”  (19 - 22 行) では Object ですし

   "coding" : [{

      "system" : "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical",

     "code" : "active",

      "display" : "Active"



(2) Bundle-Bundle-CLINS-Referral-NoEntry-Example-01.json   ( 74 - 77 行) では Arrayです

      "event" : [{

        "code" : [{

          "text" : "診療情報提供書発行"

        }],


同じように 見える “code”でも 違います


前の実験のように

(1) allergyの "code" : "active", を "code" : ["active"], のように arrayにすると

*FAILURE*: 3 errors, 0 warnings, 0 notes

  Error @ AllergyIntolerance.clinicalStatus (line 17, col4): 提供されたcodingのいずれもがValueSet 'AllergyIntolerance Clinical Status Codes' (http://hl7.org/fhir/ValueSet/allergyintolerance-clinical|4.0.1)に含まれておらず、このValueSetからのcodingが必要です(codes = http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical#null

  Error @ AllergyIntolerance.clinicalStatus.coding[0].code (line 20, col26): このプロパティは単純な値でなければならず、an Arrayではありません(codeはAllergyIntolerance.clinicalStatus.coding[0].codeで)

  Error @ AllergyIntolerance.clinicalStatus.coding[0] (line 18, col6): AllergyIntolerance.clinicalStatus.coding.code: 最小必要値 = 1、見つかった値 = 0 (from http://jpfhir.jp/fhir/eCS/StructureDefinition/JP_AllergyIntolerance_eCS|1.10.0


と 3個のエラーが 返されます。この “code”は Array ではない のです。


(2)の [ ] を削除すると やはり

*FAILURE*: 1 errors, 0 warnings, 0 notes

  Error @ Bundle.entry[0].resource.event[0].code (line 75, col10): プロパティcodeはJSON配列でなければならず、an Objectではありません(Bundle.entry[0].resource.event[0]で)


この “code”は Array なのです。


ちょっと 暗礁に 乗り上げてしまいました。

単純に項目名( property )から object, array は 決められないことになります。

Validator は 単純に 項目名から object, arrayの基準を判定するのではなく, その前後のセットから判断していると思われます。


 

No. 09

(工事中)

2025.4.16 更新