def test_complete_bundle_count():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([("_summary", "count")]), "Patient")
    bundle = Bundle()
    bundle.fill(
        {
            "count": 1,
            "_shards": {
                "total": 1,
                "successful": 1,
                "skipped": 0,
                "failed": 0
            }
        },
        search_args.formatting_args,
    )
    other_bundle = Bundle()
    other_bundle.content = {
        "resource_type": "Bundle",
        "tag": {
            "code": "SUBSETTED"
        },
        "total": 1
    }
    bundle.complete(other_bundle, search_args.formatting_args)
    assert bundle.content["total"] == 2
    assert bundle.content == {
        "resource_type": "Bundle",
        "tag": {
            "code": "SUBSETTED"
        },
        "total": 2,
    }
def test_sort_params():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([("_sort", "-birthDate,active")]), "Patient")
    assert search_args.formatting_args["sort"] == [
        {"birthDate": {"order": "desc"}},
        "active",
    ]
def test_sort_params_desc_and_score_asc():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([("_sort", "-birthDate,-_score")]), "Patient")
    assert search_args.formatting_args["sort"] == [
        {"birthDate": {"order": "desc"}},
        {"_score": {"order": "asc"}},
    ]
def test_mix_parameters():
    search_args = SearchArguments()
    search_args.parse(
        ImmutableMultiDict(
            [
                ("_count", "200"),
                ("_summary", "text"),
                ("_elements", "birthDate,gender"),
                ("language", "FR"),
                ("language", "EN,NL"),
            ]
        ),
        "Patient",
    )
    assert search_args.resource_type == "Patient"
    assert search_args.core_args == {
        "language": ["FR"],
        "multiple": {"language": ["EN", "NL"]},
    }
    assert search_args.formatting_args["sort"] is None
    assert search_args.formatting_args["elements"] == ["text", "id", "meta"]
    assert search_args.formatting_args["include"] is None
    assert search_args.formatting_args["summary"] is True
    assert search_args.formatting_args["is_summary_count"] is False
    assert search_args.meta_args["offset"] == 0
    assert search_args.meta_args["result_size"] == 200
def test_fill_no_tag_search_bundle():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([("_summary", "false")]), "Patient")
    bundle = Bundle()
    bundle.fill({}, search_args.formatting_args)
    assert bundle.content == {
        "resource_type": "Bundle",
        "entry": [],
        "total": 0,
    }
def test_fill_count_bundle():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([("_summary", "count")]), "Patient")
    bundle = Bundle()
    bundle.fill({}, search_args.formatting_args)
    assert bundle.content == {
        "resource_type": "Bundle",
        "tag": {
            "code": "SUBSETTED"
        },
        "total": 0,
    }
def test_result_size():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([("_count", "2")]), "Patient")
    assert search_args.resource_type == "Patient"
    assert search_args.core_args == {}
    assert search_args.formatting_args["sort"] is None
    assert search_args.formatting_args["elements"] is None
    assert search_args.formatting_args["include"] is None
    assert search_args.formatting_args["summary"] is False
    assert search_args.formatting_args["is_summary_count"] is False
    assert search_args.meta_args["offset"] == 0
    assert search_args.meta_args["result_size"] == 2
def test_mix_params_include_multiple():
    search_args = SearchArguments()
    search_args.parse(
        ImmutableMultiDict([("_include", "MedicationRequest:subject,MedicationRequest:requester")]),
        "Patient",
    )
    assert search_args.core_args == {}
    assert search_args.formatting_args["sort"] is None
    assert search_args.formatting_args["elements"] is None
    assert search_args.formatting_args["include"] == ["subject", "requester"]
    assert search_args.formatting_args["summary"] is False
    assert search_args.formatting_args["is_summary_count"] is False
    assert search_args.meta_args["offset"] == 0
    assert search_args.meta_args["result_size"] == 100
def test_add_included_bundle_no_include():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([]), "Patient")
    bundle = Bundle()
    bundle.append(
        {
            "took": 2,
            "timed_out": False,
            "_shards": {
                "total": 1,
                "successful": 1,
                "skipped": 0,
                "failed": 0
            },
            "hits": {
                "total": {
                    "value": 1,
                    "relation": "eq"
                },
                "max_score":
                1.0925692,
                "hits": [{
                    "_index": "fhirstore.patient",
                    "_type": "_doc",
                    "_id": "5e96c51977d71dc87644653b",
                    "_score": 1.0925692,
                    "_source": {
                        "active":
                        True,
                        "contact": [{
                            "organization": {
                                "display": "Walt Disney Corporation",
                                "reference": "Organization/1",
                            }
                        }],
                    },
                }],
            },
        },
        search_args.formatting_args,
    )
    assert bundle.content == {
        "resource_type": "Bundle",
        "entry": [],
        "total": 0,
    }
def test_mix_params_sort():
    search_args = SearchArguments()
    search_args.parse(
        ImmutableMultiDict([("language", "FR"), ("language", "EN,NL"), ("_sort", "birthDate")]),
        "Patient",
    )
    assert search_args.core_args == {
        "language": ["FR"],
        "multiple": {"language": ["EN", "NL"]},
    }
    assert search_args.formatting_args["sort"] == ["birthDate"]
    assert search_args.formatting_args["elements"] is None
    assert search_args.formatting_args["include"] is None
    assert search_args.formatting_args["summary"] is False
    assert search_args.formatting_args["is_summary_count"] is False
    assert search_args.meta_args["offset"] == 0
    assert search_args.meta_args["result_size"] == 100
Exemple #11
0
def test_complete_bundle():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([]), "Patient")
    bundle = Bundle()
    bundle.fill(
        {
            "took": 2,
            "timed_out": False,
            "_shards": {
                "total": 1,
                "successful": 1,
                "skipped": 0,
                "failed": 0
            },
            "hits": {
                "total": {
                    "value": 1,
                    "relation": "eq"
                },
                "max_score":
                1.0925692,
                "hits": [{
                    "_index": "fhirstore.patient",
                    "_type": "_doc",
                    "_id": "5e96c51977d71dc87644653b",
                    "_score": 1.0925692,
                    "_source": {
                        "active":
                        True,
                        "contact": [{
                            "organization": {
                                "display": "Walt Disney Corporation",
                                "reference": "Organization/1",
                            }
                        }],
                    },
                }],
            },
        },
        search_args.formatting_args,
    )
    new_bundle = Bundle()
    new_bundle.content = {
        "entry": [{
            "resource": {
                "active": True,
                "birthDate": "1932-09-24",
                "gender": "male",
                "id": "xcda",
                "name": [{
                    "family": "Levin",
                    "given": ["Henry"]
                }],
                "resourceType": "Patient",
            },
            "search": {
                "mode": "match"
            },
        }],
        "resource_type":
        "Bundle",
        "total":
        1,
    }
    bundle.complete(new_bundle, search_args.formatting_args)
    assert bundle.content["total"] == 2
    assert bundle.content["entry"] == [
        {
            "resource": {
                "active":
                True,
                "contact": [{
                    "organization": {
                        "display": "Walt Disney Corporation",
                        "reference": "Organization/1",
                    }
                }],
            },
            "search": {
                "mode": "match"
            },
        },
        {
            "resource": {
                "active": True,
                "birthDate": "1932-09-24",
                "gender": "male",
                "id": "xcda",
                "name": [{
                    "family": "Levin",
                    "given": ["Henry"]
                }],
                "resourceType": "Patient",
            },
            "search": {
                "mode": "match"
            },
        },
    ]
def test_sort_score_asc():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([("_sort", "-_score")]), "Patient")
    assert search_args.formatting_args["sort"] == [{"_score": {"order": "asc"}}]
def test_sort_score():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([("_sort", "_score")]), "Patient")
    assert search_args.formatting_args["sort"] == ["_score"]
def test_sort_param_desc():
    search_args = SearchArguments()
    search_args.parse({"_sort": ["-birthDate"]}, "Patient")
    assert search_args.formatting_args["sort"] == [{"birthDate": {"order": "desc"}}]
def test_no_sort_param():
    search_args = SearchArguments()
    search_args.parse(ImmutableMultiDict([("language", "FR")]), "Patient")
    assert search_args.formatting_args["sort"] is None
def test_sort_param():
    search_args = SearchArguments()
    search_args.parse({"_sort": ["birthDate"]}, "Patient")
    assert search_args.formatting_args["sort"] == ["birthDate"]