// Test 299 - doStrongIdentifiers - Look for resource instances with out strong identifiers // REFACTORED: // - switched to $utilGetAllSampledResourceFilenames to get full list of sampled resource filenames // - extracting resource type and id from the filename instead of reading all files // TODO: // - split into smaller maps, there's too much going on here // - the practice of mutating a staging file instead of writing to separate (per step) files is BAD ( // function that tests if a string (a system) is from a relevant domain // (list of domain provided in the .env) or UUID $isLocalUri := function($system) { $system = 'urn:ietf:rfc:3986' or ($strongIdentifierSystems[$contains(($exists($system) and $system!='' and $type($system)="string")?$system:'', $)] ~> $count()) >0 }; // Read all master-data and sampled resource identifiers, // check for strong identifiers and save to a single file $masterDataIdentifiers := $readFile('identifiers_master-data.json'); $masterDataIdentifiersWithStrongInd := $masterDataIdentifiers .$merge([$, {'isStrongSystem': $isLocalUri(system)}]); $sampledIdentifiers := $readFile('identifiers_sampled-data.json'); $sampledIdentifiersWithStrongInd := $sampledIdentifiers .$merge([$, {'isStrongSystem': $isLocalUri(system)}]); $writeFile( [$masterDataIdentifiersWithStrongInd, $sampledIdentifiersWithStrongInd], 'identifiers_master-data_with-strong-ind.json'); // Filter only identifiers from org provided domains, merge duplicate identifiers in the same resource (distinct) $identifiersDistinct := $readFile('identifiers_master-data_with-strong-ind.json') [isStrongSystem=true] .{ "resourceType": resourceType, "resourceId" : resourceId, "system": system, "value": value } ~> $distinct(); // Aggregate (count) to resourceType & resourceId level $identifiersCount := $identifiersDistinct{(resourceType & '|' & system & '|' & value): $count($)}; // List duplicate identifiers & attributes ( $identifiersDistinct.$merge( [ $, { "count": $lookup( $identifiersCount, ( resourceType & '|' & system & '|' & value ) ) } ] ){ resourceType & '|' & system & '|' & value: { "system": $distinct(system), "value": $distinct(value), "resourceType": $distinct(resourceType), "resourceId" : [resourceId] } } ).* ~> $writeFile('identifiers-candidate-strong.json'); // List all Resource.id's $allRsourceIds := $utilGetAllSampledResourceFilenames($readDir()) .{ "resourceType": $substringBefore($substring($, 1), ']_['), "id": $substringAfter(']_[').$substringBefore('].json') }; // List Resource.id's with a strong identifier $instancesWithStrongIdentifier := $readFile('identifiers-candidate-strong.json') [$count(resourceId) = 1] // filter only strong identifiers .{ "resourceType": resourceType, "id":resourceId[0] }; // list instances NOT found in the strong identifiers list $instancesWoStrongIdentifier := $allRsourceIds [ $not($.(resourceType & id) in $instancesWithStrongIdentifier.(resourceType & id)) ]; $instancesWoStrongIdentifier ~> $writeFile('instancesWoStrongIdentifier.json'); // Create a subset file for reporting in the /report of the certificator (cant implement this logic in the "data" element in src\helpers\expressions.ts) // TODO: clarify the previous comment $total := $instancesWoStrongIdentifier ~> $count(); $increment := $total/25 ~> $round(); $instancesWoStrongIdentifier[[0..$total][($ % $increment) = 0]] /*select every 25th element in from the result*/ ~> $writeFile('instancesWoStrongIdentifierReport.json') )