public NrlsMaintain(IOptionsSnapshot <ApiSetting> nrlsApiSetting, IFhirMaintain fhirMaintain, IFhirSearch fhirSearch, ISdsService sdsService, IFhirValidation fhirValidation) : base(nrlsApiSetting, "NrlsApiSetting") { _fhirMaintain = fhirMaintain; _sdsService = sdsService; _fhirSearch = fhirSearch; _fhirValidation = fhirValidation; }
public NrlsMaintain(IOptionsSnapshot <ApiSetting> nrlsApiSetting, IFhirMaintain fhirMaintain, IFhirSearch fhirSearch, IMemoryCache memoryCache, IFhirValidation fhirValidation) : base(nrlsApiSetting, "NrlsApiSetting") { _fhirMaintain = fhirMaintain; _cache = memoryCache; _fhirSearch = fhirSearch; _fhirValidation = fhirValidation; }
public void Dispose() { _nrlsApiSettings = null; _fhirMaintain = null; _fhirSearch = null; _fhirValidation = null; _cache = null; }
public void Dispose() { _fhirValidation = null; _fhirSearch = null; _nrlsApiSettings = null; _expectedBundle = null; _cache = null; }
public NrlsMaintainTests() { var opts = AppSettings.NrlsApiSettings; var settingsMock = new Mock <IOptionsSnapshot <NrlsApiSetting> >(); settingsMock.Setup(op => op.Get(It.IsAny <string>())).Returns(opts); var searchOrgList = new List <Organization> { FhirOrganizations.Valid_Organization }; var searchOrgBundle = FhirBundle.GetBundle <Organization>(searchOrgList); var emptySearchBundle = FhirBundle.GetBundle <Organization>(new List <Organization>()); var searchDocBundle = FhirBundle.GetBundle <DocumentReference>(new List <DocumentReference> { NrlsPointers.Valid_With_Alt_Custodian }); var searchDocAltBundle = FhirBundle.GetBundle <DocumentReference>(new List <DocumentReference> { NrlsPointers.Valid_With_Alt2_Custodian }); var searchDocAltInvalidBundle = FhirBundle.GetBundle <DocumentReference>(new List <DocumentReference> { NrlsPointers.Valid_AltCust_With_MasterId_and_RelatesTo_BadStatus }); var searchDocEmptyBundle = FhirBundle.GetBundle <DocumentReference>(new List <DocumentReference>()); var searchMock = new Mock <IFhirSearch>(); searchMock.Setup(op => op.Find <Organization>(It.Is <FhirRequest>(request => request.RequestingAsid == "000"))).Returns(SystemTasks.Task.Run(() => searchOrgBundle as Resource)); searchMock.Setup(op => op.Find <Organization>(It.Is <FhirRequest>(request => request.RequestingAsid == "001"))).Returns(SystemTasks.Task.Run(() => searchOrgBundle as Resource)); searchMock.Setup(op => op.Find <Organization>(It.Is <FhirRequest>(request => request.RequestingAsid == "002"))).Returns(SystemTasks.Task.Run(() => emptySearchBundle as Resource)); searchMock.Setup(op => op.Find <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "000"))).Returns(SystemTasks.Task.Run(() => searchDocBundle as Resource)); searchMock.Setup(op => op.Find <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "001"))).Returns(SystemTasks.Task.Run(() => searchDocAltBundle as Resource)); searchMock.Setup(op => op.Find <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "002"))).Returns(SystemTasks.Task.Run(() => searchDocEmptyBundle as Resource)); searchMock.Setup(op => op.Find <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "003"))).Returns(SystemTasks.Task.Run(() => searchDocAltInvalidBundle as Resource)); searchMock.Setup(op => op.Get <DocumentReference>(It.IsAny <FhirRequest>())).Returns(SystemTasks.Task.Run(() => searchDocBundle as Resource)); //searchMock.Setup(op => op.GetByMasterId<DocumentReference>(It.Is<FhirRequest>(request => (request.Resource as DocumentReference).MasterIdentifier.Value == "testValueForMaintTest"))).Returns(SystemTasks.Task.Run(() => searchDocBundle as Resource)); searchMock.Setup(op => op.GetByMasterId <DocumentReference>(It.IsAny <FhirRequest>())).Returns(SystemTasks.Task.Run(() => searchDocBundle as Resource)); var maintMock = new Mock <IFhirMaintain>(); maintMock.Setup(op => op.Create <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "000"))).Returns(SystemTasks.Task.Run(() => NrlsPointers.Valid as Resource)); maintMock.Setup(op => op.Create <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "002"))).Returns(SystemTasks.Task.Run(() => null as Resource)); maintMock.Setup(op => op.CreateWithUpdate <DocumentReference>(It.IsAny <FhirRequest>(), It.Is <FhirRequest>(request => request.Id == "5ab13f41957d0ad5d93a1339"), It.IsAny <UpdateDefinition <BsonDocument> >())).Returns(SystemTasks.Task.Run(() => (created: NrlsPointers.Valid as Resource, updated: true))); maintMock.Setup(op => op.CreateWithUpdate <DocumentReference>(It.IsAny <FhirRequest>(), It.Is <FhirRequest>(request => request.Id == "5ab13f41957d0ad5d93a1338"), It.IsAny <UpdateDefinition <BsonDocument> >())).Returns(SystemTasks.Task.Run(() => (created: null as Resource, updated: true))); maintMock.Setup(op => op.CreateWithUpdate <DocumentReference>(It.IsAny <FhirRequest>(), It.Is <FhirRequest>(request => request.Id == "5ab13f41957d0ad5d93a1337"), It.IsAny <UpdateDefinition <BsonDocument> >())).Returns(SystemTasks.Task.Run(() => (created: NrlsPointers.Valid as Resource, updated: false))); maintMock.Setup(op => op.CreateWithUpdate <DocumentReference>(It.IsAny <FhirRequest>(), It.Is <FhirRequest>(request => request.Id == "5ab13f41957d0ad5d93a1336"), It.IsAny <UpdateDefinition <BsonDocument> >())).ThrowsAsync(new HttpFhirException()); maintMock.Setup(op => op.Delete <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "003"))).Returns(SystemTasks.Task.Run(() => true)); maintMock.Setup(op => op.Delete <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "001"))).Returns(SystemTasks.Task.Run(() => false)); maintMock.Setup(op => op.DeleteConditional <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "003"))).Returns(SystemTasks.Task.Run(() => true)); maintMock.Setup(op => op.DeleteConditional <DocumentReference>(It.Is <FhirRequest>(request => request.RequestingAsid == "001"))).Returns(SystemTasks.Task.Run(() => false)); var validationMock = new Mock <IFhirValidation>(); validationMock.Setup(op => op.ValidPointer(It.Is <DocumentReference>(pointer => pointer.Id == "5ab13f41957d0ad5d93a1339"))).Returns(OperationOutcomes.Ok); validationMock.Setup(op => op.ValidPointer(It.Is <DocumentReference>(pointer => pointer.Id == "5affc72bcae33eb8690e5881"))).Returns(OperationOutcomes.Error); validationMock.Setup(op => op.GetOrganizationReferenceId(It.IsAny <ResourceReference>())).Returns("TestOrgCode"); validationMock.Setup(op => op.GetOrganizationReferenceId(It.Is <ResourceReference>(reference => reference.Reference == "https://directory.spineservices.nhs.uk/STU3/Organization/1XR"))).Returns("TestOrgCode"); validationMock.Setup(op => op.GetOrganizationReferenceId(It.Is <ResourceReference>(reference => reference.Reference == "https://directory.spineservices.nhs.uk/STU3/Organization/error"))).Returns("TestOrgCode2"); validationMock.Setup(op => op.GetOrganizationReferenceId(It.Is <ResourceReference>(reference => reference.Reference == "https://directory.spineservices.nhs.uk/STU3/Organization/RV99"))).Returns("RV99"); validationMock.Setup(op => op.GetOrganizationReferenceId(It.Is <ResourceReference>(reference => reference.Reference == "https://directory.spineservices.nhs.uk/STU3/Organization/RV88"))).Returns("RV88"); validationMock.Setup(op => op.ValidateIdentifierParameter(It.IsAny <string>(), It.IsAny <string>())).Returns(OperationOutcomes.Error); validationMock.Setup(op => op.ValidateIdentifierParameter(It.IsAny <string>(), It.Is <string>(p => p == "testsystem|testvalue"))).Returns(delegate { return(null); }); validationMock.Setup(op => op.ValidatePatientParameter(It.IsAny <string>())).Returns(OperationOutcomes.Error); validationMock.Setup(op => op.ValidatePatientParameter(It.Is <string>(p => p == "https://demographics.spineservices.nhs.uk/STU3/Patient/2686033207"))).Returns(delegate { return(null); }); validationMock.Setup(op => op.GetValidRelatesTo(It.Is <IList <DocumentReference.RelatesToComponent> >(r => r.FirstOrDefault(w => w.Target != null && w.Target.Identifier != null && w.Target.Identifier.Value == "urn:tag:humber.nhs.uk,2004:cdc:600009612669") != null))).Returns((FhirResources.Valid_Single_RelatesTo, "relatesTo")); validationMock.Setup(op => op.GetValidStatus(It.IsAny <DocumentReferenceStatus>())).Returns(delegate { return(null); }); validationMock.Setup(op => op.GetValidStatus(It.Is <DocumentReferenceStatus>(x => x == DocumentReferenceStatus.Current))).Returns(DocumentReferenceStatus.Current); validationMock.Setup(op => op.GetSubjectReferenceId(It.IsAny <ResourceReference>())).Returns("2686033207"); var clientMapCache = new ClientAsidMap { ClientAsids = new Dictionary <string, ClientAsid>() { { "000", new ClientAsid { Interactions = new List <string>(), OrgCode = "TestOrgCode", Thumbprint = "TestThumbprint" } }, { "002", new ClientAsid { Interactions = new List <string>(), OrgCode = "TestOrgCode2", Thumbprint = "TestThumbprint" } }, { "003", new ClientAsid { Interactions = new List <string>(), OrgCode = "RV99", Thumbprint = "TestThumbprint" } } } }; var cacheMock = MemoryCacheStub.MockMemoryCacheService.GetMemoryCache(clientMapCache); _nrlsApiSettings = settingsMock.Object; _fhirMaintain = maintMock.Object; _fhirSearch = searchMock.Object; _fhirValidation = validationMock.Object; _cache = cacheMock; }
public NrlsSearch(IOptionsSnapshot <ApiSetting> apiSetting, IFhirSearch fhirSearch, ISdsService sdsService, IFhirValidation fhirValidation) : base(apiSetting, "NrlsApiSetting") { _fhirSearch = fhirSearch; _sdsService = sdsService; _fhirValidation = fhirValidation; }
public NrlsSearchTests() { var validationMock = new Mock <IFhirValidation>(); validationMock.Setup(op => op.ValidatePatientParameter(It.IsAny <string>())).Returns(delegate { return(null); }); validationMock.Setup(op => op.ValidateCustodianParameter(It.IsAny <string>())).Returns(delegate { return(null); }); validationMock.Setup(op => op.ValidateCustodianIdentifierParameter(It.IsAny <string>())).Returns(delegate { return(null); }); validationMock.Setup(op => op.ValidSummaryParameter(It.Is <string>(p => p == "notcount"))).Returns(delegate { return(new OperationOutcome()); }); validationMock.Setup(op => op.ValidSummaryParameter(It.Is <string>(p => p == "count"))).Returns(delegate { return(null); }); validationMock.Setup(op => op.GetOrganizationParameterId(It.Is <string>(p => p == "https://directory.spineservices.nhs.uk/STU3/Organization/TestOrgCode"))).Returns("TestOrgCode"); validationMock.Setup(op => op.GetOrganizationParameterIdentifierId(It.Is <string>(p => p == "https://fhir.nhs.uk/Id/ods-organization-code|TestOrgCode"))).Returns("TestOrgCode"); _fhirValidation = validationMock.Object; var searchPointer = NrlsPointers.Valid; var searchPointerList = new List <DocumentReference> { searchPointer }; var searchBundle = FhirBundle.GetBundle <DocumentReference>(searchPointerList); var searchMock = new Mock <IFhirSearch>(); searchMock.Setup(op => op.Get <DocumentReference>(It.IsAny <FhirRequest>())).Returns(SystemTasks.Task.Run(() => searchBundle as Resource)); searchMock.Setup(op => op.Find <DocumentReference>(It.IsAny <FhirRequest>())).Returns(SystemTasks.Task.Run(() => searchBundle as Resource)); var orgSearchBundle = FhirBundle.GetBundle <Organization>(new List <Organization> { FhirOrganizations.Valid_Organization }); searchMock.Setup(op => op.Find <Organization>(It.IsAny <FhirRequest>())).Returns(SystemTasks.Task.Run(() => orgSearchBundle as Resource)); _fhirSearch = searchMock.Object; var opts = new NrlsApiSetting { BaseUrl = "https://baseurl.com/", DefaultPort = "80", ProfileUrl = "https://profileurl.com", Secure = false, SecurePort = "443", SupportedContentTypes = new List <string> { "application/fhir+json" }, SupportedResources = new List <string> { "DocumentReference" } }; var mock = new Mock <IOptionsSnapshot <NrlsApiSetting> >(); mock.Setup(op => op.Get(It.IsAny <string>())).Returns(opts); _nrlsApiSettings = mock.Object; _expectedBundle = new Bundle { Id = "b54e3ad5-04b5-4f8f-8dbd-0e41d2465b5c", Meta = new Meta { LastUpdated = new DateTimeOffset(new DateTime(2018, 3, 1, 0, 0, 0, DateTimeKind.Utc)), VersionId = "b54e3ad5-04b5-4f8f-8dbd-0e41d2465b5c" }, Type = Bundle.BundleType.Searchset, Total = 1, Link = new List <Bundle.LinkComponent> { new Bundle.LinkComponent { Relation = "_self", Url = "TestLink" } }, Entry = new List <Bundle.EntryComponent> { new Bundle.EntryComponent { Search = new Bundle.SearchComponent { Mode = Bundle.SearchEntryMode.Match }, FullUrl = $"ResourceLink", Resource = new DocumentReference { Id = "5ab13f41957d0ad5d93a1339", Status = DocumentReferenceStatus.Current, Type = new CodeableConcept { Coding = new List <Coding> { new Coding { System = "http://snomed.info/sct", Code = "736253002", Display = "Mental health crisis plan (record artifact)" } } }, Subject = new ResourceReference { Reference = "https://demographics.spineservices.nhs.uk/STU3/Patient/2686033207" }, Indexed = new DateTime(2005, 12, 24, 9, 43, 41), Author = new List <ResourceReference> { new ResourceReference { Reference = "https://directory.spineservices.nhs.uk/STU3/Organization/1XR" } }, Custodian = new ResourceReference { Reference = "https://directory.spineservices.nhs.uk/STU3/Organization/1XR" }, Content = new List <DocumentReference.ContentComponent> { new DocumentReference.ContentComponent { Attachment = new Attachment { ContentType = "application/pdf", Url = "http://example.org/xds/mhd/Binary/07a6483f-732b-461e-86b6-edb665c45510.pdf", Title = "Mental health Care Plan Report", Creation = "2016-03-08T15:26:00+00:00" } } } } } } }; var clientMapCache = new ClientAsidMap { ClientAsids = new Dictionary <string, ClientAsid>() { { "000", new ClientAsid { Interactions = new List <string>() { FhirConstants.CreateInteractionId }, OrgCode = "TestOrgCode", Thumbprint = "TestThumbprint" } }, { "002", new ClientAsid { Interactions = new List <string>(), OrgCode = "TestOrgCode2", Thumbprint = "TestThumbprint" } }, { "003", new ClientAsid { Interactions = new List <string>(), OrgCode = "RV99", Thumbprint = "TestThumbprint" } } } }; var cacheMock = MemoryCacheStub.MockMemoryCacheService.GetMemoryCache(clientMapCache); _cache = cacheMock; }
public NrlsSearch(IOptionsSnapshot<ApiSetting> apiSetting, IFhirSearch fhirSearch, IMemoryCache memoryCache, IFhirValidation fhirValidation) : base(apiSetting, "NrlsApiSetting") { _fhirSearch = fhirSearch; _cache = memoryCache; _fhirValidation = fhirValidation; }