Exemple #1
0
def test_in_query(es_data, engine):
    """ """
    builder = Q_(resource="Organization", engine=engine)
    builder = builder.where(T_("Organization.active") == V_("true")).where(
        in_(
            "Organization.meta.lastUpdated",
            (
                "2010-05-28T05:35:56+00:00",
                "2001-05-28T05:35:56+00:00",
                "2018-05-28T05:35:56+00:00",
            ),
        ))
    result = builder().fetchall()
    assert result.header.total == 1

    # Test NOT IN
    builder = Q_(resource="Organization", engine=engine)
    builder = builder.where(T_("Organization.active") == V_("true")).where(
        not_in_(
            "Organization.meta.lastUpdated",
            (
                "2010-05-28T05:35:56+00:00",
                "2001-05-28T05:35:56+00:00",
                "2018-05-28T05:35:56+00:00",
            ),
        ))
    result = builder().fetchall()
    assert result.header.total == 0
Exemple #2
0
def test_result_count(es_data, engine):
    """ """
    conn, meta_info = es_data
    load_organizations_data(conn, 5)
    builder = Q_(resource="Organization", engine=engine)
    builder = builder.where(T_("Organization.active") == V_("true"))
    assert builder().count() == 6

    builder = Q_(resource="Organization", engine=engine)
    builder = builder.where(T_("Organization.active") == V_("false"))
    assert builder().count() == 0
Exemple #3
0
async def test_async_result_empty(es_data, async_engine):
    """ """
    conn, meta_info = es_data
    load_organizations_data(conn, 5)
    builder = Q_(resource="Organization", engine=async_engine)
    builder = builder.where(T_("Organization.active") == V_("false"))
    empty = await builder().empty()
    assert empty is True
Exemple #4
0
async def test_async_select_muiltipaths(es_data, async_engine):
    """ """
    builder = Q_(resource="Organization",
                 engine=async_engine).select("Organization.name",
                                             "Organization.address")
    builder = builder.where(T_("Organization.active") == V_("true"))
    result = await builder().fetchall()

    # FIXME looks like we changed how things are built here
    assert len(result.body[0]) == 2
Exemple #5
0
def test_query_with_non_fhir_select(es_data, engine):
    """ """
    builder = Q_(resource="Patient", engine=engine)
    el_path1 = ElementPath("creation_date", non_fhir=True)
    el_path2 = ElementPath("title", non_fhir=True)
    builder = builder.select(
        el_path1, el_path2).where(T_("Patient.gender") == V_("male"))

    result = builder().fetchall()

    assert len(result.header.selects) == 2
    assert "creation_date" in result.header.selects
Exemple #6
0
async def test_in_query(es_requester):
    """ """
    async with es_requester as requester:
        container, request, txn, tm = await setup_txn_on_container(requester
                                                                   )  # noqa
        # init primary data
        await init_data(requester)
        engine = query_utility(IElasticsearchEngineFactory).get()

        index_name = await engine.get_index_name(container)

        conn = engine.connection.raw_connection
        await conn.indices.refresh(index=index_name)

        builder = Q_(resource="Organization", engine=engine)
        builder = builder.where(T_("Organization.active") == V_("true")).where(
            in_(
                "Organization.meta.lastUpdated",
                (
                    "2010-05-28T05:35:56+00:00",
                    "2001-05-28T05:35:56+00:00",
                    "2018-05-28T05:35:56+00:00",
                ),
            ))
        result = await builder(async_result=True).fetchall()
        assert result.header.total == 1

        # Test NOT IN
        builder = Q_(resource="Organization", engine=engine)
        builder = builder.where(T_("Organization.active") == V_("true")).where(
            not_in_(
                "Organization.meta.lastUpdated",
                ("2010-05-28T05:35:56+00:00", "2001-05-28T05:35:56+00:00",
                 "2018-05-28T05:35:56+00:00", "2015-05-28T05:35:56+00:00",
                 "2019-10-03T05:35:56+00:00"),
            ))
        result = await builder(async_result=True).fetchall()
        assert result.header.total == 0
Exemple #7
0
def test_result_with_path_contains_index(es_data, engine):
    """ """
    conn, meta_info = es_data
    load_organizations_data(conn, 5)
    builder = Q_(resource="Organization", engine=engine)
    builder = builder.select("Organization.name.count()",
                             "Organization.address[1]").where(
                                 T_("Organization.active") == V_("true"))
    result = builder().fetchall()
    expected_length = "Burgers University Medical Center"
    expected_postal_code = "9100 AA"

    assert result.body[0][0] == len(expected_length)
    assert result.body[0][1]["postalCode"] == expected_postal_code
Exemple #8
0
async def test_async_fetch_all(es_data, async_engine):
    """ """
    conn, meta_info = es_data
    load_organizations_data(conn, 152)

    builder = Q_(resource="Organization", engine=async_engine)
    builder = (builder.where(T_("Organization.active") == V_("true")).where(
        T_("Organization.meta.lastUpdated", "2010-05-28T05:35:56+00:00")).sort(
            sort_("Organization.meta.lastUpdated",
                  SortOrderType.DESC)).limit(20, 2))
    async for resource in builder():
        assert resource.__class__.__name__ == "Organization"
        # test fetch all
    result = await builder().fetchall()
    assert result.__class__.__name__ == "EngineResult"
Exemple #9
0
def test_result_path_contains_function(es_data, engine):
    """ """
    builder = Q_(resource="Patient", engine=engine)
    builder = builder.select(
        "Patient.name.first().given.Skip(0).Take(0)",
        "Patient.identifier.last().assigner.display",
    ).where(T_("Patient.gender") == V_("male"))
    result = builder().fetchall()

    assert result.body[0][0] == "Patient"
    assert result.body[0][1] == "Zitelab ApS"

    # Test Some exception
    with pytest.raises(NotImplementedError):
        builder = Q_(resource="Patient", engine=engine)
        builder = builder.select("Patient.language.Skip(0)").where(
            T_("Patient.gender") == V_("male"))
        result = builder().first()

    with pytest.raises(ValidationError):
        builder = Q_(resource="Patient", engine=engine)
        builder = builder.select("Patient.address[0].Skip(0)").where(
            T_("Patient.gender") == V_("male"))
        result = builder().first()