public ActionResult Index(Models.DeleteResourceViewModel model)
        {
            var  patientID = model.patientID;
            bool success   = false;

            try
            {
                //Create a client to send to the server at a given endpoint.
                var FhirClient = new Hl7.Fhir.Rest.FhirClient(OpenFHIRUrl);

                var ResourceDelete = ("/Patient/" + patientID);

                FhirClient.Delete(ResourceDelete);
                success = true;

                ViewBag.showData = success == true ? "Resource was deleted" : "Error while deleting the resource";
            }
            catch (FhirOperationException FhirOpExec)
            {
                var response     = FhirOpExec.Outcome;
                var errorDetails = fhirJsonSerializer.SerializeToString(response);
                ViewBag.showData = JValue.Parse(errorDetails).ToString();
            }
            catch (WebException ex)
            {
                var response = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
                var error    = JsonConvert.DeserializeObject(response);
                ViewBag.showData = error.ToString();
            }

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

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

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

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

            Server.Dispose();
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public void DeletePatient()
        {
            Patient p = new Patient();

            p.Name = new System.Collections.Generic.List <HumanName>();
            p.Name.Add(new HumanName().WithGiven("Grahame").AndFamily("Grieve"));
            p.BirthDate            = new DateTime(1970, 3, 1).ToFhirDate(); // yes there are extensions to convert to FHIR format
            p.Active               = true;
            p.ManagingOrganization = new ResourceReference("Organization/1", "Demo Org");

            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(_baseAddress, false);
            var result = clientFhir.Create <Patient>(p);

            Assert.IsNotNull(result.Id, "Newly created patient should have an ID");
            Assert.IsNotNull(result.Meta, "Newly created patient should have an Meta created");
            Assert.IsNotNull(result.Meta.LastUpdated, "Newly created patient should have the creation date populated");
            Assert.IsTrue(result.Active.Value, "The patient was created as an active patient");

            // Now delete the patient we just created
            clientFhir.Delete(result);
        }
Exemplo n.º 5
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 = new Patient();

            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;
            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.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()));


            //--- Clean Up ---------------------------------------------------------
            //Clean up by deleting all Test Patients
            SearchParams 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 Patient: " + Exec.Message);
            }

            //Clean up by deleting all Test Organization
            sp = new SearchParams().Where("identifier=http://TestingSystem.org/id|");
            try
            {
                clientFhir.Delete("Organization", sp);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on conditional delete of resource Organization: " + Exec.Message);
            }
        }
Exemplo n.º 6
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.");
      }

    }
Exemplo n.º 7
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);
      }

    }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
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);
            }
        }