Beispiel #1
0
def test_fhirpath_list_type_info():
    """ """
    with open(str(FHIR_EXAMPLE_RESOURCES / "Patient.json"), "r") as fp:
        data = fp.read()
        obj = lookup_fhir_class("Patient", FHIR_VERSION.R4).parse_raw(data)
    fpath = fhirpath.FHIRPath(obj)
    assert isinstance(fpath.address.get_type(), fhirpath.ListTypeInfo)
    assert fpath.address.get_type().elementType == "FHIR.Address"
    assert isinstance(
        fhirpath.FHIRPath.__storage__[fpath.address.get_type().elementType],
        fhirpath.ClassInfo,
    )
    with pytest.raises(ValueError) as exc_info:
        fhirpath.FHIRPath(["mu", "mn"])
        assert "root fhirpath cannot be initialized" in exc_info.value.args[0]

    obj.address = None
    fpath = fhirpath.FHIRPath(obj)
    assert isinstance(fpath.address.get_type(), fhirpath.ListTypeInfo)

    obj.address = []
    fpath = fhirpath.FHIRPath(obj)
    assert isinstance(fpath.address.get_type(), fhirpath.ListTypeInfo)
    assert isinstance(fpath.extension.get_type(), fhirpath.ListTypeInfo)
    assert fpath.extension() is None
Beispiel #2
0
def test_fhirpath_simple_type_info():
    """ """
    with open(str(FHIR_EXAMPLE_RESOURCES / "Patient.json"), "r") as fp:
        data = fp.read()
        obj = lookup_fhir_class("Patient", FHIR_VERSION.R4).parse_raw(data)
    fpath = fhirpath.FHIRPath(obj)
    assert fpath.gender.get_type().name == "code"
    assert fpath.gender.get_type().baseType == "FHIR.Primitive"
    assert fpath.active.get_type().name == "boolean"

    assert fpath.identifier[0].type.text.get_type().name == "string"
    obj.gender = None
    obj.active = None
    fpath = fhirpath.FHIRPath(obj)
    assert fpath.gender.get_type().name == "code"
    assert fpath.active.get_type().name == "boolean"
Beispiel #3
0
def test_fhirpath_tuple_type_info():
    """ """
    with open(str(FHIR_EXAMPLE_RESOURCES / "Patient.json"), "r") as fp:
        data = fp.read()
        obj = lookup_fhir_class("Patient", FHIR_VERSION.R4).parse_raw(data)
    fpath = fhirpath.FHIRPath(obj)
    assert isinstance(fpath.contact[0].get_type(), fhirpath.TupleTypeInfo)
    assert len(fpath.contact[0].get_type().get_elements()) == 10
Beispiel #4
0
def test_existence_5_1_1_empty():
    """ """
    obj = lookup_fhir_class("Patient", FHIR_VERSION.R4).parse_file(
        FHIR_EXAMPLE_RESOURCES / "Patient.json")
    f_path = fhirpath.FHIRPath(obj)
    assert f_path.name.empty() is False
    assert f_path.name.count() == 2
    assert f_path.extension.empty() is True
    assert f_path.extension.count() == 0
Beispiel #5
0
def test_fhirpath_class_type_info():
    """ """
    with open(str(FHIR_EXAMPLE_RESOURCES / "Patient.json"), "r") as fp:
        data = fp.read()

        obj = lookup_fhir_class("Patient", FHIR_VERSION.R4).parse_raw(data)

    fpath = fhirpath.FHIRPath(obj)
    assert isinstance(fpath.get_type(), fhirpath.ClassInfo)
    # Patient has 26 elements
    assert len(fpath.get_type().element) == 26
    assert fpath.get_type().name == "Patient"
    assert fpath.get_type().baseType == "FHIR.DomainResource"
    # Test Element from Base
    assert fpath.meta.get_type().name == "Meta"