|
|
@ -5,20 +5,18 @@ module Imports |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def create_scheme(xml_document) |
|
|
|
def create_scheme(xml_document) |
|
|
|
old_id = string_or_nil(xml_document, "id") |
|
|
|
attributes = scheme_attributes(xml_document) |
|
|
|
status = string_or_nil(xml_document, "status") |
|
|
|
if attributes["status"] == "Approved" |
|
|
|
|
|
|
|
|
|
|
|
if status == "Approved" |
|
|
|
|
|
|
|
Scheme.create!( |
|
|
|
Scheme.create!( |
|
|
|
owning_organisation_id: find_owning_organisation_id(xml_document), |
|
|
|
owning_organisation_id: attributes["owning_organisation_id"], |
|
|
|
managing_organisation_id: find_managing_organisation_id(xml_document), |
|
|
|
managing_organisation_id: attributes["managing_organisation_id"], |
|
|
|
service_name: string_or_nil(xml_document, "name"), |
|
|
|
service_name: attributes["service_name"], |
|
|
|
arrangement_type: string_or_nil(xml_document, "arrangement_type"), |
|
|
|
arrangement_type: attributes["arrangement_type"], |
|
|
|
old_id:, |
|
|
|
old_id: attributes["old_id"], |
|
|
|
old_visible_id: safe_string_as_integer(xml_document, "visible-id"), |
|
|
|
old_visible_id: attributes["old_visible_id"], |
|
|
|
) |
|
|
|
) |
|
|
|
else |
|
|
|
else |
|
|
|
@logger.warn("Scheme with legacy ID #{old_id} is not approved (#{status}), skipping") |
|
|
|
@logger.warn("Scheme with legacy ID #{attributes['old_id']} is not approved (#{attributes['status']}), skipping") |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -39,16 +37,33 @@ module Imports |
|
|
|
Integer(str, exception: false) |
|
|
|
Integer(str, exception: false) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def find_owning_organisation_id(xml_doc) |
|
|
|
def scheme_attributes(xml_doc) |
|
|
|
old_org_id = string_or_nil(xml_doc, "institution") |
|
|
|
attributes = {} |
|
|
|
|
|
|
|
attributes["old_id"] = string_or_nil(xml_doc, "id") |
|
|
|
|
|
|
|
attributes["old_visible_id"] = string_or_nil(xml_doc, "visible-id") |
|
|
|
|
|
|
|
attributes["status"] = string_or_nil(xml_doc, "status") |
|
|
|
|
|
|
|
attributes["service_name"] = string_or_nil(xml_doc, "name") |
|
|
|
|
|
|
|
attributes["arrangement_type"] = string_or_nil(xml_doc, "arrangement_type") |
|
|
|
|
|
|
|
attributes["owning_org_old_id"] = string_or_nil(xml_doc, "institution") |
|
|
|
|
|
|
|
attributes["owning_organisation_id"] = find_owning_organisation_id(attributes["owning_org_old_id"]) |
|
|
|
|
|
|
|
attributes["management_org_old_visible_id"] = safe_string_as_integer(xml_doc, "agent") |
|
|
|
|
|
|
|
attributes["managing_organisation_id"] = find_managing_organisation_id(attributes["management_org_old_visible_id"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if attributes["arrangement_type"] == "D" && attributes["managing_organisation_id"].nil? |
|
|
|
|
|
|
|
attributes["managing_organisation_id"] = attributes["owning_organisation_id"] |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attributes |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_owning_organisation_id(old_org_id) |
|
|
|
organisation = Organisation.find_by(old_org_id:) |
|
|
|
organisation = Organisation.find_by(old_org_id:) |
|
|
|
raise "Organisation not found with legacy ID #{old_org_id}" if organisation.nil? |
|
|
|
raise "Organisation not found with legacy ID #{old_org_id}" if organisation.nil? |
|
|
|
|
|
|
|
|
|
|
|
organisation.id |
|
|
|
organisation.id |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def find_managing_organisation_id(xml_doc) |
|
|
|
def find_managing_organisation_id(old_visible_id) |
|
|
|
old_visible_id = safe_string_as_integer(xml_doc, "agent") |
|
|
|
|
|
|
|
return unless old_visible_id |
|
|
|
return unless old_visible_id |
|
|
|
|
|
|
|
|
|
|
|
organisation = Organisation.find_by(old_visible_id:) |
|
|
|
organisation = Organisation.find_by(old_visible_id:) |
|
|
|