private static IReadOnlyCollection <string> GetResourceIdsForCompartmentType(CompartmentType compartmentType, CompartmentIndices compartmentIndices) { IReadOnlyCollection <string> resourceIds = null; if (compartmentType == CompartmentType.Device) { resourceIds = compartmentIndices.DeviceCompartmentEntry; } else if (compartmentType == CompartmentType.Encounter) { resourceIds = compartmentIndices.EncounterCompartmentEntry; } else if (compartmentType == CompartmentType.Patient) { resourceIds = compartmentIndices.PatientCompartmentEntry; } else if (compartmentType == CompartmentType.Practitioner) { resourceIds = compartmentIndices.PractitionerCompartmentEntry; } else if (compartmentType == CompartmentType.RelatedPerson) { resourceIds = compartmentIndices.RelatedPersonCompartmentEntry; } return(resourceIds); }
public bool TryGetResourceTypes(CompartmentType compartmentType, out HashSet <string> resourceTypes) { if (_compartmentResourceTypesLookup.TryGetValue(compartmentType, out resourceTypes)) { return(true); } resourceTypes = null; return(false); }
public bool TryGetSearchParams(string resourceType, CompartmentType compartmentType, out HashSet <string> searchParams) { if (_compartmentSearchParamsLookup.TryGetValue(resourceType, out Dictionary <CompartmentType, HashSet <string> > compartmentSearchParams) && compartmentSearchParams.TryGetValue(compartmentType, out searchParams)) { return(true); } searchParams = null; return(false); }
private static Dictionary <CompartmentType, (CompartmentType, Uri, IList <(string, IList <string>)>)> ValidateAndGetCompartmentDict(BundleWrapper bundle) { EnsureArg.IsNotNull(bundle, nameof(bundle)); var issues = new List <OperationOutcomeIssue>(); var validatedCompartments = new Dictionary <CompartmentType, (CompartmentType, Uri, IList <(string, IList <string>)>)>(); IReadOnlyList <BundleEntryWrapper> entries = bundle.Entries; for (int entryIndex = 0; entryIndex < entries.Count; entryIndex++) { // Make sure resources are not null and they are Compartment. BundleEntryWrapper entry = entries[entryIndex]; var compartment = entry.Resource; if (compartment == null || !string.Equals(KnownResourceTypes.CompartmentDefinition, compartment.InstanceType, StringComparison.Ordinal)) { AddIssue(Core.Resources.CompartmentDefinitionInvalidResource, entryIndex); continue; } string code = compartment.Scalar("code")?.ToString(); string url = compartment.Scalar("url")?.ToString(); if (code == null) { AddIssue(Core.Resources.CompartmentDefinitionInvalidCompartmentType, entryIndex); continue; } CompartmentType typeCode = EnumUtility.ParseLiteral <CompartmentType>(code).GetValueOrDefault(); if (validatedCompartments.ContainsKey(typeCode)) { AddIssue(Core.Resources.CompartmentDefinitionIsDupe, entryIndex); continue; } if (string.IsNullOrWhiteSpace(url) || !Uri.IsWellFormedUriString(url, UriKind.Absolute)) { AddIssue(Core.Resources.CompartmentDefinitionInvalidUrl, entryIndex); continue; } var resources = compartment.Select("resource") .Select(x => (x.Scalar("code")?.ToString(), (IList <string>)x.Select("param").AsStringValues().ToList())) .ToList(); var resourceNames = resources.Select(x => x.Item1).ToArray(); if (resourceNames.Length != resourceNames.Distinct().Count()) { AddIssue(Core.Resources.CompartmentDefinitionDupeResource, entryIndex); continue; } validatedCompartments.Add( typeCode, (typeCode, new Uri(url), new List <(string, IList <string>)>(resources))); } if (issues.Count != 0) { throw new InvalidDefinitionException( Core.Resources.CompartmentDefinitionContainsInvalidEntry, issues.ToArray()); } return(validatedCompartments); void AddIssue(string format, params object[] args) { issues.Add(new OperationOutcomeIssue( OperationOutcomeConstants.IssueSeverity.Fatal, OperationOutcomeConstants.IssueType.Invalid, string.Format(CultureInfo.InvariantCulture, format, args))); } }
public void GivenSearchIndicesWithResourceTypeAndCompartmentTypeAndNullReferenceSearchResourceType_WhenExtracted_ThenNoIndicesExtracted(ResourceType resourceType, CompartmentType compartmentType, ReferenceKind referenceKind, string expectedResourceId) { HashSet <string> compParams = null; _compartmentManager.TryGetSearchParams(resourceType.ToString(), compartmentType, out compParams) .Returns(x => { x[2] = new HashSet <string> { _referenceSearchTestParam.Name }; return(true); }); var searchIndexEntries = new List <SearchIndexEntry> { new SearchIndexEntry(_referenceSearchTestParam, new ReferenceSearchValue(referenceKind, null, null, expectedResourceId)), }; CompartmentIndices compartmentIndices = _compartmentIndexer.Extract(resourceType.ToString(), searchIndexEntries); Assert.Null(GetResourceIdsForCompartmentType(compartmentType, compartmentIndices)); }
public void GivenSearchIndicesWithResourceTypeAndCompartmentType_WhenExtracted_ThenCorrectIndicesExtracted(ResourceType resourceType, CompartmentType compartmentType, ReferenceKind referenceKind, string expectedResourceId) { HashSet <string> compParams = null; _compartmentManager.TryGetSearchParams(resourceType.ToString(), compartmentType, out compParams) .Returns(x => { x[2] = new HashSet <string> { _referenceSearchTestParam.Name, _nonReferenceReferenceSearchTestParam.Name }; return(true); }); var searchIndexEntries = new List <SearchIndexEntry> { new SearchIndexEntry(_referenceSearchTestParam, new ReferenceSearchValue(referenceKind, _baseUri, CompartmentDefinitionManager.CompartmentTypeToResourceType(compartmentType.ToString()).ToString(), expectedResourceId)), new SearchIndexEntry(_nonReferenceReferenceSearchTestParam, new StringSearchValue("aadsdas")), }; CompartmentIndices compartmentIndices = _compartmentIndexer.Extract(resourceType.ToString(), searchIndexEntries); Assert.Collection(GetResourceIdsForCompartmentType(compartmentType, compartmentIndices), r => string.Equals(expectedResourceId, r, StringComparison.OrdinalIgnoreCase)); }
public void GivenSearchIndicesWithMultipleReferenceSearchParams_WhenExtracted_ThenCorrectIndicesExtracted(CompartmentType expectedCompartmentType1, CompartmentType expectedCompartmentType2, CompartmentType expectedCompartmentType3) { HashSet <string> compParams = null; string expectedCareTeamResource = ResourceType.CareTeam.ToString(); // Setup the compartment search definitions. _compartmentManager.TryGetSearchParams(expectedCareTeamResource, expectedCompartmentType1, out compParams) .Returns(x => { x[2] = new HashSet <string> { _referenceSearchTestParam.Name }; return(true); }); _compartmentManager.TryGetSearchParams(expectedCareTeamResource, expectedCompartmentType2, out compParams) .Returns(x => { x[2] = new HashSet <string> { _anotherReferenceSearchTestParam.Name }; return(true); }); _compartmentManager.TryGetSearchParams(expectedCareTeamResource, expectedCompartmentType3, out compParams) .Returns(x => { x[2] = new HashSet <string> { _yetAnotherReferenceSearchTestParam.Name }; return(true); }); const string ExpectedResourceIdR1 = "r1"; const string ExpectedResourceIdR2 = "r2"; const string ExpectedResourceIdR3 = "r3"; // Setup multiple reference search parameters with expected resource ids for the compartments. var searchIndexEntries = new List <SearchIndexEntry> { new SearchIndexEntry(_referenceSearchTestParam, new ReferenceSearchValue(ReferenceKind.InternalOrExternal, _baseUri, CompartmentDefinitionManager.CompartmentTypeToResourceType(expectedCompartmentType1.ToString()).ToString(), ExpectedResourceIdR1)), new SearchIndexEntry(_anotherReferenceSearchTestParam, new ReferenceSearchValue(ReferenceKind.Internal, _baseUri, CompartmentDefinitionManager.CompartmentTypeToResourceType(expectedCompartmentType2.ToString()).ToString(), ExpectedResourceIdR2)), new SearchIndexEntry(_yetAnotherReferenceSearchTestParam, new ReferenceSearchValue(ReferenceKind.External, _baseUri, CompartmentDefinitionManager.CompartmentTypeToResourceType(expectedCompartmentType3.ToString()).ToString(), ExpectedResourceIdR3)), }; CompartmentIndices compartmentIndices = _compartmentIndexer.Extract(expectedCareTeamResource, searchIndexEntries); Assert.Collection(GetResourceIdsForCompartmentType(expectedCompartmentType1, compartmentIndices), r => string.Equals(ExpectedResourceIdR1, r, StringComparison.OrdinalIgnoreCase)); Assert.Collection(GetResourceIdsForCompartmentType(expectedCompartmentType2, compartmentIndices), r => string.Equals(ExpectedResourceIdR2, r, StringComparison.OrdinalIgnoreCase)); Assert.Collection(GetResourceIdsForCompartmentType(expectedCompartmentType3, compartmentIndices), r => string.Equals(ExpectedResourceIdR3, r, StringComparison.OrdinalIgnoreCase)); }
public void GivenAValidCompartmentDefinitionBundle_WhenValidated_ThenValidSearchParams(ResourceType resourceType, CompartmentType compartmentType, int testCount) { Assert.True(_validBuiltCompartment.TryGetSearchParams(resourceType.ToString(), compartmentType, out HashSet <string> searchParams)); Assert.Equal(testCount, searchParams.Count); }
public void GivenAValidCompartmentDefinitionBundle_WhenValidated_ThenValidResourceTypes(CompartmentType compartmentType) { Assert.True(_validBuiltCompartment.TryGetResourceTypes(compartmentType, out HashSet <string> resourceTypes)); Assert.True(resourceTypes.Count > 0); }