예제 #1
0
def generate_mappings(fhir_release=None,
                      reference_analyzer=None,
                      token_normalizer=None):
    """ """
    fhir_release = fhir_release or FHIR_VERSION.R4.name
    fhir_spec = FhirSpecFactory.from_release(fhir_release)

    resources_elements = defaultdict()

    for definition_klass in fhir_spec.profiles.values():
        if definition_klass.name in ("Resource", "DomainResource"):
            # exceptional
            resources_elements[
                definition_klass.name] = definition_klass.elements
            continue
        if definition_klass.structure.subclass_of != "DomainResource":
            # we accept domain resource only
            continue

        resources_elements[definition_klass.name] = definition_klass.elements

    elements_paths = build_elements_paths(resources_elements)

    mappings = dict()
    fhir_es_mappings = fhir_types_mapping(fhir_release, reference_analyzer,
                                          token_normalizer)
    for resource, paths_def in elements_paths.items():
        mappings[resource] = create_resource_mapping(paths_def,
                                                     fhir_es_mappings)

    return mappings
예제 #2
0
    def generate_mappings(
        self,
        reference_analyzer: str = None,
        token_normalizer: str = None,
    ):
        """
        You may use this function to build the ES mapping.
        Returns an object like:
        {
            "Patient": {
                "properties": {
                    "identifier": {
                        "properties": {
                            "use": {
                                "type": "keyword",
                                "index": true,
                                "store": false,
                                "fields": {
                                    "raw": {
                                        "type": "keyword"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        """
        fhir_spec = FhirSpecFactory.from_release(self.fhir_release.name)

        resources_elements: Dict[
            str, List[FHIRStructureDefinitionElement]] = defaultdict()

        for definition_klass in fhir_spec.profiles.values():
            if definition_klass.name in ("Resource", "DomainResource"):
                # exceptional
                resources_elements[
                    definition_klass.name] = definition_klass.elements
                continue
            if definition_klass.structure.subclass_of != "DomainResource":
                # we accept domain resource only
                continue

            resources_elements[
                definition_klass.name] = definition_klass.elements

        elements_paths = build_elements_paths(resources_elements)

        fhir_es_mappings = fhir_types_mapping(self.fhir_release.name,
                                              reference_analyzer,
                                              token_normalizer)
        return {
            resource: {
                "properties": create_resource_mapping(paths_def,
                                                      fhir_es_mappings)
            }
            for resource, paths_def in elements_paths.items()
        }
예제 #3
0
def test_fhirspec_creation_using_factory(fhir_spec_settings):
    """ """
    release_name = "R4"
    if not ensure_spec_jsons(release_name):
        pytest.skip("Internet Connection is required")

    spec = FhirSpecFactory.from_release(release_name, fhir_spec_settings)
    assert spec.info.version_raw == "4.0.1-9346c8cc45"
예제 #4
0
def main(argv):
    """ """
    if len(argv) == 1:
        sys.stderr.write("At least one argument is required!\n")
        return 1

    import fhirpath
    from fhirpath.enums import FHIR_VERSION
    from fhirpath.fhirspec import FHIRSearchSpecFactory, FhirSpecFactory

    if argv[1] in ("-v", "--version"):
        sys.stdout.write(f"v{fhirpath.__version__}\n")
    elif argv[1] in ("-I", "--init-setup"):
        fhir_releases = ("R4", "STU3")
        if len(argv) == 3:
            if argv[2].startswith("--init-setup="):
                fhir_releases = [
                    i.strip() for i in argv[2].split("=")[1].split(",")
                    if FHIR_VERSION[i.strip()]
                ]
        elif len(argv) == 4:
            fhir_releases = [
                i.strip() for i in argv[2].split(",")
                if FHIR_VERSION[i.strip()]
            ]
        if not fhir_releases:
            sys.stderr.write("No FHIR version has been provided.\n")
            return 1

        for rel in fhir_releases:
            FhirSpecFactory.from_release(rel)
            sys.stdout.write(
                f"FHIR Specification has been initiated for version {rel}\n")

            FHIRSearchSpecFactory.from_release(rel)
            sys.stdout.write(
                f"FHIR Search Specification has been initiated for version {rel}\n"
            )

    else:
        sys.stderr.write("Invalid argument has be provided.\n")
        return 1
    return 0
예제 #5
0
def test_fhir_spec_download_and_load():
    """ """
    release = FHIR_VERSION["STU3"]
    spec_dir = spec_directory / release.name
    if not spec_dir.exists():
        spec_dir.mkdir()
    if (spec_dir / release.value).exists():
        shutil.rmtree((spec_dir / release.value))

    spec = FhirSpecFactory.from_release(release.name)

    assert spec.info.version_raw == "3.0.2.11917"