def get_fhir_organisations(request, format, request_id):
    log_utils.log_layer_entry(constants.SERVICE, request_id )

    request_args = ImmutableMultiDict.copy(request.args)

    limit, page = get_pagination_parameters(request_args)

    ods_codes_dict, total_record_count, returned_record_count = model_entry.get_fhir_ods_codes(
        request_args, page, limit, request_id)

    list_of_org_dicts = []
    for ods_code in ods_codes_dict:
        org, address, role, contact, relationship, successor = model_entry.get_org_data(ods_code['odscode'], request_id,
                                                                                        is_fhir=True)
        org_dict = service_utils.build_org(org, address, role, contact, relationship, successor, is_fhir=True)
        list_of_org_dicts.append(org_dict)

    structured_bundle_dict = translation_entry.structure_fhir_organisations_bundle(list_of_org_dicts,
                                                                                   total_record_count, limit, page,
                                                                                   request, request_id)

    response_body = serialisation_entry.create_response_body(structured_bundle_dict, format, request_id, is_fhir=True)

    log_utils.log_layer_exit(constants.SERVICE, request_id)

    return response_body, returned_record_count, total_record_count
Beispiel #2
0
def structure_ord_org_summary(orgs, app_hostname, request_id):
    log_utils.log_layer_entry(constants.TRANSLATION, request_id)

    organisations = list()
    org_dict = {}

    try:
        for organisation in orgs:

            organisation = utils_translation.remove_none_values_from_dictionary(
                organisation)

            organisation['Name'] = organisation.pop('name')
            organisation['OrgId'] = organisation.pop('odscode')
            organisation['Status'] = organisation.pop('status')
            organisation['OrgRecordClass'] = organisation.pop('record_class')
            if 'post_code' in organisation:
                organisation['PostCode'] = organisation.pop('post_code')
            organisation['LastChangeDate'] = organisation.pop('last_changed')
            organisation['PrimaryRoleId'] = organisation.pop('code')
            organisation['PrimaryRoleDescription'] = organisation.pop(
                'displayname')

            link = str.format('{0}/{1}', app_hostname, organisation['OrgId'])

            organisation['OrgLink'] = link

            organisations.append(organisation)

        org_dict['Organisations'] = organisations
    except KeyError:
        raise exception.InvalidDataError

    log_utils.log_layer_exit(constants.TRANSLATION, request_id)
    return org_dict
Beispiel #3
0
def structure_fhir_organisations_bundle(orgs, count, limit, page, request,
                                        request_id):
    log_utils.log_layer_entry(constants.TRANSLATION, request_id)

    link_list = []

    if int(float(limit)) > 0:
        link_list = utils_translation.create_link_list(request, count, page,
                                                       limit)
    bundle_dict = {}
    bundle_dict['resourceType'] = "Bundle"
    bundle_dict['id'] = str(uuid.uuid4())
    bundle_dict['meta'] = {
        "lastUpdated":
        datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S") + "+00:00"
    }
    bundle_dict['type'] = constants.FHIR_BUNDLE_SEARCHSET
    bundle_dict['total'] = str(count)
    if int(float(limit)) > 0:
        bundle_dict['link'] = link_list
        bundle_dict['entry'] = create_entry_list(orgs, request.base_url,
                                                 request.url_root)

    log_utils.log_layer_exit(constants.TRANSLATION, request_id)

    return bundle_dict
Beispiel #4
0
def structure_fhir_rolesystem(rolecode_dicts_list, format, request_url,
                              request_id):
    log_utils.log_layer_entry(constants.TRANSLATION, request_id)

    master_dict = collections.OrderedDict()

    if format == constants.JSON:
        master_dict["resourceType"] = "CodeSystem"

    master_dict["url"] = request_url
    master_dict["version"] = constants.FHIR_ROLES_VERSION
    master_dict["name"] = constants.FHIR_ROLES_ENDPOINT_NAME
    master_dict["status"] = constants.FHIR_ROLES_ENDPOINT_STATUS
    master_dict["date"] = "date_placeholder"
    master_dict["publisher"] = constants.FHIR_ROLES_ENDPOINT_PUBLISHER
    master_dict["contact"] = codesystem_translation.create_contact_list()
    master_dict["description"] = constants.FHIR_ROLES_ENDPOINT_DESCRIPTION
    master_dict["copyright"] = constants.FHIR_ROLES_ENDPOINT_COPYRIGHT
    master_dict["content"] = constants.FHIR_ROLES_ENDPOINT_CONTENT
    master_dict[
        "concept"] = codesystem_translation.create_rolecodes_list_for_response_dictionary(
            rolecode_dicts_list)

    log_utils.log_layer_exit(constants.TRANSLATION, request_id)

    return master_dict
Beispiel #5
0
def structure_org(org_dict, url_root, request_id, is_fhir):
    log_utils.log_layer_entry(constants.TRANSLATION, request_id)

    if is_fhir:
        org_result = restructure_fhir_org(org_dict, url_root)
    else:
        org_result = restructure_ord_org(org_dict)

    log_utils.log_layer_exit(constants.TRANSLATION, request_id)

    return org_result
def get_fhir_capabilities(format, request_url, request_id):
    log_utils.log_layer_entry(constants.SERVICE, request_id )

    if format == constants.JSON:
        response_body = JSON % (request_url, "1.1.0")

    else:
        response_body = XML % (request_url, "1.1.0")

    log_utils.log_layer_exit(constants.SERVICE, request_id)

    return response_body
def create_response_body(org_dict, format, request_id, is_fhir):
    log_utils.log_layer_entry(constants.SERIALISATION, request_id)


    if is_fhir:
        response_body =  fhir_format(org_dict, request_id, format)

    else:
        response_body = ord_format(org_dict, request_id, format) if org_dict else None

    log_utils.log_layer_exit(constants.SERIALISATION, request_id)

    return response_body
Beispiel #8
0
def get_fhir_roles(request_id, format, request_url):
    log_utils.log_layer_entry(constants.SERVICE, request_id )

    organisation_roles_dict = model_entry.get_fhir_roles_codesystem(request_id)

    structred_organisation_roles_dict = translation_entry.structure_fhir_rolesystem(organisation_roles_dict, format,
                                                                                    request_url, request_id)

    response_body = serialisation_entry.create_response_body(structred_organisation_roles_dict, format, request_id, is_fhir=True)

    log_utils.log_layer_exit(constants.SERVICE, request_id)

    return response_body
def get_ord_organisations_summary(request, format, app_hostname, request_id):
    log_utils.log_layer_entry(constants.SERVICE, request_id)

    limit, offset = set_ord_offset_and_limit(request.args)

    orgs_summary_dict, total_record_count, returned_record_count = model_entry.get_ord_orgs_summary(
        request.args, limit, offset, request_id)

    structured_orgs_summary_dict = translation_entry.structure_ord_org_summary(
        orgs_summary_dict, app_hostname, request_id)

    response_body = serialisation_entry.create_response_body(
        structured_orgs_summary_dict, format, request_id, is_fhir=False)

    log_utils.log_layer_exit(constants.SERVICE, request_id)

    return response_body, returned_record_count, total_record_count
Beispiel #10
0
def get_single_organisation(ods_code, format, url_root, request_id, is_fhir):
    log_utils.log_layer_entry(constants.SERVICE, request_id)

    org, address, role, contact, relationship, successor = model_entry.get_org_data(
        ods_code, request_id, is_fhir)

    org_dict = service_utils.build_org(org, address, role, contact,
                                       relationship, successor, is_fhir)

    structured_org_dict = translation_entry.structure_org(
        org_dict, url_root, request_id, is_fhir)

    response_body = serialisation_entry.create_response_body(
        structured_org_dict, format, request_id, is_fhir)

    log_utils.log_layer_exit(constants.SERVICE, request_id)

    return response_body
Beispiel #11
0
def get_ord_organisations_changed_since(request_args, format, app_hostname,
                                        request_id):
    log_utils.log_layer_entry(constants.SERVICE, request_id)

    request_args = ImmutableMultiDict.copy(request_args)

    ods_codes = model_entry.get_ord_ods_codes_last_changed_since(
        request_args, request_id)

    total_record_count = len(ods_codes)

    structured_last_changed_since_summary = translation_entry.build_ord_last_changed_summary(
        ods_codes, format, app_hostname)

    response_body = serialisation_entry.create_response_body(
        structured_last_changed_since_summary,
        format,
        request_id,
        is_fhir=False)

    log_utils.log_layer_exit(constants.SERVICE, request_id)

    return response_body, total_record_count