Пример #1
0
 def test_no_args(self):
     from fhirtordf.fhirtordf import fhirtordf
     args = ""
     output = self._push_stderr()
     fhirtordf(args.split(), default_exit=False)
     self._pop_stderr()
     self.maxDiff = None
     self.assertEqual(noargs_text, output.getvalue())
Пример #2
0
 def test_version(self):
     from fhirtordf.fhirtordf import fhirtordf
     from fhirtordf import __version__
     output = self._push_stdout()
     fhirtordf(["-v"])
     self._pop_stdout()
     self.assertEqual(
         "FHIR to RDF Conversion Tool -- Version {}".format(__version__),
         output.getvalue().strip())
Пример #3
0
 def test_help(self):
     from fhirtordf.fhirtordf import fhirtordf
     args = "-h"
     output = self._push_stdout()
     fhirtordf(args.split(), default_exit=False)
     self._pop_stdout()
     self.maxDiff = None
     print(output.getvalue())
     self.assertEqual(help_text, output.getvalue())
Пример #4
0
    def test_two_uris(self):
        from fhirtordf.fhirtordf import fhirtordf

        if USE_BUILD_SERVER:
            args = "-i {}/patient-example-f201-roel.json {}/patient-example-f201-roel.json".\
                format(test_fhir_server, test_fhir_server)
        else:
            args = "-i {}Patient/f201 {}/Patient/pat1".format(
                test_fhir_server, test_fhir_server)
        output = self._push_stdout()
        fhirtordf(args.split())
        self._pop_stdout()
        print(output.getvalue())
Пример #5
0
    def test_two_infiles(self):
        from fhirtordf.fhirtordf import fhirtordf

        test_directory = os.path.join(
            os.path.split(os.path.abspath(__file__))[0], '..', 'data')
        tf1 = os.path.join(test_directory, "activitydefinition-example.json")
        tf2 = os.path.join(test_directory,
                           "activitydefinition-predecessor-example.json")
        args = "-i {} {}".format(tf1, tf2)
        output = self._push_stdout()
        fhirtordf(args.split())
        self._pop_stdout()
        print(output.getvalue())
Пример #6
0
    def test_big_fhir_convert(self):
        # This is a test of the complete FHIR directory conversion
        from fhirtordf.fhirtordf import fhirtordf

        input_directory = os.path.abspath(
            '/Users/mrf7578/Development/fhir/build/publish')
        output_directory = os.path.abspath(
            os.path.join(
                os.path.split(os.path.abspath(__file__))[0], 'data',
                'publish'))
        args = '-nc -nn -id {} -od {} -sd /v2/ /v3/ -sf .cs. .vs. .profile. .canonical. .schema. .diff.'.format(
            input_directory, output_directory)

        fhirtordf(args.split(), default_exit=False)
Пример #7
0
    def test_fhir_files(self):
        from fhirtordf.fhirtordf import fhirtordf

        fnames = [
            'activitydefinition-example',
            'activitydefinition-medicationorder-example',
            'capabilitystatement-base', 'careplan-example-f001-heart',
            'claim-example', 'patient-example'
        ]

        for fname in fnames:
            in_url = "{}{}.json".format(test_fhir_server, fname)
            test_url = "{}{}.ttl".format(test_fhir_server, fname)
            # fmv_url = "{}/fhir.ttl".format(target_fhir_build)
            fmv_url = os.path.join(
                os.path.split(os.path.abspath(__file__))[0], '..', 'data',
                'fhir_metadata_vocabulary', 'fhir.ttl')
            test_directory = os.path.join(
                os.path.split(os.path.abspath(__file__))[0], 'data')
            outfname = os.path.join(test_directory, "{}.ttl".format(fname))
            args = "-i {} -o {} -mv {} -s".format(in_url, outfname, fmv_url)
            self.assertTrue(fhirtordf(args.split()))
            out_graph = Graph()
            out_graph.load(outfname, format="turtle")
            test_graph = Graph()
            test_graph.load(test_url, format="turtle")
            comp_result = rdf_compare(test_graph,
                                      out_graph,
                                      ignore_owl_version=True,
                                      ignore_type_arcs=True)
            if len(comp_result):
                print(comp_result)
            self.assertTrue(len(comp_result) == 0)
Пример #8
0
    def test_patient_example(self):
        from fhirtordf.fhirtordf import fhirtordf

        test_directory = os.path.join(
            os.path.split(os.path.abspath(__file__))[0], '..', 'data')
        infname = os.path.join(test_directory, "patient-example.json")
        testfname = os.path.join(test_directory, "patient-example.ttl")
        if save_output:
            outfname = testfname
        else:
            outfname = os.path.join(test_directory, "patient-example-out.ttl")
        args = "-i {} -o {} -s".format(infname, outfname)
        self.assertTrue(fhirtordf(args.split()))
        self.assertFalse(save_output,
                         "Test file: {} generated".format(outfname))
        out_graph = Graph()
        out_graph.load(outfname, format="turtle")
        test_graph = Graph()
        test_graph.load(testfname, format="turtle")
        comp_result = rdf_compare(test_graph,
                                  out_graph,
                                  ignore_owl_version=True,
                                  ignore_type_arcs=True)
        if len(comp_result):
            print(comp_result)
        self.assertTrue(len(comp_result) == 0)
Пример #9
0
    def test_output_directory(self):
        from fhirtordf.fhirtordf import fhirtordf
        output_directory = os.path.abspath(
            os.path.join(
                os.path.split(os.path.abspath(__file__))[0], 'data',
                'patlist'))
        shutil.rmtree(output_directory, ignore_errors=True)

        fhirtordf(
            "-i http://fhirtest.uhn.ca/baseDstu3/Patient"
            "?_format=json&gender=male&birthdate=gt2013-01-01 -od {} -nn -nc".
            format(output_directory).split())
        self.assertTrue(os.path.exists(output_directory))
        self.assertTrue(
            os.path.exists(os.path.join(output_directory, '_url1.ttl')))
        shutil.rmtree(output_directory)
Пример #10
0
    def test_sd_issue(self):
        from fhirtordf.fhirtordf import fhirtordf

        test_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', 'data'))
        of = mktemp()
        fhir_ttl = os.path.join(test_dir, 'fhir_metadata_vocabulary',
                                'fhir.ttl')
        args = f"-id {test_dir} -mv {fhir_ttl} -u http://dss.cora/ -no -o {of}"
        print(args)
        output = StringIO()
        with redirect_stdout(output):
            fhirtordf(args.split())
        print(output.getvalue())
        # passes if we get here
        self.assertTrue(True)
Пример #11
0
 def test_subjects(self):
     from fhirtordf.fhirtordf import fhirtordf
     output = self._push_stdout()
     if USE_BUILD_SERVER:
         args = '-i {}/observation-example-vitals-panel.json'.format(test_fhir_server)
     else:
         args = "-i {}/Observation/vitals-panel".format(test_fhir_server)
     fhirtordf(args.split())
     self._pop_stdout()
     g = Graph()
     g.parse(data=output.getvalue(), format="turtle")
     self.assertEqual({URIRef('http://hl7.org/fhir/Observation/respiratory-rate'),
                       URIRef('http://hl7.org/fhir/Observation/body-temperature'),
                       URIRef('http://hl7.org/fhir/Patient/example'),
                       URIRef('http://hl7.org/fhir/Observation/vitals-panel.ttl'),
                       URIRef('http://hl7.org/fhir/Observation/blood-pressure'),
                       URIRef('http://hl7.org/fhir/Observation/heart-rate'),
                       URIRef('http://hl7.org/fhir/Observation/vitals-panel')},
                      set(s for s in g.subjects() if isinstance(s, URIRef)))
Пример #12
0
    def bester_tester(self, args: str, test_fname: str):
        from fhirtordf.fhirtordf import fhirtordf
        output = self._push_stdout()
        fhirtordf(args.split(), default_exit=False)
        g2 = Graph()
        g2.parse(data=output.getvalue(), format="turtle")
        self._pop_stdout()
        if save_sample_output:
            with open(test_fname, 'w') as f:
                f.write(output.getvalue())
        g1 = Graph()
        g1.parse(test_fname, format="turtle")
        comp_result = rdf_compare(g1, g2)

        if len(comp_result):
            print(comp_result)
        self.assertTrue(len(comp_result) == 0)
        self.assertFalse(save_sample_output,
                         "save_sample_output is True -- test not applied")
Пример #13
0
    def test_continuations(self):
        from fhirtordf.fhirtordf import fhirtordf

        test_directory = os.path.join(
            os.path.split(os.path.abspath(__file__))[0], 'data')
        outfname = os.path.join(test_directory, "patlist1.ttl")
        # The following query returned 310 entries on Sep 10, 2017
        url = "http://fhirtest.uhn.ca/baseDstu3/Patient?_format=json&gender=male&birthdate=gt2013-01-01"
        args = "-i {} -o {} -nc".format(url, outfname)
        self.assertTrue(fhirtordf(args.split()))
        out_graph = Graph()
        out_graph.load(outfname, format="turtle")
        self.assertTrue(
            len([
                s for s in set(out_graph.subjects()) if isinstance(s, URIRef)
            ]) < 50)
        args = "-i {} -o {}".format(url, outfname)
        self.assertTrue(fhirtordf(args.split()))
        out_graph = Graph()
        out_graph.load(outfname, format="turtle")
        self.assertTrue(
            len([
                s for s in set(out_graph.subjects()) if isinstance(s, URIRef)
            ]) > 300)