Exemple #1
0
 def derive_transfer(
     self, conversation: Gp2gpConversation, organisation_lookup: OrganisationLookup
 ) -> Transfer:
     sla_duration = _calculate_sla(conversation, self._probe)
     requesting_practice_asid = conversation.requesting_practice_asid()
     sending_practice_asid = conversation.sending_practice_asid()
     return Transfer(
         conversation_id=conversation.conversation_id(),
         sla_duration=sla_duration,
         requesting_practice=Practice(
             asid=requesting_practice_asid,
             supplier=conversation.requesting_supplier(),
             ods_code=organisation_lookup.practice_ods_code_from_asid(requesting_practice_asid),
         ),
         sending_practice=Practice(
             asid=sending_practice_asid,
             supplier=conversation.sending_supplier(),
             ods_code=organisation_lookup.practice_ods_code_from_asid(sending_practice_asid),
         ),
         sender_error_codes=conversation.sender_error_codes(),
         final_error_codes=conversation.final_error_codes(),
         intermediate_error_codes=conversation.intermediate_error_codes(),
         outcome=TransferOutcome.from_gp2gp_conversation(conversation, sla_duration),
         date_requested=conversation.date_requested(),
         date_completed=conversation.effective_final_acknowledgement_time(),
         last_sender_message_timestamp=conversation.last_sender_message_timestamp(),
     )
Exemple #2
0
def test_convert_one_organisation_metadata_file_to_organisation_lookup():
    s3_manager = Mock()

    transfer_classifier_io = TransferClassifierIO(s3_data_manager=s3_manager)

    s3_manager.read_json.return_value = _ORGANISATION_METADATA_DICT_FIRST_MONTH

    actual_metadatas = transfer_classifier_io.read_ods_metadata_files(
        s3_uris=[_S3_URI])
    actual_organisation_lookup = actual_metadatas.get_lookup(
        _DATE_ANCHOR_YEAR_MONTH)

    expected_first_month_practices = [
        PracticeDetails(ods_code="ABC", name="A Practice", asids=["123"])
    ]
    expected_first_month_ccgs = [
        CcgDetails(ods_code="XYZ", name="A CCG", practices=["ABC"])
    ]
    expected_organisation_lookup = OrganisationLookup(
        expected_first_month_practices, expected_first_month_ccgs)

    assert actual_organisation_lookup.practice_ods_code_from_asid(
        "123") == expected_organisation_lookup.practice_ods_code_from_asid(
            "123")

    s3_manager.read_json.assert_called_once_with(_S3_URI)
Exemple #3
0
def test_ccg_ods_code_from_practice_ods_code_returns_none_given_no_ccgs():
    practice_lookup = OrganisationLookup(practices=[], ccgs=[])

    expected = None

    actual = practice_lookup.ccg_ods_code_from_practice_ods_code("A123")

    assert actual == expected
Exemple #4
0
def test_practice_ods_code_from_asid_returns_none_given_no_practices():
    practices: List[PracticeDetails] = []
    organisation_lookup = OrganisationLookup(practices, ccgs=[])

    expected = None

    actual = organisation_lookup.practice_ods_code_from_asid("123")

    assert actual == expected
Exemple #5
0
def test_ccg_ods_code_from_practice_ods_code_returns_matching_ccg():
    ccg = build_ccg_details(practices=["A123"], ods_code="12A")
    practice_lookup = OrganisationLookup(practices=[], ccgs=[ccg])

    expected = "12A"

    actual = practice_lookup.ccg_ods_code_from_practice_ods_code("A123")

    assert actual == expected
Exemple #6
0
def test_practice_ods_code_from_asid_returns_matching_practice_given_practice_with_multiple_asids(
):
    practice = build_practice_details(asids=["123", "456"], ods_code="ABC")
    organisation_lookup = OrganisationLookup(practices=[practice], ccgs=[])

    expected = "ABC"

    actual = organisation_lookup.practice_ods_code_from_asid("456")

    assert actual == expected
Exemple #7
0
def test_has_asid_code_returns_false_given_no_matching_practice():
    practices = [build_practice_details(asids=["123"])]

    organisation_lookup = OrganisationLookup(practices, ccgs=[])

    expected = False

    actual = organisation_lookup.has_asid_code("456")

    assert actual == expected
Exemple #8
0
def test_has_asid_code_returns_true_given_a_matching_practice_with_multiple_asid(
):
    practices = [build_practice_details(asids=["123", "456"])]

    organisation_lookup = OrganisationLookup(practices, ccgs=[])

    expected = True

    actual = organisation_lookup.has_asid_code("456")

    assert actual == expected
Exemple #9
0
def test_ccg_ods_code_from_practice_ods_code_returns_matching_ccg_given_multiple_ccgs(
):
    ccg = build_ccg_details(practices=["A2431"], ods_code="42C")
    practice_lookup = OrganisationLookup(
        practices=[], ccgs=[build_ccg_details(),
                            build_ccg_details(), ccg])

    expected = "42C"

    actual = practice_lookup.ccg_ods_code_from_practice_ods_code("A2431")

    assert actual == expected
Exemple #10
0
def test_ccg_ods_code_from_practice_ods_code_returns_matching_ccg_with_multiple_practices(
):
    ccg = build_ccg_details(practices=["B3432",
                                       a_string(),
                                       a_string()],
                            ods_code="3W")
    practice_lookup = OrganisationLookup(practices=[], ccgs=[ccg])

    expected = "3W"

    actual = practice_lookup.ccg_ods_code_from_practice_ods_code("B3432")

    assert actual == expected
Exemple #11
0
 def from_list(cls, datas: Iterator[Dict]):
     metadata_dict = {}
     for data in datas:
         organisation_metadata = OrganisationMetadata.from_dict(data)
         year = organisation_metadata.generated_on.year
         month = organisation_metadata.generated_on.month
         organisation_lookup = OrganisationLookup(
             organisation_metadata.practices, organisation_metadata.ccgs)
         metadata_dict[(year, month)] = organisation_lookup
     return cls(metadata_dict)
Exemple #12
0
def test_convert_two_organisation_metadata_files_to_organisation_lookup_mapping(
):
    s3_manager = Mock()

    transfer_classifier_io = TransferClassifierIO(s3_data_manager=s3_manager)

    s3_manager.read_json.side_effect = [
        _ORGANISATION_METADATA_DICT_FIRST_MONTH,
        _ORGANISATION_METADATA_DICT_ADDITIONAL_MONTH,
    ]

    actual_metadatas = transfer_classifier_io.read_ods_metadata_files(
        s3_uris=[_S3_URI, _S3_URI_ADDITIONAL_MONTH])
    expected_first_month_practices = [
        PracticeDetails(ods_code="ABC", name="A Practice", asids=["123"])
    ]
    expected_first_month_ccgs = [
        CcgDetails(ods_code="XYZ", name="A CCG", practices=["ABC"])
    ]
    expected_first_organisation_lookup = OrganisationLookup(
        expected_first_month_practices, expected_first_month_ccgs)

    actual_first_organisation_lookup = actual_metadatas.get_lookup(
        _DATE_ANCHOR_YEAR_MONTH)

    assert actual_first_organisation_lookup.practice_ods_code_from_asid(
        "123"
    ) == expected_first_organisation_lookup.practice_ods_code_from_asid("123")

    expected_second_month_practices = [
        PracticeDetails(ods_code="A12345",
                        name="GP Practice",
                        asids=["123456789123"])
    ]
    expected_second_month_ccgs = [
        CcgDetails(ods_code="22A", name="CCG", practices=["A12345"])
    ]
    expected_second_organisation_lookup = OrganisationLookup(
        expected_second_month_practices, expected_second_month_ccgs)

    actual_second_organisation_lookup = actual_metadatas.get_lookup(
        _DATE_ANCHOR_ADDITIONAL_YEAR_MONTH)

    assert actual_second_organisation_lookup.practice_ods_code_from_asid(
        "A12345"
    ) == expected_second_organisation_lookup.practice_ods_code_from_asid(
        "A12345")

    expected_s3_manager_read_json_calls = [
        call(_S3_URI), call(_S3_URI_ADDITIONAL_MONTH)
    ]
    s3_manager.read_json.assert_has_calls(expected_s3_manager_read_json_calls)
def test_from_list_of_data_returns_dict_of_organisation_metadata():
    first_month_data = {
        "generated_on":
        "2020-07-23T00:00:00",
        "practices": [{
            "ods_code": "A12345",
            "name": "GP Practice",
            "asids": ["123456789123"]
        }],
        "ccgs": [{
            "ods_code": "12A",
            "name": "CCG",
            "practices": ["A12345"]
        }],
    }
    second_month_data = {
        "generated_on":
        "2020-08-23T00:00:00",
        "practices": [{
            "ods_code": "ABC543",
            "name": "GP Practice",
            "asids": ["123456789123"]
        }],
        "ccgs": [{
            "ods_code": "22A",
            "name": "CCG",
            "practices": ["A12345"]
        }],
    }
    list_of_data = iter([first_month_data, second_month_data])

    expected_first_month_practices = [
        PracticeDetails(ods_code="A12345",
                        name="GP Practice",
                        asids=["123456789123"])
    ]
    expected_second_month_practices = [
        PracticeDetails(ods_code="ABC543",
                        name="GP Practice",
                        asids=["123456789123"])
    ]
    expected_first_month_ccgs = [
        CcgDetails(ods_code="12A", name="CCG", practices=["A12345"])
    ]
    expected_second_month_ccgs = [
        CcgDetails(ods_code="22A", name="CCG", practices=["A12345"])
    ]
    expected_first_month_lookup = OrganisationLookup(
        expected_first_month_practices, expected_first_month_ccgs)
    expected_second_month_lookup = OrganisationLookup(
        expected_second_month_practices, expected_second_month_ccgs)

    actual_metadatas = OrganisationMetadataMonthly.from_list(list_of_data)
    actual_first_month_lookup = actual_metadatas.get_lookup((2020, 7))
    actual_second_month_lookup = actual_metadatas.get_lookup((2020, 8))

    assert actual_first_month_lookup.practice_ods_code_from_asid(
        "123456789123"
    ) == expected_first_month_lookup.practice_ods_code_from_asid(
        "123456789123")
    assert actual_second_month_lookup.practice_ods_code_from_asid(
        "123456789123"
    ) == expected_second_month_lookup.practice_ods_code_from_asid(
        "123456789123")