コード例 #1
0
def test_patient_equality():
    pt_1 = Patient("111 111 1111")
    pt_2 = Patient("111 111 1111")
    pt_3 = Patient("222 222 2222")

    assert pt_1 == pt_2
    assert pt_1 != pt_3
    assert pt_2 != pt_3
コード例 #2
0
def test_patient_list_extend(empty_patient_list, patient):
    patient_2 = Patient("222 222 2222")

    x = empty_patient_list.extend([patient, patient_2])

    assert x is None
    assert empty_patient_list.patients == [patient, patient_2]
コード例 #3
0
def test_patient_list_iter(empty_patient_list, patient):
    patient_2 = Patient("222 222 2222")

    empty_patient_list.extend([patient, patient_2])

    for list_pt, other_pt in zip(empty_patient_list, [patient, patient_2]):
        assert list_pt == other_pt
コード例 #4
0
def test_merge_fails_with_diff_patients(patient):
    pt_dict = {
        "forename": "Ronald",
        "surname": "O'Sullivan",
        "dob": date.today(),
        "reason_for_admission": "Aspiration pneumonia",
        "jobs": "Chase CXR",
        "edd": "Wed",
        "ds": "no",
        "tta": "yes",
        "bloods": "7",
    }
    new_location = {"ward": Ward.GLOSSOP, "room": "BAY 04 GL", "bed": "BedE"}
    old_location = {"ward": Ward.CAPENER, "room": "BAY 02 CA", "bed": "2A"}

    # start with a patient just with the up to date details from CareFlow
    patient.forename = pt_dict["forename"]
    patient.surname = pt_dict["surname"]
    patient.dob = pt_dict["dob"]

    for attr, value in new_location.items():
        setattr(patient, attr, value)

    # make a different patient, who is on the handover list, with all their jobs etc
    patient2 = Patient("222 222 2222")
    for attr, value in list(old_location.items()) + list(pt_dict.items()):
        setattr(patient2, attr, value)

    # merge them together
    with pytest.raises(ValueError):
        patient.merge(patient2)
コード例 #5
0
def test_patient_consistent_nhs_num():
    nhs_nums = [
        "1111111111", "111 111 1111", "1 1 11 1 11111", "111 111 1111\n"
    ]
    expected = "111 111 1111"

    for nhs_num in nhs_nums:
        assert Patient(nhs_num).nhs_number == expected
コード例 #6
0
def test_patient_from_table_row():
    class MockCell:
        def __init__(self, contents):
            self.text = contents

    class MockRow:
        def __init__(self, row):
            self.cells = [MockCell(text) for text in row]

    row = [
        "1A",  # location
        f"ALLEN, Mark\n{date.today():%d/%m/%Y} (0 Yrs)\n111 111 1111",  # patient details
        "Aspiration pneumonia",  # reason for admission
        "Settling",  # inpatient progress
        "Chase CXR",  # jobs
        "Wed",  # edd
        "Both done",  # tta_ds
        "7",  # bloods
    ]

    pt = Patient.from_table_row(MockRow(row))

    pt_dict = {
        "reason_for_admission": "Aspiration pneumonia",
        "jobs": "Chase CXR",
        "edd": "Wed",
        "tta_ds": "Both done",
        "bloods": "7",
    }

    for attr in pt_dict:
        assert getattr(pt, attr) == pt_dict[attr]

    row[1] = "pt details with no nhs number"

    with pytest.raises(ValueError):
        Patient.from_table_row(MockRow(row))
コード例 #7
0
def test_parse_nhs_number_from_table_cell():
    class MockCell:
        def __init__(self, contents):
            self.text = contents

    class MockRow:
        def __init__(self, row):
            self.cells = [MockCell(text) for text in row]

    for pt_details in [
            f"ALLEN, Mark\n{date.today():%d/%m/%Y} (0 Yrs)\n111 111 1111",
            f"ALLEN, Mark\n{date.today():%d/%m/%Y}\n111 111 1111",
            f"ALLEN, Mark\n{date.today():%d/%m/%Y} 111 111 1111",
            f"ALLEN, Mark\n{date.today():%d/%m/%Y} 1111111111",
            f"ALLEN, Mark\n{date.today():%d/%m/%Y} 111 111  1111  ",
            f"ALLEN, Mark\n{date.today():%d/%m/%Y}  \t 111 111  1111  ",
            f"ALLEN, Mark\n{date.today():%d/%m/%Y}  \t 111 111  1111  \n\t\n",
            # f"ALLEN, Mark\n{date.today():%d/%m/%Y}111 111  1111  \n\t\n",
            f"ALLEN, Mark\n{date.today():%d/%m/%Y}(0 Yrs)1111111111",
            f"ALLEN, Mark{date.today():%d/%m/%Y}(0 Yrs)1111111111",
            f"ALLEN, Mark\n111 111 1111\n{date.today():%d/%m/%Y} (0 Yrs)",
            f"ALLEN, Mark\n111 111 1111 {date.today():%d/%m/%Y} (0 Yrs)",
            f"ALLEN, Mark\n1111111111 {date.today():%d/%m/%Y} (0 Yrs)",
            f"1111111111\nALLEN, Mark\n{date.today():%d/%m/%Y} (0 Yrs)",
    ]:
        row = [
            "1A",  # location
            "{pt_details}".format(pt_details=pt_details),  # patient details
            "Aspiration pneumonia",  # reason for admission
            "Chase CXR",  # jobs
            "Wed",  # edd
            "no",  # ds
            "yes",  # tta
            "7",  # bloods
        ]

        pt = Patient.from_table_row(MockRow(row))
        print(pt_details)
        print(pt)
        assert pt.patient_id == "111 111 1111"
コード例 #8
0
def test_merge_patients(patient):
    pt_dict = {
        "forename": "Ronald",
        "surname": "O'Sullivan",
        "dob": date.today(),
        "reason_for_admission": "Aspiration pneumonia",
        "jobs": "Chase CXR",
        "edd": "Wed",
        "tta_ds": "Both done",
        "bloods": "7",
        "is_new": False,
    }
    new_location = {"ward": Ward.GLOSSOP, "room": "BAY 04 GL", "bed": "BedE"}
    old_location = {"ward": Ward.CAPENER, "room": "BAY 02 CA", "bed": "2A"}
    new_location_inst = Location(**new_location)

    # start with a patient just with the up to date details from TrakCare
    patient.forename = pt_dict["forename"]
    patient.surname = pt_dict["surname"]
    patient.dob = pt_dict["dob"]

    for attr, value in new_location.items():
        setattr(patient, attr, value)

    # make the same patient, who is on the handover list, with all their jobs etc
    patient2 = Patient(patient_id="111 111 1111")
    for attr, value in list(old_location.items()) + list(pt_dict.items()):
        setattr(patient2, attr, value)

    # merge them together
    patient.merge(patient2)

    # ensure that the resulting patient has all of the attributes taken from the handover list
    # but is also in the up to date location according to TrakCare
    for attr in pt_dict:
        assert getattr(patient, attr) == pt_dict[attr]

    assert patient.location == new_location_inst
コード例 #9
0
def test_parse_reg_number_from_table_cell():
    class MockCell:
        def __init__(self, contents):
            self.text = contents

    class MockRow:
        def __init__(self, row):
            self.cells = [MockCell(text) for text in row]

    pt_details = f"ALLEN, Mark\n{date.today():%d/%m/%Y} (0 Yrs)\n0123456"
    row = MockRow([
        "1A",  # location
        f"{pt_details}",  # patient details
        "Aspiration pneumonia",  # reason for admission
        "Chase CXR",  # jobs
        "Wed",  # edd
        "no",  # ds
        "yes",  # tta
        "7",  # bloods
    ])

    pt = Patient.from_table_row(row)

    assert pt.patient_id == "0123456"
コード例 #10
0
def patient():
    return Patient("111 111 1111")