Exemplo n.º 1
0
def test_calculate_sla_by_practice_calculates_sla_given_transfers_for_2_practices(
):
    practice_list = [
        PracticeDetails(asids=["121212121212"],
                        ods_code="A12345",
                        name="A Practice"),
        PracticeDetails(asids=["343434343434"],
                        ods_code="B12345",
                        name="Another Practice"),
    ]
    transfers = [
        build_transfer(
            requesting_practice_asid="121212121212",
            sla_duration=timedelta(days=8, hours=1, minutes=10),
        ),
        build_transfer(
            requesting_practice_asid="343434343434",
            sla_duration=timedelta(days=4, hours=1, minutes=10),
        ),
        build_transfer(
            requesting_practice_asid="121212121212",
            sla_duration=timedelta(days=0, hours=1, minutes=10),
        ),
        build_transfer(
            requesting_practice_asid="343434343434",
            sla_duration=timedelta(days=8, hours=1, minutes=10),
        ),
        build_transfer(
            requesting_practice_asid="343434343434",
            sla_duration=timedelta(days=5, hours=1, minutes=10),
        ),
    ]

    expected = [
        PracticeMetrics(
            ods_code="A12345",
            name="A Practice",
            integrated=IntegratedPracticeMetrics(transfer_count=2,
                                                 within_3_days=1,
                                                 within_8_days=0,
                                                 beyond_8_days=1),
        ),
        PracticeMetrics(
            ods_code="B12345",
            name="Another Practice",
            integrated=IntegratedPracticeMetrics(transfer_count=3,
                                                 within_3_days=0,
                                                 within_8_days=2,
                                                 beyond_8_days=1),
        ),
    ]

    actual = calculate_sla_by_practice(practice_list, transfers)
    actual_sorted = sorted(actual, key=lambda p: p.ods_code)

    assert actual_sorted == expected
def calculate_practice_metrics_data(
    transfers: List[Transfer],
    practice_list: List[PracticeDetails],
    time_range: DateTimeRange,
) -> PracticeMetricsPresentation:
    completed_transfers = filter_for_successful_transfers(transfers)
    sla_metrics = calculate_sla_by_practice(practice_list, completed_transfers)
    practice_metrics = construct_practice_metrics(sla_metrics,
                                                  year=time_range.start.year,
                                                  month=time_range.start.month)
    return practice_metrics
Exemplo n.º 3
0
def test_groups_by_ods_code_given_single_practice_and_no_transfers():
    practices = [
        PracticeDetails(asids=["121212121212"],
                        ods_code="A12345",
                        name=a_string())
    ]
    transfers = []

    actual = calculate_sla_by_practice(practices, transfers)

    _assert_has_ods_codes(actual, {"A12345"})
Exemplo n.º 4
0
def test_contains_practice_name():
    expected_name = "A Practice"
    practices = [
        PracticeDetails(asids=[a_string()],
                        ods_code=a_string(),
                        name=expected_name)
    ]
    transfers = []

    actual_name = list(calculate_sla_by_practice(practices, transfers))[0].name

    assert actual_name == expected_name
Exemplo n.º 5
0
def test_returns_practice_sla_metrics_placeholder_given_a_list_with_one_practice_and_no_metrics(
):
    practice_list = [
        PracticeDetails(asids=["121212121212"],
                        ods_code="A12345",
                        name=a_string())
    ]
    transfers = []
    actual = calculate_sla_by_practice(practice_list, transfers)

    _assert_first_summary_has_sla_counts(actual,
                                         within_3_days=0,
                                         within_8_days=0,
                                         beyond_8_days=0)
Exemplo n.º 6
0
def test_groups_by_asid_given_single_practice_and_transfers_from_the_same_practice(
):
    practices = [
        PracticeDetails(asids=["121212121212"],
                        ods_code="A12345",
                        name=a_string())
    ]
    transfers = [
        build_transfer(requesting_practice_asid="121212121212"),
        build_transfer(requesting_practice_asid="121212121212"),
    ]

    actual = calculate_sla_by_practice(practices, transfers)

    _assert_has_ods_codes(actual, {"A12345"})
Exemplo n.º 7
0
def test_calculate_sla_by_practice_calculates_sla_given_one_transfer_within_3_days(
):
    practice_list = [
        PracticeDetails(asids=["121212121212"],
                        ods_code="A12345",
                        name=a_string())
    ]
    transfer = build_transfer(requesting_practice_asid="121212121212",
                              sla_duration=timedelta(hours=1, minutes=10))
    actual = calculate_sla_by_practice(practice_list, [transfer])

    _assert_first_summary_has_sla_counts(actual,
                                         within_3_days=1,
                                         within_8_days=0,
                                         beyond_8_days=0)
Exemplo n.º 8
0
def test_groups_by_asid_given_two_practices_and_two_transfers_from_different_practices(
):
    practices = [
        PracticeDetails(asids=["121212121212"],
                        ods_code="A12345",
                        name=a_string()),
        PracticeDetails(asids=["343434343434"],
                        ods_code="X67890",
                        name=a_string()),
    ]
    transfers = [
        build_transfer(requesting_practice_asid="121212121212"),
        build_transfer(requesting_practice_asid="343434343434"),
    ]

    actual = calculate_sla_by_practice(practices, transfers)

    _assert_has_ods_codes(actual, {"A12345", "X67890"})
Exemplo n.º 9
0
def test_counts_both_asids_for_practice_with_two_asids():
    practice_list = [
        PracticeDetails(asids=["121212121212", "343434343434"],
                        ods_code="A12345",
                        name=a_string())
    ]
    transfers = [
        build_transfer(
            requesting_practice_asid="343434343434",
            sla_duration=timedelta(hours=1, minutes=10),
        ),
        build_transfer(
            requesting_practice_asid="121212121212",
            sla_duration=timedelta(days=5, hours=1, minutes=10),
        ),
    ]
    actual = calculate_sla_by_practice(practice_list, transfers)

    _assert_first_summary_has_sla_counts(actual,
                                         within_3_days=1,
                                         within_8_days=1,
                                         beyond_8_days=0)
Exemplo n.º 10
0
def test_returns_sum_of_all_integrated_transfers():
    practice_list = [
        PracticeDetails(asids=["121212121212"],
                        ods_code="A12345",
                        name=a_string())
    ]
    transfers = [
        build_transfer(
            requesting_practice_asid="121212121212",
            sla_duration=timedelta(days=0, hours=1, minutes=10),
        ),
        build_transfer(
            requesting_practice_asid="121212121212",
            sla_duration=timedelta(days=7, hours=1, minutes=10),
        ),
        build_transfer(
            requesting_practice_asid="121212121212",
            sla_duration=timedelta(days=10, hours=1, minutes=10),
        ),
    ]
    actual = list(calculate_sla_by_practice(practice_list, transfers))

    assert actual[0].integrated.transfer_count == 3
Exemplo n.º 11
0
def test_warns_about_transfer_with_unexpected_asid():
    practices = []
    transfers = [build_transfer(requesting_practice_asid="121212121212")]

    with pytest.warns(RuntimeWarning):
        calculate_sla_by_practice(practices, transfers)