-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a secondary filter to `rdf_compare`, a filter to skip decimal precision differences to `base_test_case.py` and invokes the skip in test_all_fhir_elements. The basic problem is now focused exclusively in test_issue4.
- Loading branch information
hsolbrig
committed
Sep 16, 2017
1 parent
26d6b8a
commit 6c2a396
Showing
5 changed files
with
274 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# Copyright (c) 2017, Mayo Clinic | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, | ||
# are permitted provided that the following conditions are met: | ||
# | ||
# Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# | ||
# Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# Neither the name of the Mayo Clinic nor the names of its contributors | ||
# may be used to endorse or promote products derived from this software | ||
# without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
# OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import unittest | ||
|
||
import os | ||
from jsonasobj import loads | ||
from rdflib import Graph | ||
|
||
from fhirtordf.rdfsupport.rdfcompare import rdf_compare | ||
from tests.utils.base_test_case import FHIRGraph | ||
|
||
data = """{ | ||
"resourceType": "Bundle", | ||
"id": "b248b1b2-1686-4b94-9936-37d7a5f94b51", | ||
"meta": { | ||
"lastUpdated": "2012-05-29T23:45:32Z" | ||
}, | ||
"type": "collection", | ||
"entry": [ | ||
{ | ||
"fullUrl": "http://hl7.org/fhir/Patient/1", | ||
"resource": { | ||
"resourceType": "Patient", | ||
"id": "1", | ||
"meta": { | ||
"lastUpdated": "2012-05-29T23:45:32Z" | ||
}, | ||
"text": { | ||
"status": "generated", | ||
"div": "" | ||
}, | ||
"identifier": [ | ||
{ | ||
"type": { | ||
"coding": [ | ||
{ | ||
"system": "http://hl7.org/fhir/v2/0203", | ||
"code": "SS" | ||
} | ||
] | ||
}, | ||
"system": "http://hl7.org/fhir/sid/us-ssn", | ||
"value": "444222222" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}""" | ||
|
||
expected = """@prefix fhir: <http://hl7.org/fhir/> . | ||
@prefix owl: <http://www.w3.org/2002/07/owl#> . | ||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
@prefix v2-0203: <http://hl7.org/fhir/v2/0203> . | ||
@prefix w5: <http://hl7.org/fhir/w5#> . | ||
@prefix xml: <http://www.w3.org/XML/1998/namespace> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
<http://hl7.org/fhir/Bundle/b248b1b2-1686-4b94-9936-37d7a5f94b51> a fhir:Bundle ; | ||
fhir:nodeRole fhir:treeRoot ; | ||
fhir:Bundle.entry [ | ||
fhir:Bundle.entry.fullUrl [ | ||
fhir:value "http://hl7.org/fhir/Patient/1" | ||
] ; | ||
fhir:Bundle.entry.resource <http://hl7.org/fhir/Patient/1> ; | ||
fhir:index "0"^^xsd:integer | ||
] ; | ||
fhir:Bundle.type [ | ||
fhir:value "collection" | ||
] ; | ||
fhir:Resource.id [ | ||
fhir:value "b248b1b2-1686-4b94-9936-37d7a5f94b51" | ||
] ; | ||
fhir:Resource.meta [ | ||
fhir:Meta.lastUpdated [ | ||
fhir:value "2012-05-29T23:45:32+00:00"^^xsd:dateTime | ||
] | ||
] . | ||
<http://hl7.org/fhir/Bundle/b248b1b2-1686-4b94-9936-37d7a5f94b51.ttl> a owl:Ontology ; | ||
owl:imports fhir:fhir.ttl . | ||
<http://hl7.org/fhir/Patient/1> a fhir:Patient ; | ||
fhir:DomainResource.text [ | ||
fhir:Narrative.div "" ; | ||
fhir:Narrative.status [ | ||
fhir:value "generated" | ||
] | ||
] ; | ||
fhir:Patient.identifier [ | ||
fhir:index "0"^^xsd:integer ; | ||
fhir:Identifier.system [ | ||
fhir:value "http://hl7.org/fhir/sid/us-ssn" | ||
] ; | ||
fhir:Identifier.type [ | ||
fhir:CodeableConcept.coding [ | ||
a <http://hl7.org/fhir/v2/0203/SS> ; | ||
fhir:index "0"^^xsd:integer ; | ||
fhir:Coding.code [ | ||
fhir:value "SS" | ||
] ; | ||
fhir:Coding.system [ | ||
fhir:value "http://hl7.org/fhir/v2/0203" | ||
] | ||
] | ||
] ; | ||
fhir:Identifier.value [ | ||
fhir:value "444222222" | ||
] | ||
] ; | ||
fhir:Resource.id [ | ||
fhir:value "1" | ||
] ; | ||
fhir:Resource.meta [ | ||
fhir:Meta.lastUpdated [ | ||
fhir:value "2012-05-29T23:45:32+00:00"^^xsd:dateTime | ||
] | ||
] . | ||
""" | ||
|
||
|
||
class Issue2TestCase(unittest.TestCase): | ||
def test_reference(self): | ||
test_json = loads(data) | ||
from fhirtordf.loaders.fhirresourceloader import FHIRResource | ||
test_rdf = FHIRResource(FHIRGraph(), None, "http://hl7.org/fhir", test_json) | ||
g = test_rdf.graph | ||
expected_graph = Graph() | ||
diffs = rdf_compare(expected_graph, test_rdf.graph, ignore_owl_version=True, ignore_type_arcs=True) | ||
self.assertEqual("", diffs) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright (c) 2017, Mayo Clinic | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, | ||
# are permitted provided that the following conditions are met: | ||
# | ||
# Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# | ||
# Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# Neither the name of the Mayo Clinic nor the names of its contributors | ||
# may be used to endorse or promote products derived from this software | ||
# without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
# OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import unittest | ||
|
||
from jsonasobj import loads | ||
from rdflib import URIRef, Literal, XSD | ||
|
||
from fhirtordf.rdfsupport.namespaces import FHIR | ||
from tests.utils.base_test_case import FHIRGraph | ||
|
||
json_data = """{ | ||
"resourceType": "VisionPrescription", | ||
"id": "33123", | ||
"text": { | ||
"status": "generated", | ||
"div": "(cut)" | ||
}, | ||
"dispense": [ | ||
{ | ||
"product": { | ||
"coding": [ | ||
{ | ||
"system": "http://hl7.org/fhir/ex-visionprescriptionproduct", | ||
"code": "lens" | ||
} | ||
] | ||
}, | ||
"eye": "right", | ||
"sphere": -2.00, | ||
"prism": 0.5, | ||
"base": "down", | ||
"add": 2.00 | ||
} | ||
] | ||
} | ||
""" | ||
|
||
|
||
class Issue4TestCase(unittest.TestCase): | ||
def test_decimal(self): | ||
test_json = loads(json_data) | ||
from fhirtordf.loaders.fhirresourceloader import FHIRResource | ||
test_rdf = FHIRResource(FHIRGraph(), None, "http://hl7.org/fhir", test_json) | ||
g = test_rdf.graph | ||
# rdflib supports decimal precision if you create the data as a string. | ||
self.assertNotEqual(Literal("2.00", datatype=XSD.decimal), Literal("2.0", datatype=XSD.decimal)) | ||
self.assertEqual(Literal(2.00), Literal(2.0)) | ||
|
||
# FHIR requires that *all* decimals use the first form. While the diopter example above | ||
# would work, issues arise in situations where numbers really ARE decimal... | ||
self.assertEqual(Literal("2.00", datatype=XSD.decimal), | ||
g.value( | ||
g.value( | ||
g.value(URIRef("http://hl7.org/fhir/VisionPrescription/33123"), | ||
FHIR.VisionPrescription.dispense), | ||
FHIR.VisionPrescription.dispense.add), FHIR.value)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters