コード例 #1
0
    private static void PutPatient()
    {
      Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
      //Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient("https://stu3.test.pyrohealth.net/fhir", false);
      clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).
      //clientFhir.Timeout = 30000; // give the call a while to execute (particularly while debugging).
      Hl7.Fhir.Model.Patient Pat = new Hl7.Fhir.Model.Patient();
      //Pat.Id = Guid.NewGuid().ToString();
      Pat.Name = new List<Hl7.Fhir.Model.HumanName>()
      {
       new Hl7.Fhir.Model.HumanName()
       {
         Family = "millar104"
       }
      };
      var response = clientFhir.Create<Hl7.Fhir.Model.Patient>(Pat);
      string PatientResourceId = response.Id;
      Assert.AreEqual("1", response.VersionId);

      Pat.Id = PatientResourceId;
      Pat.Name[0].Family = "millar105";

      response = clientFhir.Update<Hl7.Fhir.Model.Patient>(Pat);
      Assert.AreEqual("2", response.VersionId);

      var PatientResult = (Hl7.Fhir.Model.Patient)clientFhir.Get($"{StaticTestData.FhirEndpoint()}/{PatientResourceId}");

      Assert.AreEqual(Hl7.Fhir.Model.ResourceType.Patient, PatientResult.ResourceType);
      
    }
コード例 #2
0
        private void CleanUpByIdentifier(ResourceType ResourceType)
        {
            // give the call a while to execute (particularly while debugging).
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 1000;

            //--- Clean Up ---------------------------------------------------------
            //Clean up by deleting all Test Patients

            SearchParams sp = new SearchParams().Where($"identifier={StaticTestData.TestIdentiferSystem}|");

            try
            {
                clientFhir.Delete(ResourceType.GetLiteral(), sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, $"Exception thrown on clean up delete of resource {ResourceType.GetLiteral()}: " + Exec.Message);
            }
        }
コード例 #3
0
        public void Test_TransBundleIfNoneExsists()
        {
            CleanUpByIdentifier(ResourceType.Patient);
            CleanUpByIdentifier(ResourceType.Observation);

            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 1000; // give the call a while to execute (particularly while debugging).

            //Test If-None-Exsists within a bundle transaction where their is a link from
            //one resource Observation to a Patient resource that by an identifier Reference.
            //So the idea is that the Observation resource identifier Reference is updated
            //with the servers true Id for the Patient resource which already exsists in the server.
            //The Patient resource in the bundle is not actualy commited as it already exsist.
            //So the test is as follows:
            //1. Add as a POST (Create) patient one as setup so it is in the server
            //2. POST a transaction bundle which has the same Pateint one resource marked as 'IfNoneExsists'
            //   and an Observation resource with a identifier Reference to Patient one. I will also add
            //   another Patient Two and Observation two resource that also have a identifier Reference link between
            //   them selves and IfNoneExists for the Patient two, yet in this case the Patient resource
            //   will not exists, so will be commited.
            //3. The outcome should be:
            //   - Patient One - OK (indicating it is already in the server, and has the same Fhir id as the step 1 PUT)
            //   - ObservationOne - Created (referance updated Patient One Fhir Id)
            //   - Patient Two - Created (Assigned a new Fhir ID)
            //   - Observation Two - Created (referance updated Patient One Fhir Id)


            //Arrange ------------------------------------------------------------

            //Patient One Setup
            string  PatientOneMRNIdentifer = Guid.NewGuid().ToString();
            Patient PatientOne             = StaticTestData.CreateTestPatient(PatientOneMRNIdentifer);

            Patient PatientCreateResult = null;

            try
            {
                //POST Patent One as Setup
                PatientCreateResult = clientFhir.Create(PatientOne);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on PUT Patient One setup: " + Exec.Message);
            }
            //Get the Fhir Id Assiged to patient One to assert later
            string PatientOneFhirId = PatientCreateResult.Id;

            Observation ObservationOne = new Observation();

            ObservationOne.Subject    = new ResourceReference($"{ResourceType.Patient.GetLiteral()}?identifier={PatientOneMRNIdentifer}");
            ObservationOne.Identifier = new List <Identifier>()
            {
                new Identifier()
                {
                    System = StaticTestData.TestIdentiferSystem,
                    Value  = Common.Tools.FhirGuid.FhirGuid.NewFhirGuid()
                }
            };
            ObservationOne.Code        = new CodeableConcept();
            ObservationOne.Code.Coding = new List <Coding>();
            ObservationOne.Code.Coding.Add(new Coding()
            {
                System = "http:/mytestcodesystem.com/system",
                Code   = "ObsOne"
            });

            //Patient Two Setup
            string  PatientTwoMRNIdentifer = Guid.NewGuid().ToString();
            Patient PatientTwo             = StaticTestData.CreateTestPatient(PatientTwoMRNIdentifer);

            Observation ObservationTwo = new Observation();

            ObservationTwo.Subject    = new ResourceReference($"{ResourceType.Patient.GetLiteral()}?identifier={PatientTwoMRNIdentifer}");
            ObservationTwo.Identifier = new List <Identifier>()
            {
                new Identifier()
                {
                    System = StaticTestData.TestIdentiferSystem,
                    Value  = Common.Tools.FhirGuid.FhirGuid.NewFhirGuid()
                }
            };
            ObservationTwo.Code        = new CodeableConcept();
            ObservationTwo.Code.Coding = new List <Coding>();
            ObservationTwo.Code.Coding.Add(new Coding()
            {
                System = "http:/mytestcodesystem.com/system",
                Code   = "ObsTwo"
            });

            //Now setup Transaction bundle
            Bundle TransBundleIfNoneExsists = new Bundle();

            TransBundleIfNoneExsists.Id    = Guid.NewGuid().ToString();
            TransBundleIfNoneExsists.Type  = Bundle.BundleType.Transaction;
            TransBundleIfNoneExsists.Entry = new List <Bundle.EntryComponent>();

            //Patient One Entry
            var PatientOneEntry = new Bundle.EntryComponent();

            TransBundleIfNoneExsists.Entry.Add(PatientOneEntry);
            PatientOneEntry.FullUrl             = CreateFullUrlUUID(Guid.NewGuid().ToString());
            PatientOneEntry.Resource            = PatientOne;
            PatientOneEntry.Request             = new Bundle.RequestComponent();
            PatientOneEntry.Request.Method      = Bundle.HTTPVerb.POST;
            PatientOneEntry.Request.Url         = ResourceType.Patient.GetLiteral();
            PatientOneEntry.Request.IfNoneExist = $"identifier={PatientOneMRNIdentifer}";

            //Observation One Entry
            //Patient One Entry
            var ObservationOneEntry = new Bundle.EntryComponent();

            TransBundleIfNoneExsists.Entry.Add(ObservationOneEntry);
            ObservationOneEntry.FullUrl        = CreateFullUrlUUID(Guid.NewGuid().ToString());
            ObservationOneEntry.Resource       = ObservationOne;
            ObservationOneEntry.Request        = new Bundle.RequestComponent();
            ObservationOneEntry.Request.Method = Bundle.HTTPVerb.POST;
            ObservationOneEntry.Request.Url    = ResourceType.Observation.GetLiteral();

            //Patient Two Entry
            var PatientTwoEntry = new Bundle.EntryComponent();

            TransBundleIfNoneExsists.Entry.Add(PatientTwoEntry);
            PatientTwoEntry.FullUrl             = CreateFullUrlUUID(Guid.NewGuid().ToString());
            PatientTwoEntry.Resource            = PatientTwo;
            PatientTwoEntry.Request             = new Bundle.RequestComponent();
            PatientTwoEntry.Request.Method      = Bundle.HTTPVerb.POST;
            PatientTwoEntry.Request.Url         = ResourceType.Patient.GetLiteral();
            PatientTwoEntry.Request.IfNoneExist = $"identifier={PatientTwoMRNIdentifer}";

            //Observation One Entry
            //Patient One Entry
            var ObservationTwoEntry = new Bundle.EntryComponent();

            TransBundleIfNoneExsists.Entry.Add(ObservationTwoEntry);
            ObservationTwoEntry.FullUrl        = CreateFullUrlUUID(Guid.NewGuid().ToString());
            ObservationTwoEntry.Resource       = ObservationTwo;
            ObservationTwoEntry.Request        = new Bundle.RequestComponent();
            ObservationTwoEntry.Request.Method = Bundle.HTTPVerb.POST;
            ObservationTwoEntry.Request.Url    = ResourceType.Observation.GetLiteral();

            //Act -------------------------------------------------------------------
            Bundle TransactionResult = null;

            try
            {
                TransactionResult = clientFhir.Transaction(TransBundleIfNoneExsists);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on POST Transaction bundle if-none-exsists: " + Exec.Message);
            }

            //Assert ---------------------------------------------------------------
            Assert.True(TransactionResult.Type == Bundle.BundleType.TransactionResponse);
            Assert.AreEqual(TransactionResult.Entry.Count, 4);

            //Patient One
            Assert.AreEqual(TransactionResult.Entry[0].Resource.ResourceType, ResourceType.Patient);
            //Assert.AreSame(TransactionResult.Entry[0].Resource.Id, PatientOneFhirId);
            Assert.AreEqual(TransactionResult.Entry[0].Response.Status, "200 OK");
            Assert.AreEqual(TransactionResult.Entry[0].Response.Etag, "W/\"1\"");

            //Observation One
            Assert.AreEqual(TransactionResult.Entry[1].Resource.ResourceType, ResourceType.Observation);
            Assert.AreEqual(TransactionResult.Entry[1].Response.Status, "201 Created");
            Assert.AreEqual(TransactionResult.Entry[1].Response.Etag, "W/\"1\"");
            if (TransactionResult.Entry[1].Resource is Observation ObsOneResult)
            {
                Assert.AreEqual(ObsOneResult.Code.Coding[0].Code, "ObsOne");
                Assert.AreEqual(ObsOneResult.Subject.Reference, $"{ResourceType.Patient.GetLiteral()}/{PatientOneFhirId}");
            }
            else
            {
                Assert.True(false, "Entry[1] shoudl have been a Observation resource");
            }

            //Patient Two
            Assert.AreEqual(TransactionResult.Entry[2].Resource.ResourceType, ResourceType.Patient);
            Assert.AreEqual(TransactionResult.Entry[2].Response.Status, "201 Created");
            Assert.AreEqual(TransactionResult.Entry[2].Response.Etag, "W/\"1\"");
            string PatientTwoFhirId = string.Empty;

            if (TransactionResult.Entry[2].Resource is Patient PatTwoResult)
            {
                Assert.AreEqual(PatTwoResult.Identifier[0].Value, PatientTwoMRNIdentifer);
                PatientTwoFhirId = PatTwoResult.Id;
            }
            else
            {
                Assert.True(false, "Entry[2] should have been a Patient resource");
            }

            //Observation Two
            Assert.AreEqual(TransactionResult.Entry[3].Resource.ResourceType, ResourceType.Observation);
            Assert.AreEqual(TransactionResult.Entry[3].Response.Status, "201 Created");
            Assert.AreEqual(TransactionResult.Entry[3].Response.Etag, "W/\"1\"");
            if (TransactionResult.Entry[3].Resource is Observation ObsTwoResult)
            {
                Assert.AreEqual(ObsTwoResult.Code.Coding[0].Code, "ObsTwo");
                Assert.AreEqual(ObsTwoResult.Subject.Reference, $"{ResourceType.Patient.GetLiteral()}/{PatientTwoFhirId}");
            }
            else
            {
                Assert.True(false, "Entry[3] should have been a Observation resource");
            }

            CleanUpByIdentifier(ResourceType.Patient);
            CleanUpByIdentifier(ResourceType.Observation);
        }
コード例 #4
0
        public void Test_BundleTransaction()
        {
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 1000; // give the call a while to execute (particularly while debugging).

            //------------------------------------------------------------------------------------------------------
            //Transaction Bundle 1 (Create) ---------------------------------------------------------------------------------
            //------------------------------------------------------------------------------------------------------

            Bundle TransBundle = new Bundle();

            TransBundle.Id    = Guid.NewGuid().ToString();
            TransBundle.Type  = Bundle.BundleType.Transaction;
            TransBundle.Entry = new List <Bundle.EntryComponent>();
            string PatientOneMRNIdentifer      = Guid.NewGuid().ToString();
            string OrganizationOneMRNIdentifer = Guid.NewGuid().ToString();

            //Add a Patient resource by Create
            Patient PatientOne             = StaticTestData.CreateTestPatient(PatientOneMRNIdentifer);
            string  OrgOneResourceIdFulUrl = CreateFullUrlUUID(Guid.NewGuid().ToString());

            PatientOne.ManagingOrganization = new ResourceReference()
            {
                Reference = OrgOneResourceIdFulUrl
            };

            var PatientEntry = new Bundle.EntryComponent();

            TransBundle.Entry.Add(PatientEntry);
            PatientEntry.Resource       = PatientOne;
            PatientEntry.Request        = new Bundle.RequestComponent();
            PatientEntry.Request.Method = Bundle.HTTPVerb.POST;
            string PatientResourceIdFulUrl = CreateFullUrlUUID(Guid.NewGuid().ToString());

            PatientEntry.FullUrl        = PatientResourceIdFulUrl;
            PatientEntry.Resource       = PatientOne;
            PatientEntry.Request        = new Bundle.RequestComponent();
            PatientEntry.Request.Method = Bundle.HTTPVerb.POST;
            PatientEntry.Request.Url    = "Patient";

            //Add a Organization resource by Create
            Organization OrganizationOne = new Organization();

            OrganizationOne.Name = "Test OrganizationOne";
            OrganizationOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, OrganizationOneMRNIdentifer));

            var OrganizationOneEntry = new Bundle.EntryComponent();

            TransBundle.Entry.Add(OrganizationOneEntry);
            OrganizationOneEntry.Resource       = OrganizationOne;
            OrganizationOneEntry.Request        = new Bundle.RequestComponent();
            OrganizationOneEntry.Request.Method = Bundle.HTTPVerb.POST;
            OrganizationOneEntry.FullUrl        = OrgOneResourceIdFulUrl;

            OrganizationOneEntry.Resource       = OrganizationOne;
            OrganizationOneEntry.Request        = new Bundle.RequestComponent();
            OrganizationOneEntry.Request.Method = Bundle.HTTPVerb.POST;
            OrganizationOneEntry.Request.Url    = "Organization";


            Bundle TransactionResult = null;

            try
            {
                TransactionResult = clientFhir.Transaction(TransBundle);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on POST Transaction bundle: " + Exec.Message);
            }

            Assert.True(TransactionResult.Type == Bundle.BundleType.TransactionResponse);
            Assert.IsTrue(TransactionResult.Entry[0].Response.Status.Contains(System.Net.HttpStatusCode.Created.ToString()));
            Assert.IsTrue(TransactionResult.Entry[1].Response.Status.Contains(System.Net.HttpStatusCode.Created.ToString()));
            Patient      TransactionResultPatient      = TransactionResult.Entry[0].Resource as Patient;
            Organization TransactionResultOrganization = TransactionResult.Entry[1].Resource as Organization;
            string       PatientOneResourceId          = TransactionResult.Entry[0].Resource.Id;
            string       OrgOneResourceId = TransactionResult.Entry[1].Resource.Id;


            //Check that the referance in the Patient to the Organization has been updated.
            Assert.AreEqual(TransactionResultPatient.ManagingOrganization.Reference, $"Organization/{TransactionResultOrganization.Id}");

            //Check the Response Etag matches the resource Version number
            string PatientResourceVersionNumber = TransactionResultPatient.VersionId;

            Assert.AreEqual(Common.Tools.HttpHeaderSupport.GetEntityTagHeaderValueFromVersion(PatientResourceVersionNumber).Tag, Common.Tools.HttpHeaderSupport.GetETagEntityTagHeaderValueFromETagString(TransactionResult.Entry[0].Response.Etag).Tag);

            //Check that the FullURL of the entry is correct aginst the returned Resource
            string PatientFullUrlExpected = $"{StaticTestData.FhirEndpoint()}/Patient/{PatientOneResourceId}";

            Assert.AreEqual(PatientFullUrlExpected, TransactionResult.Entry[0].FullUrl);

            //------------------------------------------------------------------------------------------------------
            //Transaction Bundle 2 (Update) ------------------------------------------------------------------------
            //------------------------------------------------------------------------------------------------------

            TransBundle.Id = Guid.NewGuid().ToString();
            TransBundle.Entry.Clear();
            //Patient
            PatientOne.Id = PatientOneResourceId;
            PatientOne.Name.Clear();
            string PatientFamilyName = "TestPatientUpdate";

            PatientOne.Name.Add(HumanName.ForFamily(PatientFamilyName).WithGiven("TestUpdate"));
            //PatientOne.BirthDateElement = new Date("1979-09-30");
            //PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, PatientOneMRNIdentifer));
            //PatientOne.Gender = AdministrativeGender.Unknown;

            PatientEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(PatientEntry);
            PatientResourceIdFulUrl     = $"{StaticTestData.FhirEndpoint()}/Patient/{PatientOneResourceId}";
            PatientEntry.FullUrl        = PatientResourceIdFulUrl;
            PatientEntry.Resource       = PatientOne;
            PatientEntry.Request        = new Bundle.RequestComponent();
            PatientEntry.Request.Method = Bundle.HTTPVerb.PUT;
            PatientEntry.Request.Url    = $"Patient/{PatientOneResourceId}";

            //Organization
            OrganizationOne.Id   = OrgOneResourceId;
            OrganizationOne.Name = "Test OrganizationOne Updated";
            //OrganizationOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, OrganizationOneMRNIdentifer));

            OrganizationOneEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(OrganizationOneEntry);
            OrgOneResourceIdFulUrl              = $"{StaticTestData.FhirEndpoint()}/Organization/{OrgOneResourceId}";
            OrganizationOneEntry.FullUrl        = OrgOneResourceIdFulUrl;
            OrganizationOneEntry.Resource       = OrganizationOne;
            OrganizationOneEntry.Request        = new Bundle.RequestComponent();
            OrganizationOneEntry.Request.Method = Bundle.HTTPVerb.PUT;
            OrganizationOneEntry.Request.Url    = $"Organization/{OrgOneResourceId}";

            TransactionResult = null;
            try
            {
                TransactionResult = clientFhir.Transaction(TransBundle);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on PUT Transaction bundle: " + Exec.Message);
            }
            Assert.IsTrue(TransactionResult.Entry[0].Response.Status.Contains(System.Net.HttpStatusCode.OK.ToString()));
            Assert.IsTrue(TransactionResult.Entry[1].Response.Status.Contains(System.Net.HttpStatusCode.OK.ToString()));

            TransactionResultPatient      = TransactionResult.Entry[0].Resource as Patient;
            TransactionResultOrganization = TransactionResult.Entry[1].Resource as Organization;

            //Check the family name was updated in the returned resource
            Assert.AreEqual(PatientFamilyName, TransactionResultPatient.Name[0].Family);

            //------------------------------------------------------------------------------------------------------
            //Transaction Bundle 3 (GET) ------------------------------------------------------------------------
            //------------------------------------------------------------------------------------------------------
            TransBundle.Id = Guid.NewGuid().ToString();
            TransBundle.Entry.Clear();

            PatientEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(PatientEntry);
            PatientEntry.Request        = new Bundle.RequestComponent();
            PatientEntry.Request.Method = Bundle.HTTPVerb.GET;
            PatientEntry.Request.Url    = $"Patient/{TransactionResultPatient.Id}";

            OrganizationOneEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(OrganizationOneEntry);
            OrganizationOneEntry.Request        = new Bundle.RequestComponent();
            OrganizationOneEntry.Request.Method = Bundle.HTTPVerb.GET;
            OrganizationOneEntry.Request.Url    = $"Organization/{TransactionResultOrganization.Id}";

            TransactionResult = null;
            try
            {
                TransactionResult = clientFhir.Transaction(TransBundle);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on GET Transaction bundle" + Exec.Message);
            }
            Assert.IsTrue(TransactionResult.Entry[0].Response.Status.Contains(System.Net.HttpStatusCode.OK.ToString()));
            Assert.IsTrue(TransactionResult.Entry[1].Response.Status.Contains(System.Net.HttpStatusCode.OK.ToString()));

            TransactionResultPatient      = TransactionResult.Entry[0].Resource as Patient;
            TransactionResultOrganization = TransactionResult.Entry[1].Resource as Organization;

            //------------------------------------------------------------------------------------------------------
            //Transaction Bundle 4 Search (GET) ------------------------------------------------------------------------
            //------------------------------------------------------------------------------------------------------
            TransBundle.Id = Guid.NewGuid().ToString();
            TransBundle.Entry.Clear();

            PatientEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(PatientEntry);
            PatientEntry.Request        = new Bundle.RequestComponent();
            PatientEntry.Request.Method = Bundle.HTTPVerb.GET;
            PatientEntry.Request.Url    = $"Patient?identifier={StaticTestData.TestIdentiferSystem}|{PatientOneMRNIdentifer}";

            OrganizationOneEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(OrganizationOneEntry);
            OrganizationOneEntry.Request        = new Bundle.RequestComponent();
            OrganizationOneEntry.Request.Method = Bundle.HTTPVerb.GET;
            OrganizationOneEntry.Request.Url    = $"Organization?identifier={StaticTestData.TestIdentiferSystem}|{OrganizationOneMRNIdentifer}";

            TransactionResult = null;
            try
            {
                TransactionResult = clientFhir.Transaction(TransBundle);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on GET Transaction bundle" + Exec.Message);
            }
            Assert.IsTrue(TransactionResult.Entry[0].Response.Status.Contains(System.Net.HttpStatusCode.OK.ToString()));
            Assert.IsTrue(TransactionResult.Entry[1].Response.Status.Contains(System.Net.HttpStatusCode.OK.ToString()));

            Bundle TransactionResultSearchPatientOneBundle   = TransactionResult.Entry[0].Resource as Bundle;
            Bundle TransactionResultOrganizationSearchBundle = TransactionResult.Entry[1].Resource as Bundle;

            //Check we only got one back in the search bundle
            Assert.AreEqual(TransactionResultSearchPatientOneBundle.Entry.Count, 1);
            Assert.AreEqual(TransactionResultOrganizationSearchBundle.Entry.Count, 1);

            //Check that each we got back were the two we added.
            Assert.AreEqual(TransactionResultSearchPatientOneBundle.Entry[0].Resource.Id, PatientOneResourceId);
            Assert.AreEqual(TransactionResultOrganizationSearchBundle.Entry[0].Resource.Id, OrgOneResourceId);

            //------------------------------------------------------------------------------------------------------
            //Transaction Bundle 5 If-Match (GET) --------------------------------------------------------------------
            //------------------------------------------------------------------------------------------------------
            TransBundle.Id = Guid.NewGuid().ToString();
            TransBundle.Entry.Clear();

            PatientEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(PatientEntry);
            PatientEntry.Request         = new Bundle.RequestComponent();
            PatientEntry.Request.Method  = Bundle.HTTPVerb.GET;
            PatientEntry.Request.Url     = $"Patient?identifier={StaticTestData.TestIdentiferSystem}|{PatientOneMRNIdentifer}";
            PatientEntry.Request.IfMatch = Common.Tools.HttpHeaderSupport.GetETagString(TransactionResultSearchPatientOneBundle.Entry[0].Resource.VersionId);

            OrganizationOneEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(OrganizationOneEntry);
            OrganizationOneEntry.Request         = new Bundle.RequestComponent();
            OrganizationOneEntry.Request.Method  = Bundle.HTTPVerb.GET;
            OrganizationOneEntry.Request.Url     = $"Organization?identifier={StaticTestData.TestIdentiferSystem}|{OrganizationOneMRNIdentifer}";
            OrganizationOneEntry.Request.IfMatch = Common.Tools.HttpHeaderSupport.GetETagString(TransactionResultOrganizationSearchBundle.Entry[0].Resource.VersionId);

            TransactionResult = null;
            try
            {
                TransactionResult = clientFhir.Transaction(TransBundle);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on GET Transaction bundle" + Exec.Message);
            }
            Assert.IsTrue(TransactionResult.Entry[0].Response.Status.Contains(System.Net.HttpStatusCode.OK.ToString()));
            Assert.IsTrue(TransactionResult.Entry[1].Response.Status.Contains(System.Net.HttpStatusCode.OK.ToString()));

            TransactionResultSearchPatientOneBundle   = TransactionResult.Entry[0].Resource as Bundle;
            TransactionResultOrganizationSearchBundle = TransactionResult.Entry[1].Resource as Bundle;

            //Check we only got one back in the search bundle
            Assert.AreEqual(TransactionResultSearchPatientOneBundle.Entry.Count, 1);
            Assert.AreEqual(TransactionResultOrganizationSearchBundle.Entry.Count, 1);


            //------------------------------------------------------------------------------------------------------
            //Transaction Bundle 6 If-Match (DELETE) --------------------------------------------------------------------
            //------------------------------------------------------------------------------------------------------
            TransBundle.Id = Guid.NewGuid().ToString();
            TransBundle.Entry.Clear();

            PatientEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(PatientEntry);
            PatientEntry.Request         = new Bundle.RequestComponent();
            PatientEntry.Request.Method  = Bundle.HTTPVerb.DELETE;
            PatientEntry.Request.Url     = $"Patient?identifier={StaticTestData.TestIdentiferSystem}|{PatientOneMRNIdentifer}";
            PatientEntry.Request.IfMatch = Common.Tools.HttpHeaderSupport.GetETagString(TransactionResultSearchPatientOneBundle.Entry[0].Resource.VersionId);

            OrganizationOneEntry = new Bundle.EntryComponent();
            TransBundle.Entry.Add(OrganizationOneEntry);
            OrganizationOneEntry.Request         = new Bundle.RequestComponent();
            OrganizationOneEntry.Request.Method  = Bundle.HTTPVerb.DELETE;
            OrganizationOneEntry.Request.Url     = $"Organization?identifier={StaticTestData.TestIdentiferSystem}|{OrganizationOneMRNIdentifer}";
            OrganizationOneEntry.Request.IfMatch = Common.Tools.HttpHeaderSupport.GetETagString(TransactionResultOrganizationSearchBundle.Entry[0].Resource.VersionId);

            TransactionResult = null;
            try
            {
                TransactionResult = clientFhir.Transaction(TransBundle);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on GET Transaction bundle" + Exec.Message);
            }
            Assert.IsTrue(TransactionResult.Entry[0].Response.Status.Contains(System.Net.HttpStatusCode.NoContent.ToString()));
            Assert.IsTrue(TransactionResult.Entry[1].Response.Status.Contains(System.Net.HttpStatusCode.NoContent.ToString()));

            CleanUpByIdentifier(ResourceType.Patient);
            CleanUpByIdentifier(ResourceType.Organization);
        }
コード例 #5
0
 public void Setup()
 {
     Server = StaticTestData.StartupServer();
 }
コード例 #6
0
        public void Test_MetadataCapabilityStatment()
        {
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

            Resource CapabilityStatment = null;

            try
            {
                CapabilityStatment = clientFhir.CapabilityStatement(SummaryType.Data);
            }
            catch (FhirOperationException ex)
            {
                Assert.Fail($"Call to server metadata operation threw an exception. {ex.Message}");
            }

            if (CapabilityStatment is CapabilityStatement Cap)
            {
                Assert.NotNull(Cap.Contact, "No Contact element in CapabilityStatement.");
                Assert.AreEqual(1, Cap.Contact.Count(), "Not exactly 1 Contact elements in CapabilityStatement.");
                Assert.NotNull(Cap.Contact[0].Telecom, "No Contact[0].Telecom element in CapabilityStatement.");
                Assert.AreEqual(2, Cap.Contact[0].Telecom.Count(), "Not exactly 2 Contact[0].Telecom elements in CapabilityStatement.");

                Assert.AreEqual(1, Cap.Contact.Count(), "Not exactly 1 Format element in CapabilityStatement.");

                Assert.NotNull(Cap.Format, "No Format element in CapabilityStatement.");
                Assert.AreEqual(9, Cap.Format.Count(), "Not exactly 9 Format elements in CapabilityStatement.");

                Assert.NotNull(Cap.Rest, "No Rest element in CapabilityStatement.");
                Assert.AreEqual(1, Cap.Rest.Count, "Not exactly one Rest element in CapabilityStatement.");


                Assert.NotNull(Cap.Rest[0].Resource, "No Rest.Resource element in CapabilityStatement.");
                Assert.GreaterOrEqual(119, Cap.Rest[0].Resource.Count(), "Less than 197 FHIR resources in CapabilityStatement.");

                var ObsResourceElement = Cap.Rest[0].Resource.SingleOrDefault(x => x.Type == ResourceType.Observation);
                Assert.NotNull(ObsResourceElement, "No Observation Resource element in CapabilityStatement.");
                Assert.NotNull(ObsResourceElement.Interaction, "No Observation Interaction element in CapabilityStatement.");
                Assert.GreaterOrEqual(8, ObsResourceElement.Interaction.Count(), "Less than 8 Observation Interactions in CapabilityStatement.");
                Assert.AreEqual(CapabilityStatement.ResourceVersionPolicy.Versioned, ObsResourceElement.Versioning, "Versioning element incorrect");
                Assert.AreEqual(true, ObsResourceElement.ReadHistory, "ReadHistory should be True");
                Assert.AreEqual(true, ObsResourceElement.UpdateCreate, "UpdateCreate should be True");
                Assert.AreEqual(true, ObsResourceElement.ConditionalCreate, "conditionalCreate should be True");
                Assert.AreEqual(CapabilityStatement.ConditionalReadStatus.FullSupport, ObsResourceElement.ConditionalRead, "conditionalUpdate should be True");
                Assert.AreEqual(true, ObsResourceElement.ConditionalUpdate, "conditionalUpdate should be True");
                Assert.AreEqual(CapabilityStatement.ConditionalDeleteStatus.Multiple, ObsResourceElement.ConditionalDelete, "ConditionalDelete should be True");
                Assert.AreEqual(CapabilityStatement.ReferenceHandlingPolicy.Literal, ObsResourceElement.ReferencePolicy.ElementAt(0), "ReferencePolicy 1 should be True");
                Assert.AreEqual(CapabilityStatement.ReferenceHandlingPolicy.Local, ObsResourceElement.ReferencePolicy.ElementAt(1), "ReferencePolicy 2 should be True");

                Assert.AreEqual(27, ObsResourceElement.SearchInclude.Count(), "Not exactly 27 SearchInclude elements in CapabilityStatement.");
                Assert.AreEqual(67, ObsResourceElement.SearchRevInclude.Count(), "Not exactly 67 SearchRevInclude elements in CapabilityStatement.");
                Assert.AreEqual(43, ObsResourceElement.SearchParam.Count(), "Not exactly 43 SearchParam elements in CapabilityStatement.");
                Assert.IsNotEmpty(ObsResourceElement.SearchParam[0].Name, "SearchParam Name element should not be empty in CapabilityStatement.");
                Assert.IsNotEmpty(ObsResourceElement.SearchParam[0].Definition, "SearchParam Definition element should not be empty in CapabilityStatement.");
                Assert.IsNotNull(ObsResourceElement.SearchParam[0].Type, "SearchParam Type element should not be empty in CapabilityStatement.");
                Assert.IsNotEmpty(ObsResourceElement.SearchParam[0].Documentation, "SearchParam documentation element should not be empty in CapabilityStatement.");
            }
            else
            {
                Assert.Fail($"Call to server metadata operation returned a resource not of type CapabilityStatement");
            }
        }
コード例 #7
0
        public void Test_DeleteHistoryIndexes()
        {
            FhirClient clientFhir = new FhirClient(StaticTestData.FhirEndpoint(), false);

            clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

            string PatientOneResourceId   = Guid.NewGuid().ToString();
            string PatientOneMRNIdentifer = Guid.NewGuid().ToString();

            //Add a Patient resource by Create
            Patient PatientOne = new Patient();

            PatientOne.Id = PatientOneResourceId;
            PatientOne.Name.Add(HumanName.ForFamily("TestPatient").WithGiven("Test"));
            PatientOne.BirthDateElement = new Date("1979-09-30");
            PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, PatientOneMRNIdentifer));
            PatientOne.Gender = AdministrativeGender.Unknown;

            Patient PatientResult = null;

            try
            {
                PatientResult = clientFhir.Update <Patient>(PatientOne);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on Patient resource Update: " + Exec.Message);
            }
            Assert.NotNull(PatientResult, "Resource create by Updated returned resource of null");

            PatientResult = null;

            //Update the patient again to ensure there are History indexes to delete
            try
            {
                PatientResult = clientFhir.Update <Patient>(PatientOne);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on Patient resource Update: " + Exec.Message);
            }
            Assert.NotNull(PatientResult, "Resource create by Updated returned resource of null");

            //------------------------------------------------------------------------------------
            // ------------ Base Operation, limited types by parameters --------------------------
            //------------------------------------------------------------------------------------

            //Now setup to use the base operation $delete-history-indexes
            //Parameter Resource
            Parameters ParametersIn = new Parameters();

            //ParametersIn.Id = Guid.NewGuid().ToString();
            ParametersIn.Parameter = new List <Parameters.ParameterComponent>();
            var ParamOne = new Parameters.ParameterComponent();

            ParametersIn.Parameter.Add(ParamOne);
            ParamOne.Name  = "ResourceType";
            ParamOne.Value = new FhirString(FHIRAllTypes.Patient.GetLiteral());

            Parameters ParametersResult = null;

            try
            {
                var ResourceResult = clientFhir.WholeSystemOperation(OperationName, ParametersIn);
                ParametersResult = ResourceResult as Parameters;
            }
            catch (Exception Exec)
            {
                Assert.True(false, $"Exception thrown on Operation call to ${OperationName}: " + Exec.Message);
            }
            Assert.NotNull(ParametersResult, "Resource create by Updated returned resource of null");
            Assert.NotNull(ParametersResult.Parameter, "ParametersResult.Parameter is null");
            Assert.AreEqual(ParametersResult.Parameter.Count(), 1, "ParametersResult.Parameter contains more than one parameter.");
            Assert.AreEqual(ParametersResult.Parameter[0].Name, $"{FHIRAllTypes.Patient.GetLiteral()}_TotalIndexesDeletedCount", "ParametersResult.Parameter.Name not as expected.");
            Assert.IsInstanceOf <FhirDecimal>(ParametersResult.Parameter[0].Value, "ParametersResult.Parameter.Value expected FhirDecimal.");
            Assert.Greater((ParametersResult.Parameter[0].Value as FhirDecimal).Value, 0, "ParametersResult.Parameter.Value expected to be greater than 0.");
            ParametersResult = null;


            //------------------------------------------------------------------------------------
            // ------------ Resource Base Operation ALL resource ResourceType = *----------------------------------------------
            //------------------------------------------------------------------------------------

            //Now setup to use the base operation $delete-history-indexes
            //Parameter Resource
            ParametersIn           = new Parameters();
            ParametersIn.Id        = Guid.NewGuid().ToString();
            ParametersIn.Parameter = new List <Parameters.ParameterComponent>();
            ParamOne = new Parameters.ParameterComponent();
            ParametersIn.Parameter.Add(ParamOne);
            ParamOne.Name  = "ResourceType";
            ParamOne.Value = new FhirString("*");

            ParametersResult = null;
            try
            {
                var ResourceResult = clientFhir.WholeSystemOperation(OperationName, ParametersIn);
                ParametersResult = ResourceResult as Parameters;
            }
            catch (Exception Exec)
            {
                Assert.True(false, $"Exception thrown on Operation call to ${OperationName}: " + Exec.Message);
            }
            Assert.NotNull(ParametersResult, "Resource create by Updated returned resource of null");
            Assert.NotNull(ParametersResult.Parameter, "ParametersResult.Parameter is null");
            Assert.AreEqual(ParametersResult.Parameter.Count(), ModelInfo.SupportedResources.Count, "ParametersResult.Parameter.Count Not equal to Supported resource total.");
            ParametersResult = null;

            //------------------------------------------------------------------------------------
            // ------------ Resource Type Operation ----------------------------------------------
            //------------------------------------------------------------------------------------

            //Update the patient again to ensure there are History indexes to delete
            PatientResult = null;
            try
            {
                PatientResult = clientFhir.Update <Patient>(PatientOne);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on Patient resource Update: " + Exec.Message);
            }
            Assert.NotNull(PatientResult, "Resource create by Updated returned resource of null");

            ParametersIn    = new Parameters();
            ParametersIn.Id = Guid.NewGuid().ToString();

            ParametersResult = null;
            try
            {
                var ResourceResult = clientFhir.TypeOperation <Patient>(OperationName, ParametersIn);
                ParametersResult = ResourceResult as Parameters;
            }
            catch (Exception Exec)
            {
                Assert.True(false, $"Exception thrown on Operation call to ${OperationName}: " + Exec.Message);
            }
            Assert.NotNull(ParametersResult, "Resource create by Updated returned resource of null");
            Assert.NotNull(ParametersResult.Parameter, "ParametersResult.Parameter is null");
            Assert.AreEqual(ParametersResult.Parameter.Count(), 1, "ParametersResult.Parameter contains more than one parameter.");
            Assert.AreEqual(ParametersResult.Parameter[0].Name, $"{FHIRAllTypes.Patient.GetLiteral()}_TotalIndexesDeletedCount", "ParametersResult.Parameter.Name not as expected.");
            Assert.IsInstanceOf <FhirDecimal>(ParametersResult.Parameter[0].Value, "ParametersResult.Parameter.Value expected FhirDecimal.");
            Assert.Greater((ParametersResult.Parameter[0].Value as FhirDecimal).Value, 0, "ParametersResult.Parameter.Value expected to be greater than 0.");

            //--- Clean Up ---------------------------------------------------------
            //Clean up by deleting all Test Patients
            SearchParams sp = new SearchParams().Where($"identifier={StaticTestData.TestIdentiferSystem}|");

            try
            {
                clientFhir.Delete("Patient", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource Patient: " + Exec.Message);
            }
        }
コード例 #8
0
    public void Test_TokenCaseInCorrect()
    {
      CleanUpByIdentifier(ResourceType.Observation);

      Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
      clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

      //Add an Observation one with an Effective Period 10:00 AM to 11:00 AM 
      FhirDateTime ObsOneEffectiveStart = new FhirDateTime(new DateTimeOffset(2018, 08, 5, 10, 00, 00, new TimeSpan(8, 0, 0)));
      FhirDateTime ObsOneEffectiveEnd = new FhirDateTime(new DateTimeOffset(2018, 08, 5, 11, 00, 00, new TimeSpan(8, 0, 0)));
      string ObsOneResourceId = string.Empty;
      Observation ObsOne = new Observation();
      ObsOne.Identifier = new List<Identifier>(){
         new Identifier()
         {
            System = StaticTestData.TestIdentiferSystem,
            Value = Common.Tools.FhirGuid.FhirGuid.NewFhirGuid()
         }
      };
      ObsOne.Code = new CodeableConcept();
      ObsOne.Code.Coding = new List<Coding>();
      ObsOne.Code.Coding.Add(new Coding()
      {
        System = "http:/mytestcodesystem.com/system",
        Code = "ObsOne"
      });
      var EffectiveObsOnePeriod = new Period();
      EffectiveObsOnePeriod.StartElement = ObsOneEffectiveStart;
      EffectiveObsOnePeriod.EndElement = ObsOneEffectiveEnd;
      ObsOne.Effective = EffectiveObsOnePeriod;

      Observation ObsOneResult = null;
      try
      {
        ObsOneResult = clientFhir.Create(ObsOne);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.NotNull(ObsOneResult, "Resource create by Updated returned resource of null");
      ObsOneResourceId = ObsOneResult.Id;
      ObsOneResult = null;

      //Add an Observation one with an Effective Period 10:30 AM to 11:30 AM 
      FhirDateTime ObsTwoEffectiveStart = new FhirDateTime(new DateTimeOffset(2018, 08, 5, 10, 30, 00, new TimeSpan(8, 0, 0)));
      FhirDateTime ObsTwoEffectiveEnd = new FhirDateTime(new DateTimeOffset(2018, 08, 5, 11, 30, 00, new TimeSpan(8, 0, 0)));
      string ObsTwoResourceId = string.Empty;
      Observation ObsTwo = new Observation();
      ObsTwo.Identifier = new List<Identifier>(){
         new Identifier()
         {
            System = StaticTestData.TestIdentiferSystem,
            Value = Common.Tools.FhirGuid.FhirGuid.NewFhirGuid()
         }
      };
      ObsTwo.Code = new CodeableConcept();
      ObsTwo.Code.Coding = new List<Coding>();
      ObsTwo.Code.Coding.Add(new Coding()
      {
        System = "http:/mytestcodesystem.com/system",
        Code = "ObsTwo"
      });
      var EffectiveObsTwoPeriod = new Period();
      EffectiveObsTwoPeriod.StartElement = ObsTwoEffectiveStart;
      EffectiveObsTwoPeriod.EndElement = ObsTwoEffectiveEnd;
      ObsTwo.Effective = EffectiveObsTwoPeriod;

      Observation ObsTwoResult = null;
      try
      {
        ObsTwoResult = clientFhir.Create(ObsTwo);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.NotNull(ObsTwoResult, "Resource create by Updated returned resource of null");
      ObsTwoResourceId = ObsTwoResult.Id;
      ObsTwoResult = null;

      //Assert
      var SearchParam = new SearchParams();
      try
      {
        //ObsOne = 10:00 to 11:00
        //ObsTwo = 10:30 to 11:30
        SearchParam.Add("identifier", $"{StaticTestData.TestIdentiferSystem}|");
        SearchParam.Add("code", "http:/mytestcodesystem.com/system|obsone");
        clientFhir.PreferredParameterHandling = SearchParameterHandling.Strict;
        Bundle BundleResult = clientFhir.Search<Observation>(SearchParam);

        //From thr R4 FHIR Spec
        //Note: There are many challenging issues around case senstivity and token searches. 
        //Some code systems are case sensitive(e.g.UCUM) while others are known not to be.For many 
        //code systems, it's ambiguous. Other kinds of values are also ambiguous. When in doubt, servers
        //SHOULD treat tokens in a case-insensitive manner, on the grounds that including undesired data 
        //has less safety implications than excluding desired behavior. Clients SHOULD always use the 
        //correct case when possible, and allow for the server to perform case-insensitive matching.

        //STU3 was a little vage on this point. Trying to conclude case sesativity based on CodeSystem is 
        //a more difficult goal and would slow down searches, do not plan on doing that any time soon.
        Assert.IsNotNull(BundleResult);
        Assert.IsNotNull(BundleResult.Entry);
        Assert.AreEqual(1, BundleResult.Entry.Count);
        Assert.AreEqual(ObsOneResourceId, BundleResult.Entry[0].Resource.Id);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Search: " + Exec.Message);
      }

      CleanUpByIdentifier(ResourceType.Observation);
    }
コード例 #9
0
        public void Setup()
        {
            Server = StaticTestData.StartupServer();

            clientFhir         = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

            //This Set up creates an Observation linked to a Patient as the 'subject' and an Organization as the 'performer'
            // Observation1
            //           --> Patient
            //           --> Organization - > Endpoint
            //           --> Observation2
            //                           ----> Observation3

            //Add a Endpoint resource
            //Loop only here for load testing
            for (int i = 0; i < 1; i++)
            {
                Endpoint EndpointOnex = new Endpoint();
                EndpointOnex.Name    = EndpointOneName;
                EndpointOneIdentifer = Guid.NewGuid().ToString();
                EndpointOnex.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, EndpointOneIdentifer));
                Endpoint EndPointOneResult = null;
                try
                {
                    EndPointOneResult = clientFhir.Create(EndpointOnex);
                }
                catch (Exception Exec)
                {
                    Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
                }
                Assert.NotNull(EndPointOneResult, "Resource created but returned resource is null");
                EndpointOneResourceId = EndPointOneResult.Id;
            }

            //Add a Endpoint resource
            Endpoint EndpointTwo = new Endpoint();

            EndpointTwo.Name = EndpointOneName;
            string EndpointTwoIdentifer = Guid.NewGuid().ToString();

            EndpointTwo.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, EndpointTwoIdentifer));
            Endpoint EndPointTwoResult = null;

            try
            {
                EndPointTwoResult = clientFhir.Create(EndpointTwo);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
            }
            Assert.NotNull(EndPointTwoResult, "Resource created but returned resource is null");
            string EndpointTwoResourceId = EndPointTwoResult.Id;



            //Add a Organization resource by Update
            Organization OrganizationOne = new Organization();

            OrganizationOne.Name     = OrganizationOneName;
            OrganizationOneIdentifer = Guid.NewGuid().ToString();
            OrganizationOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, OrganizationOneIdentifer));
            OrganizationOne.Endpoint = new List <ResourceReference>()
            {
                new ResourceReference($"{ResourceType.Endpoint.GetLiteral()}/{EndpointOneResourceId}")
            };
            Organization OrganizationOneResult = null;

            try
            {
                OrganizationOneResult = clientFhir.Create(OrganizationOne);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
            }
            Assert.NotNull(OrganizationOneResult, "Resource created but returned resource is null");
            OrganizationOneResourceId = OrganizationOneResult.Id;

            //Patient where Obs.performer -> Org.name
            // Add a Patient to Link to a Observation below  ================================
            //Loop only here for load testing debugging
            for (int i = 0; i < 10; i++)
            {
                Patient PatientOne = new Patient();
                PatientOne.Name.Add(HumanName.ForFamily(PatientOneFamily).WithGiven("Test"));
                PatientOne.BirthDateElement = new Date("1979-09-30");
                PatientOneMRNIdentifer      = Guid.NewGuid().ToString();
                PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, PatientOneMRNIdentifer));
                PatientOne.Gender = AdministrativeGender.Unknown;
                PatientOne.ManagingOrganization = new ResourceReference($"{ResourceType.Organization.GetLiteral()}/{OrganizationOneResourceId}");
                Patient PatientResult = null;
                try
                {
                    PatientResult = clientFhir.Create(PatientOne);
                }
                catch (Exception Exec)
                {
                    Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
                }
                Assert.NotNull(PatientResult, "Resource created but returned resource is null");
                PatientResourceId = PatientResult.Id;
            }

            //Here we set up 3 observations linked in a chain Obs1 -> Obs2 - > Obs3 to test recursive includes

            // Add Observation 3 Linked to no other observation
            // This is to test recursive includes
            Observation ObsResourceThree = new Observation();

            ObsResourceThree.Status   = ObservationStatus.Final;
            ObsResourceThree.Code     = new CodeableConcept("http://somesystem.net/ObSystem", "WCC");
            ObservationThreeIdentifer = Guid.NewGuid().ToString();
            ObsResourceThree.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, ObservationTwoIdentifer));
            ObsResourceThree.Subject   = new ResourceReference($"{ResourceType.Patient.GetLiteral()}/{PatientResourceId}");
            ObsResourceThree.Performer = new List <ResourceReference>()
            {
                new ResourceReference($"{ResourceType.Organization.GetLiteral()}/{OrganizationOneResourceId}")
            };
            Observation ObservationThreeResult = null;

            try
            {
                ObservationThreeResult = clientFhir.Create(ObsResourceThree);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on Observation resource two create: " + Exec.Message);
            }
            Assert.NotNull(ObservationThreeResult, "Resource created but returned resource is null");
            ObservationThreeResourceId = ObservationThreeResult.Id;
            ObservationThreeResult     = null;


            // Add Observation 2 Linked to the Observation3 above and Patient above
            // This is to test recursive includes
            Observation ObsResourceTwo = new Observation();

            ObsResourceTwo.Status   = ObservationStatus.Final;
            ObsResourceTwo.Code     = new CodeableConcept("http://somesystem.net/ObSystem", "WCC");
            ObservationTwoIdentifer = Guid.NewGuid().ToString();
            ObsResourceTwo.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, ObservationTwoIdentifer));
            ObsResourceTwo.Subject   = new ResourceReference($"{ResourceType.Patient.GetLiteral()}/{PatientResourceId}");
            ObsResourceTwo.Performer = new List <ResourceReference>()
            {
                new ResourceReference($"{ResourceType.Organization.GetLiteral()}/{OrganizationOneResourceId}")
            };
            ObsResourceTwo.Related = new List <Observation.RelatedComponent>();
            var RelatedArtifact2 = new Observation.RelatedComponent();

            RelatedArtifact2.Target = new ResourceReference($"{ResourceType.Observation.GetLiteral()}/{ObservationThreeResourceId}");
            ObsResourceTwo.Related.Add(RelatedArtifact2);
            Observation ObservationTwoResult = null;

            try
            {
                ObservationTwoResult = clientFhir.Create(ObsResourceTwo);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on Observation resource two create: " + Exec.Message);
            }
            Assert.NotNull(ObservationTwoResult, "Resource created but returned resource is null");
            ObservationTwoResourceId = ObservationTwoResult.Id;
            ObservationTwoResult     = null;

            // Add Observation1 linked to Observation 2 above and the Patient above ================================
            Observation ObsResourceOne = new Observation();

            ObsResourceOne.Status   = ObservationStatus.Final;
            ObsResourceOne.Code     = new CodeableConcept("http://somesystem.net/ObSystem", "HB");
            ObservationOneIdentifer = Guid.NewGuid().ToString();
            ObsResourceOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, ObservationOneIdentifer));
            ObsResourceOne.Subject   = new ResourceReference($"{ResourceType.Patient.GetLiteral()}/{PatientResourceId}");
            ObsResourceOne.Performer = new List <ResourceReference>()
            {
                new ResourceReference($"{ResourceType.Organization.GetLiteral()}/{OrganizationOneResourceId}")
            };
            ObsResourceOne.Related = new List <Observation.RelatedComponent>();
            var RelatedArtifact1 = new Observation.RelatedComponent();

            RelatedArtifact1.Target = new ResourceReference($"{ResourceType.Observation.GetLiteral()}/{ObservationTwoResourceId}");
            ObsResourceOne.Related.Add(RelatedArtifact1);
            Observation ObservationOneResult = null;

            try
            {
                ObservationOneResult = clientFhir.Create(ObsResourceOne);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
            }
            Assert.NotNull(ObservationOneResult, "Resource created but returned resource is null");
            ObservationOneResourceId = ObservationOneResult.Id;
            ObservationOneResult     = null;
        }
コード例 #10
0
    public void Test_CRUD()
    {

      Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
      clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

      string PatientResourceId = string.Empty;

      //Add a Patient resource by Update
      Patient PatientOne = new Patient();
      PatientOne.Name.Add(HumanName.ForFamily("TestPatient").WithGiven("Test"));
      PatientOne.BirthDateElement = new Date("1979-09-30");
      string PatientOneMRNIdentifer = Guid.NewGuid().ToString();
      PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, PatientOneMRNIdentifer));
      PatientOne.Gender = AdministrativeGender.Unknown;

      Patient PatientResult = null;
      try
      {
        PatientResult = clientFhir.Create(PatientOne);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.NotNull(PatientResult, "Resource create by Updated returned resource of null");
      PatientResourceId = PatientResult.Id;
      PatientResult = null;

      //Get the Added resource by Id
      try
      {
        //PatientOneResourceId
        PatientResult = (Patient)clientFhir.Get($"{StaticTestData.FhirEndpoint()}/Patient/{PatientResourceId}");
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
      }
      Assert.NotNull(PatientResult, "Resource Get returned resource of null");
      Assert.AreEqual(PatientResourceId, PatientResult.Id, "Resource created by Updated has incorrect Resource Id");
      Assert.AreEqual(AdministrativeGender.Unknown, PatientResult.Gender, "Patient gender does not match.");

      //Update
      PatientResult.Gender = AdministrativeGender.Male;
      try
      {
        clientFhir.Update(PatientResult);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
      }
      PatientResult = null;

      //Get the Added resource by Id
      try
      {
        PatientResult = (Patient)clientFhir.Get($"{StaticTestData.FhirEndpoint()}/Patient/{PatientResourceId}");
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
      }
      Assert.NotNull(PatientResult, "Resource Get returned resource of null");
      Assert.AreEqual(AdministrativeGender.Male, PatientResult.Gender, "Patient gender does not match.");

      //Delete Resource
      try
      {
        clientFhir.Delete($"Patient/{PatientResourceId}");
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
      }

      //Get the Added resource by Id
      try
      {
        var Result = clientFhir.Get($"{StaticTestData.FhirEndpoint()}/Patient/{PatientResourceId}");
      }
      catch (Hl7.Fhir.Rest.FhirOperationException OpExec)
      {
        Assert.AreEqual(OpExec.Status, System.Net.HttpStatusCode.Gone, "Final Get did not return Http Status of Gone.");
      }

    }
コード例 #11
0
    public void Test_TokenCaseCorrect()
    {
      CleanUpByIdentifier(ResourceType.Observation);

      Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
      clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

      //Add an Observation one with an Effective Period 10:00 AM to 11:00 AM 
      FhirDateTime ObsOneEffectiveStart = new FhirDateTime(new DateTimeOffset(2018, 08, 5, 10, 00, 00, new TimeSpan(8, 0, 0)));
      FhirDateTime ObsOneEffectiveEnd = new FhirDateTime(new DateTimeOffset(2018, 08, 5, 11, 00, 00, new TimeSpan(8, 0, 0)));
      string ObsOneResourceId = string.Empty;
      Observation ObsOne = new Observation();
      ObsOne.Identifier = new List<Identifier>(){
         new Identifier()
         {
            System = StaticTestData.TestIdentiferSystem,
            Value = Common.Tools.FhirGuid.FhirGuid.NewFhirGuid()
         }
      };
      ObsOne.Code = new CodeableConcept();
      ObsOne.Code.Coding = new List<Coding>();
      ObsOne.Code.Coding.Add(new Coding()
      {
        System = "http:/mytestcodesystem.com/system",
        Code = "ObsOne"
      });
      var EffectiveObsOnePeriod = new Period();
      EffectiveObsOnePeriod.StartElement = ObsOneEffectiveStart;
      EffectiveObsOnePeriod.EndElement = ObsOneEffectiveEnd;
      ObsOne.Effective = EffectiveObsOnePeriod;

      Observation ObsOneResult = null;
      try
      {
        ObsOneResult = clientFhir.Create(ObsOne);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.NotNull(ObsOneResult, "Resource create by Updated returned resource of null");
      ObsOneResourceId = ObsOneResult.Id;
      ObsOneResult = null;

      //Add an Observation one with an Effective Period 10:30 AM to 11:30 AM 
      FhirDateTime ObsTwoEffectiveStart = new FhirDateTime(new DateTimeOffset(2018, 08, 5, 10, 30, 00, new TimeSpan(8, 0, 0)));
      FhirDateTime ObsTwoEffectiveEnd = new FhirDateTime(new DateTimeOffset(2018, 08, 5, 11, 30, 00, new TimeSpan(8, 0, 0)));
      string ObsTwoResourceId = string.Empty;
      Observation ObsTwo = new Observation();
      ObsTwo.Identifier = new List<Identifier>(){
         new Identifier()
         {
            System = StaticTestData.TestIdentiferSystem,
            Value = Common.Tools.FhirGuid.FhirGuid.NewFhirGuid()
         }
      };
      ObsTwo.Code = new CodeableConcept();
      ObsTwo.Code.Coding = new List<Coding>();
      ObsTwo.Code.Coding.Add(new Coding()
      {
        System = "http:/mytestcodesystem.com/system",
        Code = "ObsTwo"
      });
      var EffectiveObsTwoPeriod = new Period();
      EffectiveObsTwoPeriod.StartElement = ObsTwoEffectiveStart;
      EffectiveObsTwoPeriod.EndElement = ObsTwoEffectiveEnd;
      ObsTwo.Effective = EffectiveObsTwoPeriod;

      Observation ObsTwoResult = null;
      try
      {
        ObsTwoResult = clientFhir.Create(ObsTwo);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.NotNull(ObsTwoResult, "Resource create by Updated returned resource of null");
      ObsTwoResourceId = ObsTwoResult.Id;
      ObsTwoResult = null;

      //Assert
      var SearchParam = new SearchParams();
      try
      {
        //ObsOne = 10:00 to 11:00
        //ObsTwo = 10:30 to 11:30
        SearchParam.Add("identifier", $"{StaticTestData.TestIdentiferSystem}|");
        SearchParam.Add("code", "http:/mytestcodesystem.com/system|ObsOne");
        clientFhir.PreferredParameterHandling = SearchParameterHandling.Strict;
        Bundle BundleResult = clientFhir.Search<Observation>(SearchParam);

        Assert.IsNotNull(BundleResult);
        Assert.IsNotNull(BundleResult.Entry);
        Assert.AreEqual(1, BundleResult.Entry.Count);
        Assert.AreEqual(ObsOneResourceId, BundleResult.Entry[0].Resource.Id);        
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Search: " + Exec.Message);
      }

      CleanUpByIdentifier(ResourceType.Observation);
    }
コード例 #12
0
    public void Test_CaseSensitive_FHIR_Id()
    {
      CleanUpByIdentifier(ResourceType.Patient);

      Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
      clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).
      
      //Add a Patient resource by Update
      Patient PatientOne = new Patient();
      string PatientOneResourceId = Guid.NewGuid().ToString().ToLower();
      PatientOne.Id = PatientOneResourceId;
      string PatientOneFamilyName = "TestPatientOne";
      PatientOne.Name.Add(HumanName.ForFamily(PatientOneFamilyName).WithGiven("Test"));
      PatientOne.BirthDateElement = new Date("1979-09-30");
      string PatientOneMRNIdentifer = Guid.NewGuid().ToString();
      PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, PatientOneMRNIdentifer));
      PatientOne.Gender = AdministrativeGender.Unknown;

      Patient PatientResult = null;
      try
      {
        PatientResult = clientFhir.Update(PatientOne);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.NotNull(PatientResult, "Resource create by Updated returned resource of null");      
      PatientResult = null;


      //Add a Patient resource by Update
      Patient PatientTwo = new Patient();
      string PatientTwoResourceId = PatientOneResourceId.ToUpper();
      PatientTwo.Id = PatientTwoResourceId;
      string PatientTwoFamilyName = "TestPatientTwo";
      PatientTwo.Name.Add(HumanName.ForFamily(PatientTwoFamilyName).WithGiven("Test"));
      PatientTwo.BirthDateElement = new Date("1979-09-30");
      string PatientTwoMRNIdentifer = Guid.NewGuid().ToString();
      PatientTwo.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, PatientOneMRNIdentifer));
      PatientTwo.Gender = AdministrativeGender.Unknown;

      PatientResult = null;
      try
      {
        PatientResult = clientFhir.Update(PatientTwo);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.NotNull(PatientResult, "Resource create by Updated returned resource of null");      
      PatientResult = null;

      Bundle SearchResult = null;
      try
      {
        SearchResult = clientFhir.SearchById<Patient>(PatientOneResourceId);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.AreEqual(1, SearchResult.Entry.Count);
      Assert.AreEqual(PatientOneFamilyName, (SearchResult.Entry[0].Resource as Patient).Name[0].Family);

      SearchResult = null;
      try
      {
        SearchResult = clientFhir.SearchById<Patient>(PatientTwoResourceId);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
      }
      Assert.AreEqual(1, SearchResult.Entry.Count);
      Assert.AreEqual(PatientTwoFamilyName, (SearchResult.Entry[0].Resource as Patient).Name[0].Family);

      //--- Clean Up ---------------------------------------------------------
      //Clean up by deleting all Test Patients
      SearchParams sp = new SearchParams().Where($"identifier={StaticTestData.TestIdentiferSystem}|");
      try
      {
        clientFhir.Delete("Patient", sp);
      }
      catch (Exception Exec)
      {
        Assert.True(false, "Exception thrown on conditional delete of resource Patient: " + Exec.Message);
      }

    }
コード例 #13
0
        public void Test_ConditionalUpdate()
        {
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

            // Prepare 3 test patients
            Patient p1       = new Patient();
            string  TestPat1 = Guid.NewGuid().ToString();

            p1.Id = TestPat1;
            p1.Name.Add(HumanName.ForFamily("Postlethwaite").WithGiven("Brian"));
            p1.BirthDateElement = new Date("1970-01");
            p1.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "1"));
            var r1 = clientFhir.Update(p1);

            Patient p2       = new Patient();
            string  TestPat2 = Guid.NewGuid().ToString();

            p2.Id = TestPat2;
            p2.Name.Add(HumanName.ForFamily("Portlethwhite").WithGiven("Brian"));
            p2.BirthDateElement = new Date("1970-01");
            p2.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "1"));
            var r2 = clientFhir.Update(p2);

            Patient p3       = new Patient();
            string  TestPat3 = Guid.NewGuid().ToString();

            p3.Id = TestPat3;
            p3.Name.Add(HumanName.ForFamily("Dole").WithGiven("Bob"));
            p3.BirthDateElement = new Date("1957-01");
            p3.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "1"));
            var r3 = clientFhir.Update(p3);


            // Test the conditional update now
            // Try to update Bob Doles data
            Patient p3a = new Patient();

            p3a.Name.Add(HumanName.ForFamily("Dole").WithGiven("Bob"));
            p3a.BirthDateElement = new Date("1957-01-12");
            p3a.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "1"));
            SearchParams sp  = new SearchParams().Where("name=Dole").Where("birthdate=1957-01");
            var          r3a = clientFhir.Update(p3a, sp);

            Assert.AreEqual(TestPat3, r3a.Id, "pat3 should have been updated (not a new one created)");
            Assert.AreEqual("1957-01-12", r3a.BirthDate, "Birth date should have been updated");

            // Try to update Brian's data (which has multuple rows!)
            Patient p1a = new Patient();

            p1a.Name.Add(HumanName.ForFamily("Postlethwaite").WithGiven("Brian"));
            p1a.BirthDateElement = new Date("1970-02");
            p1a.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "1"));
            sp = new SearchParams().Where("identifier=1");
            try
            {
                var r1a = clientFhir.Update(p1a, sp);
                Assert.Fail("This identifier is used multiple times, the conditional update should have failed");
            }
            catch (FhirOperationException ex)
            {
                Assert.AreEqual(System.Net.HttpStatusCode.PreconditionFailed, ex.Status, "Expected failure of the update due to a pre-condition check");
            }

            // Try to update Bob Doles data with incorrect id
            Patient p3b = new Patient();

            p3b.Id = "NotTheCorrectId";
            p3b.Name.Add(HumanName.ForFamily("Dole").WithGiven("Bob"));
            p3b.BirthDateElement = new Date("1957-01-01");
            p3b.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "1"));
            try
            {
                var r3b = clientFhir.Update(p3b, sp);
                Assert.Fail("This identifier given in the resource Update does not match the Id in the resource located by search.");
            }
            catch (FhirOperationException ex)
            {
                Assert.AreEqual(System.Net.HttpStatusCode.PreconditionFailed, ex.Status, "Expected failure of the update due to a pre-condition check");
            }

            // Try to update New Patient resource where search returns zero hits and Resource is created occurs
            Patient p4 = new Patient();

            p4.Name.Add(HumanName.ForFamily("Dole4").WithGiven("John"));
            p4.BirthDateElement = new Date("1957-01-01");
            p4.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "2"));
            sp = new SearchParams().Where("identifier=http://TestingSystem.org/id|2");
            Patient r4 = null;

            try
            {
                r4 = clientFhir.Update(p4, sp);
            }
            catch (FhirOperationException ex)
            {
                Assert.True(false, "Update p4 failed" + ex.Message);
            }


            //Clean up by deleting all resources created while also testing Conditional Delete many
            sp = new SearchParams().Where("identifier=http://TestingSystem.org/id|");
            try
            {
                clientFhir.Delete("Patient", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource G: " + Exec.Message);
            }
        }
コード例 #14
0
        public void Test_PUT_IfMatch()
        {
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

            //Best to have this clean up here as things can get out of
            //synch with the database when debugging.
            //We always need a clean db to start run.
            var sp = new SearchParams().Where("identifier=http://TestingSystem.org/id|");

            try
            {
                clientFhir.Delete("Patient", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource G: " + Exec.Message);
            }

            string         PatientOneId       = string.Empty;
            string         PatientOneVersion  = string.Empty;
            DateTimeOffset?PatientOneModified = null;

            // Prepare Patient
            Patient PatientOne     = new Patient();
            string  TestPatIfMatch = Guid.NewGuid().ToString();

            PatientOne.Id = TestPatIfMatch;
            PatientOne.Name.Add(HumanName.ForFamily("IfMatch0").WithGiven("Test0"));
            PatientOne.BirthDateElement = new Date("1970-01");
            PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "AF28B8ED-B81A-41D4-96DE-9012ED1868BD"));

            Patient ResultOne = null;

            try
            {
                ResultOne          = clientFhir.Update(PatientOne);
                PatientOneId       = ResultOne.Id;
                PatientOneVersion  = ResultOne.VersionId;
                PatientOneModified = ResultOne.Meta.LastUpdated;
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
            }

            ResultOne.Name.Clear();
            ResultOne.Name.Add(HumanName.ForFamily("IfMatch1").WithGiven("Test1"));

            Patient ResultTwo = null;

            try
            {
                //Perform a Version aware update that should be successfully. This uses "if-match" HTTP Header.
                ResultTwo = clientFhir.Update(ResultOne, true);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
            }

            //Increment the last returned resource's version by one and then attempt a version aware update.
            //This should fail with a HTTP Error '409 Conflict'
            ResultTwo.VersionId = (Convert.ToInt32(ResultTwo.VersionId) + 1).ToString();
            Patient ResultThree = null;

            try
            {
                ResultThree = clientFhir.Update(ResultTwo, true);
            }
            catch (FhirOperationException execOper)
            {
                Assert.AreEqual(System.Net.HttpStatusCode.Conflict, execOper.Status, "Did not get Http status 409 Conflict on incorrect Version aware update.");
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on Version aware update: " + Exec.Message);
            }

            //Clean up by deleting all Test Patients
            sp = new SearchParams().Where("identifier=http://TestingSystem.org/id|");
            try
            {
                clientFhir.Delete("Patient", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource G: " + Exec.Message);
            }
        }
コード例 #15
0
        public void Test_ConditionalRead()
        {
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

            string         PatientOneId       = string.Empty;
            string         PatientOneVersion  = string.Empty;
            DateTimeOffset?PatientOneModified = null;

            // Prepare 3 test patients
            Patient PatientOne = new Patient();

            string TestPat1 = Guid.NewGuid().ToString();

            PatientOne.Id = TestPat1;
            PatientOne.Name.Add(HumanName.ForFamily("FhirMan").WithGiven("Sam"));
            PatientOne.BirthDateElement = new Date("1970-01");
            PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "6"));

            Patient ResultOne = null;

            try
            {
                ResultOne          = clientFhir.Update(PatientOne);
                PatientOneId       = ResultOne.Id;
                PatientOneVersion  = ResultOne.VersionId;
                PatientOneModified = ResultOne.Meta.LastUpdated;
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on resource Get: " + Exec.Message);
            }


            Patient PatientTwo = null;

            try
            {
                //Resource has not changed so should return a 304 Not Modified
                PatientTwo = clientFhir.Read <Patient>($"{StaticTestData.FhirEndpoint()}/Patient/{PatientOneId}", PatientOneVersion, PatientOneModified);
                Assert.Fail("Conditional Read is expected to throw an exception due to bug in FHIR .NET API");
            }
            catch (FhirOperationException ExecOp)
            {
                //Catch the error and check it is a 304 http status.
                Assert.True(true, "FhirOperationException should be thrown on resource Read: " + ExecOp.Message);
                Assert.IsTrue(ExecOp.Status.IsRedirection());
            }

            PatientTwo         = null;
            PatientOneModified = PatientOneModified.Value.AddMinutes(-1);
            try
            {
                //If-Modified-Since has been pushed back 1 min so we should get a resource back this time
                PatientTwo = clientFhir.Read <Patient>($"{StaticTestData.FhirEndpoint()}/Patient/{PatientOneId}", PatientOneVersion, PatientOneModified);
                Assert.NotNull(PatientTwo, "Not Resource returned when 1 min subtracted from last-modified on Conditional Read.");
                //reset the PatientOneModified
                PatientOneModified = PatientTwo.Meta.LastUpdated;
            }
            catch (FhirOperationException ExecOp)
            {
                Assert.True(false, "FhirOperationException thrown on resource Read: " + ExecOp.Message);
                Assert.IsTrue(ExecOp.Status.IsRedirection());
            }

            PatientTwo        = null;
            PatientOneVersion = "xxxxx";
            try
            {
                //If-None-Match version has been set to not match so we should get a resource back this time
                PatientTwo = clientFhir.Read <Patient>($"{StaticTestData.FhirEndpoint()}/Patient/{PatientOneId}", PatientOneVersion, PatientOneModified);
                Assert.NotNull(PatientTwo, "Not Resource returned when Resource Version did not match active resource Version on Conditional Read.");
            }
            catch (FhirOperationException ExecOp)
            {
                Assert.True(false, "FhirOperationException thrown on resource Read: " + ExecOp.Message);
            }

            //Clean up by deleting all Test Patients
            var sp = new SearchParams().Where("identifier=" + StaticTestData.TestIdentiferSystem + "|");

            try
            {
                clientFhir.Delete("Patient", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource G: " + Exec.Message);
            }
        }
コード例 #16
0
        public void Test_ConditionalCreate()
        {
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 600; // give the call a while to execute (particularly while debugging).
            string TempResourceVersion = string.Empty;
            string TempResourceId      = string.Empty;

            //Best to have this clean up here as things can get out of
            //synch with the database when debugging.
            //We always need a clean db to start run.
            var sp = new SearchParams().Where("identifier=http://TestingSystem.org/id|");

            try
            {
                clientFhir.Delete("Patient", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource G: " + Exec.Message);
            }


            // Prepare test patient
            Patient PatientOne = new Patient();

            PatientOne.Name.Add(HumanName.ForFamily("FhirMan").WithGiven("Sam"));
            PatientOne.BirthDateElement = new Date("1970-01");
            PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "5"));

            SearchParams SearchParams = new SearchParams().Where("identifier=5");

            try
            {
                var ResultOne = clientFhir.Create(PatientOne, SearchParams);
                TempResourceId      = ResultOne.Id;
                TempResourceVersion = ResultOne.VersionId;
            }
            catch (FhirOperationException execOper)
            {
                Assert.Fail("Exception was thrown on Condition Create, message was: " + execOper.Message);
            }

            try
            {
                //This will return status OK but does not commit the resource and therefore
                //does not increment the resource version number
                clientFhir.Create(PatientOne, SearchParams);
            }
            catch (FhirOperationException execOper)
            {
                Assert.Fail("Exception was thrown on Condition Create, message was: " + execOper.Message);
            }

            try
            {
                //This will return status OK but does not commit the resource and therefore
                //does not increment the resource version number
                var PatientResult = (Patient)clientFhir.Get($"{StaticTestData.FhirEndpoint()}/Patient/{TempResourceId}");
                Assert.AreEqual(TempResourceVersion, PatientResult.VersionId, "The Version Id was not correct post Conditional Create when Resource was found.");
            }
            catch (FhirOperationException execOper)
            {
                Assert.Fail("Exception was thrown on Condition Create get operation, message was: " + execOper.Message);
            }


            // Create another Patient with the same name
            Patient PatientTwo = new Patient();

            PatientTwo.Name.Add(HumanName.ForFamily("FhirMan").WithGiven("Sam"));
            PatientTwo.BirthDateElement = new Date("1970-01");
            PatientTwo.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "6"));
            try
            {
                var ResultTwo = clientFhir.Create(PatientTwo);
            }
            catch (FhirOperationException execOper)
            {
                Assert.Fail("Exception was thrown on Condition Create, message was: " + execOper.Message);
            }

            //Now try an Create another again with a search on the Name
            //This should fail as it will resolve to many resource
            Patient PatientThree = new Patient();

            PatientThree.Name.Add(HumanName.ForFamily("FhirMan").WithGiven("Sam"));
            PatientThree.BirthDateElement = new Date("1970-01");
            PatientThree.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, "7"));
            SearchParams = new SearchParams().Where("family=FhirMan").Where("given=Sam");
            try
            {
                var ResultThree = clientFhir.Create(PatientTwo, SearchParams);
                Assert.IsNull(ResultThree, "ResultThree should be null as the ConditionaCreate search parameters should find many resource");
            }
            catch (FhirOperationException execOper)
            {
                Assert.AreEqual(System.Net.HttpStatusCode.PreconditionFailed, execOper.Status, "Did not get Http status 412 when resolving against many resources on ConditionalCreate");
            }



            //Clean up by deleting all resources created while also testing Conditional Delete many
            sp = new SearchParams().Where("identifier=http://TestingSystem.org/id|");
            try
            {
                clientFhir.Delete("Patient", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource G: " + Exec.Message);
            }
        }