Example #1
0
    def test_basics(self):
        g = fhir_json_to_rdf("http://hl7.org/fhir/Observation/vitals-panel")
        self.assertEqual(['http://hl7.org/fhir/Observation/blood-pressure',
                          'http://hl7.org/fhir/Observation/body-temperature',
                          'http://hl7.org/fhir/Observation/heart-rate',
                          'http://hl7.org/fhir/Observation/respiratory-rate',
                          'http://hl7.org/fhir/Observation/vitals-panel',
                          'http://hl7.org/fhir/Observation/vitals-panel.ttl',
                          'http://hl7.org/fhir/Patient/example'],
                         sorted(str(s) for s in set(g.subjects()) if isinstance(s, URIRef)))

        mv = FHIRMetaVoc()
        self.assertTrue(mv.from_cache)
        g = fhir_json_to_rdf("http://hl7.org/fhir/DiagnosticReport/f201", target_graph=g, metavoc=mv)
        self.assertEqual({URIRef('http://hl7.org/fhir/Observation/blood-pressure'),
                          URIRef('http://hl7.org/fhir/Observation/heart-rate'),
                          URIRef('http://hl7.org/fhir/DiagnosticReport/f201.ttl'),
                          URIRef('http://hl7.org/fhir/Patient/example'),
                          URIRef('http://hl7.org/fhir/Observation/body-temperature'),
                          URIRef('http://hl7.org/fhir/Observation/respiratory-rate'),
                          URIRef('http://hl7.org/fhir/Observation/vitals-panel.ttl'),
                          URIRef('http://hl7.org/fhir/Patient/f201'),
                          URIRef('http://hl7.org/fhir/DiagnosticReport/f201'),
                          URIRef('http://hl7.org/fhir/Organization/f203'),
                          URIRef('http://hl7.org/fhir/Observation/vitals-panel')},
                         set(s for s in g.subjects() if isinstance(s, URIRef)))
Example #2
0
def proc_file(infile: str, outfile: str, opts: Namespace) -> bool:
    """
    Process infile.
    :param infile: input file to be processed
    :param outfile: target output file.
    :param opts:
    :return:
    """
    g = fhir_json_to_rdf(infile,
                         opts.uribase,
                         opts.graph,
                         add_ontology_header=not opts.noontology,
                         do_continuations=not opts.nocontinuation,
                         replace_narrative_text=bool(opts.nonarrative),
                         metavoc=opts.fhir_metavoc)

    os.makedirs(os.path.dirname(outfile), exist_ok=True)

    # If we aren't carrying graph in opts, we're doing a file by file transformation
    if g:
        if not opts.graph:
            serialize_graph(g, outfile, opts)
        return True
    else:
        print("{} : Not a FHIR collection or resource".format(infile))
        return False
Example #3
0
 def load_file(dirname: str, fname: str) -> None:
     filepath = fname if '://' in fname else os.path.join(dirname, fname)
     print("--> loading {}".format(filepath))
     if '://' in fname:
         if opts.filetype == 'rdf':
             rdf_str = read_rdf_uri(fname)
             if not rdf_str:
                 print("   Read Failed")
             g.parse(data=rdf_str, format="turtle")
         else:
             fhir_json_to_rdf(fname, opts.uribase, g, metavoc=fmv)
     else:
         if filepath.endswith('.json'):
             fhir_json_to_rdf(filepath, opts.uribase, g, metavoc=fmv)
         else:
             g.load(filepath, format="turtle")
Example #4
0
    def test_basics(self):
        # TODO: The test below fails.  See: https://github.com/fhircat/FHIRCat/issues/36
        print(
            "http://hl7.org/fhir/Observation/vitals-panel test skipped -- See: FHIRCat issue #36 for details"
        )
        # g = fhir_json_to_rdf("http://hl7.org/fhir/Observation/vitals-panel")
        g = fhir_json_to_rdf(
            "http://hl7.org/fhir/observation-example-vitals-panel.json")
        self.assertEqual([
            'http://hl7.org/fhir/Observation/blood-pressure',
            'http://hl7.org/fhir/Observation/body-temperature',
            'http://hl7.org/fhir/Observation/heart-rate',
            'http://hl7.org/fhir/Observation/respiratory-rate',
            'http://hl7.org/fhir/Observation/vitals-panel',
            'http://hl7.org/fhir/Observation/vitals-panel.ttl',
            'http://hl7.org/fhir/Patient/example'
        ], sorted(str(s) for s in set(g.subjects()) if isinstance(s, URIRef)))

        mv = FHIRMetaVoc()
        self.assertTrue(mv.from_cache)

        print(
            "http://hl7.org/fhir/DiagnosticReport/f201 test skipped -- See: FHIRCat issue #36 for details"
        )
        # g = fhir_json_to_rdf("http://hl7.org/fhir/DiagnosticReport/f201")
        g = fhir_json_to_rdf(
            "http://hl7.org/fhir/diagnosticreport-example-f201-brainct.json",
            target_graph=g,
            metavoc=mv)
        self.assertEqual(
            {
                URIRef('http://hl7.org/fhir/Observation/blood-pressure'),
                URIRef('http://hl7.org/fhir/Observation/heart-rate'),
                URIRef('http://hl7.org/fhir/DiagnosticReport/f201.ttl'),
                URIRef('http://hl7.org/fhir/Patient/example'),
                URIRef('http://hl7.org/fhir/Observation/body-temperature'),
                URIRef('http://hl7.org/fhir/Observation/respiratory-rate'),
                URIRef('http://hl7.org/fhir/Observation/vitals-panel.ttl'),
                URIRef('http://hl7.org/fhir/Patient/f201'),
                URIRef('http://hl7.org/fhir/DiagnosticReport/f201'),
                URIRef('http://hl7.org/fhir/Organization/f203'),
                URIRef('http://hl7.org/fhir/Observation/vitals-panel')
            }, set(s for s in g.subjects() if isinstance(s, URIRef)))
Example #5
0
    def test_statement(self):

        test_json = os.path.join(ISSUE_TEST_DATA_DIR, 'issue_15.json')
        mvg = Graph()
        mvg.load(FHIR_R4_TTL, format="turtle")
        g = fhir_json_to_rdf(test_json, metavoc=mvg)
        expected_graph = Graph()
        g.load(os.path.join(ISSUE_TEST_DATA_DIR, 'issue_15.ttl'),
               format="turtle")
        expected, actual = rdf_compare_split(expected_graph,
                                             g,
                                             ignore_owl_version=False,
                                             ignore_type_arcs=False)
        self.assertEqual('', expected)
        self.assertEqual('', actual)