Exemplo n.º 1
0
async def test_record_treatments(client):
    response = await client.get(
        f"{configuration.base_url}/v1/patientrecords/PYTEST01:PV:00000000A/treatments"
    )
    assert response.status_code == 200
    assert {
        "id": "TREATMENT1",
        "fromTime": days_ago(730).date().isoformat(),
        "toTime": None,
        "admitReasonCode": "1",
        "admitReasonCodeStd": None,
        "admitReasonDesc": None,
        "dischargeReasonCode": None,
        "dischargeReasonCodeStd": None,
        "dischargeReasonDesc": None,
        "healthCareFacilityCode": "TEST_SENDING_FACILITY_1",
    } in response.json()

    assert {
        "id": "TREATMENT2",
        "fromTime": days_ago(730).date().isoformat(),
        "toTime": days_ago(-999).date().isoformat(),
        "admitReasonCode": "1",
        "admitReasonCodeStd": None,
        "admitReasonDesc": None,
        "dischargeReasonCode": None,
        "dischargeReasonCodeStd": None,
        "dischargeReasonDesc": None,
        "healthCareFacilityCode": "TEST_SENDING_FACILITY_1",
    } in response.json()
Exemplo n.º 2
0
async def test_record_observations(client):
    response = await client.get(
        f"{configuration.base_url}/v1/patientrecords/PYTEST01:PV:00000000A/observations"
    )
    assert response.status_code == 200
    assert {
        "enteredAt": None,
        "enteredAtDescription": None,
        "observationDesc": "OBSERVATION_SYS_1_DESC",
        "observationTime": days_ago(730).isoformat(),
        "observationUnits": "OBSERVATION_SYS_1_UNITS",
        "observationValue": "OBSERVATION_SYS_1_VALUE",
        "prePost": None,
    } in response.json()["items"]

    assert {
        "enteredAt": None,
        "enteredAtDescription": None,
        "observationDesc": "OBSERVATION_DIA_1_DESC",
        "observationTime": days_ago(730).isoformat(),
        "observationUnits": "OBSERVATION_DIA_1_UNITS",
        "observationValue": "OBSERVATION_DIA_1_VALUE",
        "prePost": None,
    } in response.json()["items"]

    assert {
        "enteredAt": None,
        "enteredAtDescription": None,
        "observationDesc": "OBSERVATION_DESC",
        "observationTime": days_ago(365).isoformat(),
        "observationUnits": "OBSERVATION_UNITS",
        "observationValue": "OBSERVATION_VALUE",
        "prePost": None,
    } in response.json()["items"]
Exemplo n.º 3
0
def test_get_full_workitem_history_all_time(jtrace_session):
    history = workitems.get_full_workitem_history(
        jtrace_session, since=date(1970, 1, 1)
    )
    d = {point.time: point.count for point in history}
    assert d[days_ago(365).date()] == 1
    assert d[days_ago(1).date()] == 3
Exemplo n.º 4
0
def test_get_full_errors_history(stats_session):
    history_test_1 = ErrorHistory(facility="TEST_SENDING_FACILITY_99",
                                  date=days_ago(1).date(),
                                  count=1)
    history_test_2 = ErrorHistory(facility="TEST_SENDING_FACILITY_98",
                                  date=days_ago(2).date(),
                                  count=1)

    stats_session.add(history_test_1)
    stats_session.add(history_test_2)
    stats_session.commit()

    history = get_full_errors_history(stats_session)

    d = {point.time: point.count for point in history}
    assert d[days_ago(1).date()] == 2
    assert d[days_ago(2).date()] == 1
Exemplo n.º 5
0
async def test_laborder_delete(client, ukrdc3_session):
    laborder = LabOrder(
        id="LABORDER_TEMP",
        pid="PYTEST01:PV:00000000A",
        external_id="EXTERNAL_ID_TEMP",
        order_category="ORDER_CATEGORY_TEMP",
        specimen_collected_time=days_ago(365),
    )
    resultitem = ResultItem(
        id="RESULTITEM_TEMP",
        order_id="LABORDER_TEMP",
        service_id_std="SERVICE_ID_STD_TEMP",
        service_id="SERVICE_ID_TEMP",
        service_id_description="SERVICE_ID_DESCRIPTION_TEMP",
        value="VALUE_TEMP",
        value_units="VALUE_UNITS_TEMP",
        observation_time=days_ago(365),
    )
    ukrdc3_session.add(laborder)
    ukrdc3_session.add(resultitem)
    ukrdc3_session.commit()

    # Make sure the laborder was created
    assert ukrdc3_session.query(LabOrder).get("LABORDER_TEMP")
    assert ukrdc3_session.query(ResultItem).get("RESULTITEM_TEMP")
    response = await client.get(
        f"{configuration.base_url}/v1/patientrecords/PYTEST01:PV:00000000A/laborders/LABORDER_TEMP"
    )
    assert response.status_code == 200

    # Delete the lab order
    response = await client.delete(
        f"{configuration.base_url}/v1/patientrecords/PYTEST01:PV:00000000A/laborders/LABORDER_TEMP/"
    )
    assert response.status_code == 204

    # Make sure the lab order was deleted
    response = await client.get(
        f"{configuration.base_url}/v1/patientrecords/PYTEST01:PV:00000000A/laborders/LABORDER_TEMP/"
    )
    assert response.status_code == 404
    assert not ukrdc3_session.query(LabOrder).get("LABORDER_TEMP")
    assert not ukrdc3_session.query(ResultItem).get("RESULTITEM_TEMP")
Exemplo n.º 6
0
def _create_membership(pid: str, ukrdc3_session):
    membership = ProgramMembership(
        id="MEMBERSHIP_PKB",
        pid=pid,
        program_name="PKB",
        from_time=days_ago(365),
        to_time=None,
    )
    ukrdc3_session.add(membership)
    ukrdc3_session.commit()
Exemplo n.º 7
0
def test_get_extended_workitem_superuser(jtrace_session, superuser):
    # Create a new master record
    master_record_999 = MasterRecord(
        id=999,
        status=0,
        last_updated=days_ago(0),
        date_of_birth=datetime(1980, 12, 12),
        nationalid="119999999",
        nationalid_type="UKRDC",
        effective_date=days_ago(0),
    )

    # Link the new master record to an existing person
    link_record_999 = LinkRecord(
        id=999,
        person_id=1,
        master_id=999,
        link_type=0,
        link_code=0,
        last_updated=days_ago(0),
    )

    # Person 3 now has 2 master records we want to merge
    jtrace_session.add(master_record_999)
    jtrace_session.add(link_record_999)
    jtrace_session.commit()

    record = workitems.get_extended_workitem(jtrace_session, 1, superuser)
    assert record
    assert record.id == 1

    in_person = record.incoming.person.id
    in_masters = [master.id for master in record.incoming.master_records]
    dest_master = record.destination.master_record.id
    dest_persons = [person.id for person in record.destination.persons]

    assert in_person == 1
    assert in_masters == [1, 999]
    assert dest_master == 4
    assert dest_persons == [4]
Exemplo n.º 8
0
async def test_record_medications(client):
    response = await client.get(
        f"{configuration.base_url}/v1/patientrecords/PYTEST01:PV:00000000A/medications"
    )
    assert response.status_code == 200
    assert response.json() == [
        {
            "fromTime": days_ago(730).isoformat(),
            "toTime": None,
            "drugProductGeneric": "DRUG_PRODUCT_GENERIC",
            "comment": None,
            "enteringOrganizationCode": None,
            "enteringOrganizationDescription": None,
        },
        {
            "fromTime": days_ago(730).isoformat(),
            "toTime": days_ago(-999).isoformat(),
            "drugProductGeneric": "DRUG_PRODUCT_GENERIC_2",
            "comment": None,
            "enteringOrganizationCode": None,
            "enteringOrganizationDescription": None,
        },
    ]
Exemplo n.º 9
0
async def test_record_surveys(client):
    response = await client.get(
        f"{configuration.base_url}/v1/patientrecords/PYTEST01:PV:00000000A/surveys"
    )
    assert response.status_code == 200
    assert response.json() == [{
        "questions": [
            {
                "id": "QUESTION1",
                "questiontypecode": "TYPECODE1",
                "response": "RESPONSE1",
                "questionGroup": None,
                "questionType": None,
                "responseText": None,
            },
            {
                "id": "QUESTION2",
                "questiontypecode": "TYPECODE2",
                "response": "RESPONSE2",
                "questionGroup": None,
                "questionType": None,
                "responseText": None,
            },
        ],
        "scores": [{
            "id": "SCORE1",
            "value": "SCORE_VALUE",
            "scoretypecode": "TYPECODE"
        }],
        "levels": [{
            "id": "LEVEL1",
            "value": "LEVEL_VALUE",
            "leveltypecode": "TYPECODE"
        }],
        "id":
        "SURVEY1",
        "pid":
        "PYTEST01:PV:00000000A",
        "surveytime":
        days_ago(730).isoformat(),
        "surveytypecode":
        "TYPECODE",
        "enteredbycode":
        "ENTEREDBYCODE",
        "enteredatcode":
        "ENTEREDATCODE",
    }]
Exemplo n.º 10
0
async def test_record_export_pkb(client, ukrdc3_session):
    # Ensure PKB membership
    PID_1 = "PYTEST01:PV:00000000A"
    membership = ProgramMembership(
        id="MEMBERSHIP_PKB",
        pid=PID_1,
        program_name="PKB",
        from_time=days_ago(365),
        to_time=None,
    )
    ukrdc3_session.add(membership)
    ukrdc3_session.commit()

    response = await client.post(
        f"{configuration.base_url}/v1/patientrecords/PYTEST01:PV:00000000A/export/pkb/",
        json={},
    )
    assert response.status_code == 202
    task = TrackableTaskSchema(**response.json())
    assert task.status == "pending"

    task_status = await client.get(f"{configuration.base_url}/v1/tasks/{task.id}/")
    assert task_status.status_code == 200
    assert task_status.json().get("status") == "finished"
Exemplo n.º 11
0
async def test_record_export_pkb(ukrdc3_session, redis_session, mirth_session,
                                 superuser):
    # Ensure PKB membership
    PID_1 = "PYTEST01:PV:00000000A"
    membership = ProgramMembership(
        id="MEMBERSHIP_PKB",
        pid=PID_1,
        program_name="PKB",
        from_time=days_ago(365),
        to_time=None,
    )
    ukrdc3_session.add(membership)
    ukrdc3_session.commit()

    # Store responses
    messages = []

    # Iterate over each message response
    for response in await export.export_all_to_pkb(PID_1, superuser,
                                                   ukrdc3_session,
                                                   mirth_session,
                                                   redis_session):
        messages.append(response.message)
        assert response.status == "success"

    assert messages == [
        "<result><msg_type>ADT_A28</msg_type><pid>PYTEST01:PV:00000000A</pid></result>",
        "<result><msg_type>MDM_T02_CP</msg_type><pid>PYTEST01:PV:00000000A</pid></result>",
        "<result><msg_type>MDM_T02_DOC</msg_type><pid>PYTEST01:PV:00000000A</pid><id>DOCUMENT_PDF</id></result>",
        "<result><msg_type>MDM_T02_DOC</msg_type><pid>PYTEST01:PV:00000000A</pid><id>DOCUMENT_TXT</id></result>",
        "<result><msg_type>ORU_R01_LAB</msg_type><pid>PYTEST01:PV:00000000A</pid><id>LABORDER1</id></result>",
        "<result><msg_type>ORU_R01_LAB</msg_type><pid>PYTEST01:PV:00000000A</pid><id>LABORDER2</id></result>",
        "<result><msg_type>ORU_R01_OBS</msg_type><pid>PYTEST01:PV:00000000A</pid><id>OBSERVATION1</id></result>",
        "<result><msg_type>ORU_R01_OBS</msg_type><pid>PYTEST01:PV:00000000A</pid><id>OBSERVATION_DIA_1</id></result>",
        "<result><msg_type>ORU_R01_OBS</msg_type><pid>PYTEST01:PV:00000000A</pid><id>OBSERVATION_SYS_1</id></result>",
    ]
Exemplo n.º 12
0
def test_get_workitems_until(jtrace_session, superuser):
    all_items = workitems.get_workitems(jtrace_session, superuser, until=days_ago(2))
    assert {item.id for item in all_items} == {1}
Exemplo n.º 13
0
def test_get_workitems_since(jtrace_session, superuser):
    all_items = workitems.get_workitems(jtrace_session, superuser, since=days_ago(1))
    assert {item.id for item in all_items} == {2, 3}
Exemplo n.º 14
0
def test_get_full_workitem_history_default(jtrace_session):
    history = workitems.get_full_workitem_history(jtrace_session)
    d = {point.time: point.count for point in history}
    assert d[days_ago(1).date()] == 3
Exemplo n.º 15
0
async def test_workitems_list_filter_until(client):
    until = days_ago(365).isoformat()
    response = await client.get(f"{configuration.base_url}/v1/workitems?until={until}")
    assert response.status_code == 200
    returned_ids = {item["id"] for item in response.json()["items"]}
    assert returned_ids == {1}
Exemplo n.º 16
0
async def test_workitems_list_filter_since(client):
    since = days_ago(2).isoformat()
    response = await client.get(f"{configuration.base_url}/v1/workitems?since={since}")
    assert response.status_code == 200
    returned_ids = {item["id"] for item in response.json()["items"]}
    assert returned_ids == {2, 3}