From 534c116dae59d75b68b8c46985b4458390c632c5 Mon Sep 17 00:00:00 2001 From: Emily Michaud <59289146+emichaud998@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:17:55 -0500 Subject: [PATCH] Fix Organization validation so that it skips to the next one if there is a necessary field needed for validation missing --- .../service_base_url_validate_group.rb | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/service_base_url_test_kit/service_base_url_validate_group.rb b/lib/service_base_url_test_kit/service_base_url_validate_group.rb index 9124ebf..0fbfc94 100644 --- a/lib/service_base_url_test_kit/service_base_url_validate_group.rb +++ b/lib/service_base_url_test_kit/service_base_url_validate_group.rb @@ -128,7 +128,7 @@ def limit_bundle_entries(resource_validation_limit, bundle_resource) elsif organization_resource.partOf.present? parent_org = find_parent_organization_entry(organization_entries, organization_resource.partOf.reference) - unless resource_already_exists?(new_entries, parent_org, 'Organization') + unless parent_org.blank? || resource_already_exists?(new_entries, parent_org, 'Organization') new_entries.append(parent_org) resource_validation_limit -= 1 @@ -138,12 +138,25 @@ def limit_bundle_entries(resource_validation_limit, bundle_resource) end found_endpoint_entries.each do |found_endpoint_entry| - unless resource_already_exists?(new_entries, found_endpoint_entry, 'Endpoint') - new_entries.append(found_endpoint_entry) - resource_validation_limit -= 1 + next if resource_already_exists?(new_entries, found_endpoint_entry, 'Endpoint') + + new_entries.append(found_endpoint_entry) + + endpoint_entries.delete_if do |entry| + entry.resource.resourceType == 'Endpoint' && entry.resource.id == found_endpoint_entry.resource.id end + + resource_validation_limit -= 1 end end + + endpoint_entries.each do |endpoint_entry| + break if resource_validation_limit <= 0 + + new_entries.append(endpoint_entry) + resource_validation_limit -= 1 + end + new_entries end @@ -158,7 +171,7 @@ def find_referenced_endpoints(organization_endpoints, endpoint_entries) found_endpoint = endpoint_entries.find do |endpoint_entry| endpoint_ref.reference.include?(endpoint_entry.resource.id) end - endpoints.append(found_endpoint) + endpoints.append(found_endpoint) if found_endpoint.present? end endpoints end @@ -448,6 +461,7 @@ def resource_already_exists?(new_entries, found_resource_entry, resource_type) add_message('error', %( Organization with id: #{organization.id} does not have the endpoint or partOf field populated )) + next end parent_organization = find_parent_organization(bundle_resource, organization.partOf.reference) @@ -457,6 +471,7 @@ def resource_already_exists?(new_entries, found_resource_entry, resource_type) Organization with id: #{organization.id} references parent Organization not found in the Bundle: #{organization.partOf.reference} )) + next end if parent_organization.endpoint.empty?