Fhir in Json LD
Fhir in Json LD
7
Round-tripped JSON-LD - dob
1. {
2. "@context": {
3. "fhir": "http://example/fhir#",
4. "rdf": "http://www.w3.org/1999/02/22rdfsyntaxns#",
@context embedded
5. "rdfs": "http://www.w3.org/2000/01/rdfschema#",
6. "xsd": "http://www.w3.org/2001/XMLSchema#"
7. },
8. "@graph": [
9. {
@graph wrapper
10. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb3",
11. "http://example/fhir/vocab#url": "http://example.org/fhir/extensions#text",
12. "http://example/fhir/vocab#valueString": "Easter 1970"
13. },
14. {
15. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb2",
16. "http://example/fhir/vocab#extension": { Prefixes are lost
17. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb3"
18. },
19. "http://example/fhir/vocab#id": "314159"
20. },
21. {
22. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb1",
23. "fhir:_dob": {
RDF blank node
24. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb2" labels change
25. },
26. "fhir:dob": {
27. "@type": "xsd:date",
28. "@value": "19721130"
29. } CONCLUSION: Generic RDF-->JSON-LD
30. } re-serializers will not suffice
31. ]
32. } 8
Good: Most issues seem manageable
• Blank nodes
• Extensions can be related:
fhir:dob fhir:extension fhir:_dob
9
Good: modifier extensions okay
10
Good: FHIR has a closed content model
11
Bad: Element type depends on context
"resourceType": "Observation",
"id": "example",
"code": { Object
"coding": [
{
"system": "http://loinc.org",
"code": "31419", String
"display": "Weight Measured"
}
]
},
12
RDF lists
13
Potential @context for "code"
"@context":
{
"@base": "http://example/base/",
"base": "http://example/base/",
"@vocab": "http://example/fhir#",
"fhir": "http://example/fhir#",
"resourceType": { "@type": "@vocab" },
"code": {
"@id": "fhir:code",
"@container": "@list"
},
"Observation": {"@id": "fhir:Observation"}
},
14
JSON-LD versus Turtle
{ "@context": ... [] fhir:resourceType
"resourceType": "Observation", fhir:Observation ;
"code": { fhir:code ( [
"coding": [ fhir:coding
{ [
"system": "http://loinc.org", fhir:system "http://loinc.org" ;
"code": "31419"
fhir:code ( "31419" )
}
]
]
] ) ;
},
fhir:foo [
"foo": {
fhir:code ( "aaa" "bbb" )
"code": [ "aaa", "bbb" ]
] ;
},
fhir:bar [
"bar": {
"code": [ { "ccc": "ddd" } ]
fhir:code ([fhir:ccc "ddd"])
} ] .
}
15
Potential solutions
16
Options
• JSON-LD:
– Avoids a third FHIR serialization
– W3C standard
– Can standardize for FHIR very quickly
• Custom "ideal" RDF:
– Can be better for inference
– Will take much longer to standardize
• Combined approach: Adopt direct RDF now (either JSON-LD or
custom RDF) + "ideal" RDF later
– Open question: How much gap is there between direct RDF and
"ideal" RDF? Could direct RDF be good enough?
17
EVEN OLDER SLIDES -- OBSOLETE
19
Observations
21
What is JSON-LD?
• Both:
– A form of JSON
– An RDF serialization
22
Why JSON-LD for FHIR?
23
JSON-LD Example:
lennon.jsonld
1.{
2. "@context": "http://dbooth.org/2015/fhir/json-
ld/person.jsonld",
3. "@id": "http://dbpedia.org/resource/John_Lennon",
4. "name": "John Lennon",
5. "born": "1940-10-09",
6. "spouse":
"http://dbpedia.org/resource/Cynthia_Lennon"
7.}
24
JSON-LD context:
http://dbooth.org/.../person.jsonld
1.{
2. "@context":
3. {
4. "Person": "http://xmlns.com/foaf/0.1/Person",
5. "xsd": "http://www.w3.org/2001/XMLSchema#",
6. "name": "http://xmlns.com/foaf/0.1/name",
7. "born":
8. {
9. "@id": "http://schema.org/birthDate",
10. "@type": "xsd:date"
11. },
12. "spouse":
13. {
14. "@id": "http://schema.org/spouse",
15. "@type": "@id"
16. }
17. }
25
JSON-LD Example
JSON-LD Context
lennon.jsonld http://dbooth.org/.../person.jsonld
{ {
"@context": "http://dbooth.org/2015/fhir/json-ld/person.jsonld", "@context":
"@id": "http://dbpedia.org/resource/John_Lennon", {
"name": "John Lennon", "Person": "http://xmlns.com/foaf/0.1/Person",
"born": "1940-10-09", "xsd": "http://www.w3.org/2001/XMLSchema#",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon" "name": "http://xmlns.com/foaf/0.1/name",
} "born":
{
"@id": "http://schema.org/birthDate",
"@type": "xsd:date"
},
"spouse":
{
"@id": "http://schema.org/spouse",
"@type": "@id"
}
}
26
For FHIR in JSON-LD
27
FHIR XML – dob
(primitive element with extension)
<dob id="314159" value="19700330" >
<extension url="http://example.org/fhir/extensions#text">
<valueString value="Easter 1970"/>
</extension>
</dob>
See http://www.hl7.org/implement/standards/fhir/json.html
28
FHIR JSON – dob
In FHIR JSON it becomes two properties:
{
"dob": "19721130",
"_dob": {
"id": "314159",
"extension": [{
"url" : "http://example.org/fhir/extensions#text",
"valueString" : "Easter 1970"
}]
}
29
FHIR JSON-LD – dob
{
"@context": "http://dbooth.org/2015/fhir/jsonld/dobcontext.jsonld",
"dob": "19721130",
"_dob": {
"id": "314159",
"extension": [{
"url" : "http://example.org/fhir/extensions#text ",
"valueString" : "Easter 1970"
}]
}
}
30
FHIR JSON-LD – dob @context
1.{
2. "@context":
3. {
4. "@vocab": "http://example/fhir/vocab#",
5. "fhir": "http://example/fhir#",
6. "xsd": "http://www.w3.org/2001/XMLSchema#",
7. "dob":
8. {
9. "@id": "fhir:dob",
10.
"@type": "xsd:date"
11.
},
12.
"_dob":
13.
{
14.
"@id": "fhir:_dob",
15.
"@type": "@id"
16.
}
17.
}
18.
} 31
Primitive extension names
XML:
<dob ...>
JSON:
"dob": ...
"_dob": ... Implicit relationship --
needs to be explicit
RDF:
<http://...#dob> ...
<http://...#_dob> ...
32
RDF / Turtle - dob
Implicit relationship between fhir:dob and fhir:_dob needs to be explicit:
1. @prefix fhir: <http://example/fhir#> .
2. @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
3.
4. _:b0 fhir:_dob _:b1 ;
5. fhir:dob "19721130"^^xsd:date .
6.
7. # fhir:_dob fhir:extends fhir:dob . # From ontology?
8.
9. _:b1 <http://example/fhir/vocab#extension> _:b2 ;
10. <http://example/fhir/vocab#id> "314159" .
11.
12. _:b2 <http://example/fhir/vocab#url>
13. "http://example.org/fhir/extensions#text" ;
14. <http://example/fhir/vocab#valueString>
15. "Easter 1970" .
33
Issue 1: Extensions are implicitly related
fhir:dob vs. fhir:_dob
• Solution A: Ontology could relate them, but this would mean that
round-tripping would depend on the ontology. Maybe okay for
extensions to standard elements, but not for extensions to extensions.
• Solution B: Add explicit statement to JSON:
"dob":
{
"@id": "fhir:dob",
"@type": "xsd:date",
"extension": "fhir:_dob"
}
34
Round-tripped JSON-LD - dob
1. {
2. "@context": {
3. "fhir": "http://example/fhir#",
4. "rdf": "http://www.w3.org/1999/02/22rdfsyntaxns#",
@context embedded
5. "rdfs": "http://www.w3.org/2000/01/rdfschema#",
6. "xsd": "http://www.w3.org/2001/XMLSchema#"
7. },
8. "@graph": [
9. {
@graph wrapper
10. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb3",
11. "http://example/fhir/vocab#url": "http://example.org/fhir/extensions#text",
12. "http://example/fhir/vocab#valueString": "Easter 1970"
13. },
14. {
15. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb2",
16. "http://example/fhir/vocab#extension": { Prefixes are lost
17. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb3"
18. },
19. "http://example/fhir/vocab#id": "314159"
20. },
21. {
22. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb1",
23. "fhir:_dob": {
RDF blank node
24. "@id": "_:fc7725329340449efa72b6f7f5d7182eeb2" labels change
25. },
26. "fhir:dob": {
27. "@type": "xsd:date",
28. "@value": "19721130"
29. } CONCLUSION: Generic RDF-->JSON-LD
30. } re-serializers will not suffice
31. ]
32. } 35
Issue 2: Context embedded
"@context": { ... }
36
Issue 3: @graph wrapper
"@graph": { ... }
37
Issue 4: Prefixes are lost
"url" (JSON) >
<http://example/fhir/vocab#url> (RDF) >
"http://example/fhir/vocab#url" (JSON)
38
Issue 5: Blank node labels change
"@id": "_:fc7725329340449efa72b6f7f5d7182eeb3"
• Why:
– JSON objects do not always have explicit @ids
39
JSON-LD round tripping conclusions
40
JSON-LD alignment
41
TO DO: Investigate modifier extensions
42
TO DO: Investigate identifiers further
<dob id="314159" value="19700330" >
43
Summary of required FHIR JSON
changes
1. Add @context to every FHIR JSON instance document,
or link externally, such as by an HTTP Link header.
2. Change "id" to "@id" in JSON. (TODO: Figure out how
to handle the scoping properly.)
3. Always permit an @id in every element. (TODO: File
FHIR change request regarding profiles)
4. Change extension "url" to "@type". (TODO: Verify that
"url" is not used elsewhere, or this context can be
distinguished.)
44
Conclusions
45
QUESTIONS?
46
Other Notes (mostly to self)
47
JSON-LD uses CURIEs
48
Resource identity
http://www.hl7.org/implement/standards/fhir/managing.html
• Each resource has a URL (outside the resource)
• Many resources also have a logical identifier, which is different from
the literal identity of the resource. Multiple resource instances can
describe the same concept across multiple systems.
• "The full identity of a resource is an absolute URL constructed from
the server address at which it is found, the resource type, and the
Logical Id, such as http://test.fhir.org/rest/Patient/123 (where 123 is
the Logical Id)." --
http://www.hl7.org/implement/standards/fhir/resources.html
– SERVER_URI/TYPE/LOGICAL_ID
49
FHIR Resources
• http://www.hl7.org/implement/standards/fhir
/overview.html
• Resources all have:
– Common way to define and represent them,
building from data types
– A common set of metadata
– A human readable part
50
Special Resources
51
Resource definition
• http://www.hl7.org/implement/standards/fhir/resources.html
• A resource is an entity that:
• has a known identity (a url) by which it can be addressed
• identifies itself as one of the types of resource defined in this
specification
• contains a set of structured data items as described by the
definition of the resource type
• contains a human-readable XHTML representation of the
content of the resource
• has an identified version that changes if the contents of the
resource change
•
52
Contents of a Resource
• http://www.hl7.org/implement/standards/fhir/resources.html#content
• Resources have:
• A base set of defined data elements specific to the type
• Extensions - additional data elements added by implementations
• A human-readable narrative description of the contents of the resource
• Contained resources - additional resources that are part of the identification and
transaction space of this resource
• Metadata - important information about the resource that is not part of the content
model of the resource:
– Logical Id
– Versioin Id
– Last Modified Date
• Tags - labels affixed to the resources that may be used to define additional
operational behavior such as security, workflow, etc.
•
53
Issue: Minting URIs from identifiers
54
Message Identifiers
• http://www.hl7.org/implement/standards/fhir
/messaging.html
• Envelope ID (feed.id), changed each time a
message is sent
• Message ID (unique within the message
stream)
• Q: How is the message stream identified?
•
55
Issue: Language element
• http://www.hl7.org/implement/standards/fhir/resourc
es.html
• "specifies the base language of the resource"
• Should this be propagated to RDF lang tags?
• Prob not. It looks like it will be used for narratives,
which are specified in xhtml, which has lang
attributes:
– http://www.w3.org/International/questions/qa-html-
language-declarations
56
Issue: Lists
• Q: Can new extension elements contain lists? If so, how
will the JSON parser know that?
• Q: Normally a JSON-LD list produces an unordered set of
triples, which seems like a loss of information. If there is
only one member of the set, how would a JSON-LD
serializer (from RDF) know that it should be serialized as
a list rather than as a single property?
• A: Not a problem. FHIR is a closed content model, so no
new elements are possible. Therefore, all lists can be
declared in the @context.
57