首页 > 解决方案 > 为 FHIR 资源实例定义自定义属性

问题描述

我正在尝试为从业者资源定义自定义属性。但是当我根据我的结构定义验证一个实例时它失败并且目前不知道我做错了什么:

{
    "resourceType": "StructureDefinition",
    "url": "http://example.com/fhir/StructureDefinition/PractitionerProfile",
    "name": "PractitionerProfile",
    "status": "active",
    "kind": "resource",
    "abstract": false,
    "type": "Practitioner",
    "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Practitioner",
    "derivation": "specialization",
    "differential": {
        "element": [
            {
                "id": "Practitioner.telecom",
                "path": "Practitioner.telecom",
                "definition": "A contact detail for the practitioner, e.g. a telephone number or an email address.",
                "min": 1,
                "max": "1"
            },
            {
                "id": "Practitioner.foo",
                "path": "Practitioner.foo",
                "definition": "A contact detail for the practitioner, e.g. a telephone number or an email address.",
                "min": 1,
                "max": "1",
                "type": [{
                  "code": "string"
                }]
            }
        ]
    }
}
<Practitioner xmlns='http://hl7.org/fhir'>
    <meta>
        <profile value='http://example.com/fhir/StructureDefinition/PractitionerProfile' />
    </meta>
    <active value='true' />
    <foo value="bar"/>
    <telecom>
        <system value='phone' />
        <value value='555-101-0987' />
        <use value='home' />
    </telecom>
</Practitioner>
java -jar 'validator_cli.jar' -ig src/test/resources/integration/4.0/validate/ src/test/resources/integration/4.0/validate/valid-resource.xml -version 4.0 -tx n/a
FHIR Validation tool Version 5.4.2 (Git# 552ef55adaf0). Built 2021-05-21T18:15:07.271Z (7 days old)
  Java:   11.0.8 from /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home on x86_64 (64bit). 4096MB available
  Paths:  Current = ~/fhir-rest, Package Cache = ~/.fhir/packages
  Params: -ig src/test/resources/integration/4.0/validate/ src/test/resources/integration/4.0/validate/valid-resource.xml -version 4.0 -tx n/a
Loading
  Load FHIR v4.0 from hl7.fhir.r4.core#4.0.1 - 4575 resources (00:04.0177)
  Load hl7.terminology#2.0.0 - 3749 resources (00:00.0799)
  Terminology server null - Version n/a: No Terminology Server (00:00.0000)
  Load src/test/resources/integration/4.0/validate/* load file: valid-resource.xml - ignored due to error: Unknown Content foo @  START_TAG seen ...<active value=\'true\' />\n    <foo value="bar"/>... @6:23
 - 2 resources (00:00.0056)
  Get set...  go (00:00.0045)
Validating
  Validate src/test/resources/integration/4.0/validate/valid-resource.xmlInternal error in location for message: 'Error @1, 1: Found / expecting a token name', loc = '/f:Practitioner', err = 'Undefined element 'foo''
 00:00.0649
Done. Times: Loading: 00:05.0356, validation: 00:00.0649. Memory = 199Mb

*FAILURE*: 2 errors, 0 warnings, 0 notes
  Error @ Practitioner (line 1, col43) : Practitioner.foo: minimum required = 1, but only found 0 (from http://example.com/fhir/StructureDefinition/PractitionerProfile)
  Error @ /f:Practitioner (line 6, col23) : Undefined element 'foo'

标签: validationhl7-fhirhapi-fhir

解决方案


添加自定义属性是不符合要求的。如果您有自定义要求,则需要使用 Practitioner.extension 并将您的元素定义为 Extension 数据类型的配置文件。查看https://build.fhir.org/extensibility


推荐阅读