Esempio n. 1
0
        public void TestFhirDelete()
        {
            ResourceIdentity identity1 = ResourceIdentity.Build("Observation", "1");
            ResourceIdentity identity2 = ResourceIdentity.Build("Observation", "2");

            fhirClient.Delete(identity1);
            fhirClient.Delete(identity2);

            try
            {
                fhirClient.Read <Observation>(baseUrl + "/Observation/1");
                Assert.Fail();
            }
            catch (FormatException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Observation with id 1 has been deleted!"));
            }

            try
            {
                fhirClient.Read <Observation>(baseUrl + "/Observation/2");
                Assert.Fail();
            }
            catch (FormatException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Observation with id 2 has been deleted!"));
            }
        }
        public void WhenResourceDeleted()
        {
            var createdModel = _fhirClient.Create(_observation);

            _fhirClient.Delete(createdModel);

            AssertHelper.CheckDeleteStatusCode(_fhirClient.LastResult.Status);
        }
Esempio n. 3
0
        public void CreateEditDelete()
        {
            var furore = new Organization
            {
                Name       = "Furore",
                Identifier = new List <Identifier> {
                    new Identifier("http://hl7.org/test/1", "3141")
                },
                Telecom = new List <Contact> {
                    new Contact {
                        System = Contact.ContactSystem.Phone, Value = "+31-20-3467171"
                    }
                }
            };

            FhirClient client = new FhirClient(testEndpoint);
            var        tags   = new List <Tag> {
                new Tag("http://nu.nl/testname", "TestCreateEditDelete")
            };

            var fe = client.Create(furore, tags);

            Assert.IsNotNull(furore);
            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.SelfLink);
            Assert.AreNotEqual(fe.Id, fe.SelfLink);
            Assert.IsNotNull(fe.Tags);
            Assert.AreEqual(1, fe.Tags.Count());
            Assert.AreEqual(fe.Tags.First(), tags[0]);
            createdTestOrganization = fe.Id;

            fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));

            var fe2 = client.Update(fe);

            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.SelfLink, fe2.SelfLink);
            Assert.IsNotNull(fe2.Tags);
            Assert.AreEqual(1, fe2.Tags.Count());
            Assert.AreEqual(fe2.Tags.First(), tags[0]);

            client.Delete(fe2.Id);

            try
            {
                fe = client.Read <Organization>(ResourceLocation.GetIdFromResourceId(fe.Id));
                Assert.Fail();
            }
            catch
            {
                Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.Gone);
            }

            Assert.IsNull(fe);
        }
Esempio n. 4
0
        /// <summary>
        /// Delete a patient, specified by id
        /// </summary>
        /// <param name="fhirClient"></param>
        /// <param name="id"></param>
        static void DeletePatient(
            FhirClient fhirClient,
            string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            System.Console.WriteLine($"Deleting patient {id}");
            fhirClient.Delete($"Patient/{id}");
        }
Esempio n. 5
0
        public void CreateEditDelete()
        {
            var furore = new Organization
            {
                Name = "Furore",
                Identifier = new List<Identifier> { new Identifier("http://hl7.org/test/1", "3141") },
                Telecom = new List<Contact> { new Contact { System = Contact.ContactSystem.Phone, Value = "+31-20-3467171" } }
            };

            FhirClient client = new FhirClient(testEndpoint);
            var tags = new List<Tag> { new Tag("http://nu.nl/testname", Tag.FHIRTAGNS, "TestCreateEditDelete") };

            var fe = client.Create(furore,tags);

            Assert.IsNotNull(furore);
            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.SelfLink);
            Assert.AreNotEqual(fe.Id,fe.SelfLink);
            Assert.IsNotNull(fe.Tags);
            Assert.AreEqual(1, fe.Tags.Count());
            Assert.AreEqual(fe.Tags.First(), tags[0]);
            createdTestOrganization = fe.Id;

            fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));

            var fe2 = client.Update(fe);

            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.SelfLink, fe2.SelfLink);
            Assert.IsNotNull(fe2.Tags);
            Assert.AreEqual(1, fe2.Tags.Count());
            Assert.AreEqual(fe2.Tags.First(), tags[0]);

            client.Delete(fe2.Id);

            try
            {
                fe = client.Read<Organization>(ResourceLocation.GetIdFromResourceId(fe.Id));
                Assert.Fail();
            }
            catch
            {
                Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.Gone);
            }

            Assert.IsNull(fe);
        }
        public void CreateEditDelete()
        {
            FhirClient client = new FhirClient(testEndpoint);

            client.OnBeforeRequest += Compression_OnBeforeRequestZipOrDeflate;
            // client.CompressRequestBody = true;

            var pat = client.Read <Patient>("Patient/example");

            pat.Id = null;
            pat.Identifier.Clear();
            pat.Identifier.Add(new Identifier("http://hl7.org/test/2", "99999"));

            var fe = client.Create(pat); // Create as we are not providing the ID to be used.

            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.Meta.VersionId);
            createdTestPatientUrl = fe.ResourceIdentity();

            fe.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
            var fe2 = client.Update(fe);

            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.ResourceIdentity(), fe2.ResourceIdentity());
            Assert.AreEqual(2, fe2.Identifier.Count);

            fe.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
            var fe3 = client.Update(fe);

            Assert.IsNotNull(fe3);
            Assert.AreEqual(3, fe3.Identifier.Count);

            client.Delete(fe3);

            try
            {
                // Get most recent version
                fe = client.Read <Patient>(fe.ResourceIdentity().WithoutVersion());
                Assert.Fail();
            }
            catch (FhirOperationException ex)
            {
                Assert.AreEqual(HttpStatusCode.Gone, ex.Status); //"410"
            }
        }
Esempio n. 7
0
        public void CreateEditDelete()
        {
            FhirClient client = new FhirClient(testEndpoint);
            var        pat    = client.Read <Patient>("Patient/example");

            pat.Id = null;
            pat.Identifier.Clear();
            pat.Identifier.Add(new Identifier("http://hl7.org/test/2", "99999"));

            var fe = client.Create(pat); // Create as we are not providing the ID to be used.

            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.Meta.VersionId);
            createdTestPatientUrl = fe.ResourceIdentity();

            fe.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
            var fe2 = client.Update(fe);

            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.ResourceIdentity(), fe2.ResourceIdentity());
            Assert.AreEqual(2, fe2.Identifier.Count);

            fe.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
            var fe3 = client.Update(fe);

            Assert.IsNotNull(fe3);
            Assert.AreEqual(3, fe3.Identifier.Count);

            client.Delete(fe3);

            try
            {
                // Get most recent version
                fe = client.Read <Patient>(fe.ResourceIdentity().WithoutVersion());
                Assert.Fail();
            }
            catch
            {
                Assert.AreEqual("410", client.LastResult.Status);
            }
        }
Esempio n. 8
0
        public void CreateEditDelete()
        {
            var pat = (Patient)FhirParser.ParseResourceFromXml(File.ReadAllText(@"TestData\TestPatient.xml"));
            var key = new Random().Next();

            pat.Id = "NetApiCRUDTestPatient" + key;

            FhirClient client = new FhirClient(testEndpoint);

            var fe = client.Create(pat);

            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.Meta.VersionId);
            createdTestPatientUrl = fe.ResourceIdentity();

            fe.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
            var fe2 = client.Update(fe);

            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.ResourceIdentity(), fe2.ResourceIdentity());
            Assert.AreEqual(2, fe2.Identifier.Count);

            fe.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
            var fe3 = client.Update(fe);

            Assert.IsNotNull(fe3);
            Assert.AreEqual(3, fe3.Identifier.Count);

            client.Delete(fe3);

            try
            {
                // Get most recent version
                fe = client.Read <Patient>(fe.ResourceIdentity().WithoutVersion());
                Assert.Fail();
            }
            catch
            {
                Assert.IsTrue(client.LastResult.Status == HttpStatusCode.Gone.ToString());
            }
        }
Esempio n. 9
0
        public static void DeletePatient(Patient patient)
        {
            try
            {
                LogToFile("Delete Patient");

                LogToFile("Request: ");
                var patientXml = FhirSerializer.SerializeResourceToXml(patient);
                LogToFile(XDocument.Parse(patientXml).ToString());

                FhirClient fhirClient = new FhirClient(FhirClientEndPoint);
                fhirClient.Delete(patient);

                LogToFile("Response: Delete has no response");
            }
            catch (Exception ex)
            {
                LogToFile(ex.ToString());
            }
        }
Esempio n. 10
0
        public static void DeletePatientByEndPoint(string patientId)
        {
            try
            {
                UriBuilder uriBuilder = new UriBuilder(FhirClientEndPoint + "Patient/" + patientId);

                LogToFile("Delete Patient");

                LogToFile("Request: ");
                LogToFile(uriBuilder.Uri.ToString());

                FhirClient fhirClient = new FhirClient(FhirClientEndPoint);
                fhirClient.Delete(uriBuilder.Uri);

                LogToFile("Response: Delete has no response");
            }
            catch (Exception ex)
            {
                LogToFile(ex.ToString());
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Value search parameters for this search are:
        /// [_id, _language, active, address, address-city, address-country, address-postalcode, address-state, address-use,
        /// animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given,
        /// identifier, language, link, name, organization, phone, phonetic, telecom]
        /// </summary>
        /// <param name="patient"></param>
        public static void DeletePatientBySearchParams(Patient patient)
        {
            try
            {
                LogToFile("Delete Patient");

                LogToFile("Request: ");
                var patientXml = FhirSerializer.SerializeResourceToXml(patient);
                LogToFile(XDocument.Parse(patientXml).ToString());

                FhirClient fhirClient = new FhirClient(FhirClientEndPoint);

                SearchParams searchParams = new SearchParams();
                searchParams.Add("_id", patient.Id);

                fhirClient.Delete("Patient", searchParams);

                LogToFile("Response: Delete has no response");
            }
            catch (Exception ex)
            {
                LogToFile(ex.ToString());
            }
        }
Esempio n. 12
0
        public void ManipulateMeta()
        {
           FhirClient client = new FhirClient(testEndpoint);
           var pat = FhirParser.ParseResourceFromXml(File.ReadAllText(@"TestData\TestPatient.xml"));
           var key = new Random().Next();
           pat.Id = "NetApiMetaTestPatient" + key;

           var meta = new Meta();
           meta.ProfileElement.Add(new FhirUri("http://someserver.org/fhir/Profile/XYZ1-" + key));
           meta.Security.Add(new Coding("http://mysystem.com/sec", "1234-" + key));
           meta.Tag.Add(new Coding("http://mysystem.com/tag", "sometag1-" + key));
           pat.Meta = meta;

          //Before we begin, ensure that our new tags are not actually used when doing System Meta()
          var wsm = client.Meta();
          Assert.IsFalse(wsm.Meta.Profile.Contains("http://someserver.org/fhir/Profile/XYZ1-" + key));
          Assert.IsFalse(wsm.Meta.Security.Select(c => c.Code + "@" + c.System).Contains("1234-" + key + "@http://mysystem.com/sec"));
          Assert.IsFalse(wsm.Meta.Tag.Select(c => c.Code + "@" + c.System).Contains("sometag1-" + key + "@http://mysystem.com/tag"));

          Assert.IsFalse(wsm.Meta.Profile.Contains("http://someserver.org/fhir/Profile/XYZ2-" + key));
          Assert.IsFalse(wsm.Meta.Security.Select(c => c.Code + "@" + c.System).Contains("5678-" + key + "@http://mysystem.com/sec"));
          Assert.IsFalse(wsm.Meta.Tag.Select(c => c.Code + "@" + c.System).Contains("sometag2-" + key + "@http://mysystem.com/tag"));


          // First, create a patient with the first set of meta
          var pat2 = client.Create(pat);
          var loc = pat2.ResourceIdentity(testEndpoint);          

          // Meta should be present on created patient
          verifyMeta(pat2.Meta, false,key);

          // Should be present when doing instance Meta()
          var par = client.Meta(loc);
          verifyMeta(par.Meta, false,key);

          // Should be present when doing type Meta()
          par = client.Meta(ResourceType.Patient);
          verifyMeta(par.Meta, false,key);

          // Should be present when doing System Meta()
          par = client.Meta();
          verifyMeta(par.Meta, false,key);

          // Now add some additional meta to the patient

          var newMeta = new Meta();
          newMeta.ProfileElement.Add(new FhirUri("http://someserver.org/fhir/Profile/XYZ2-" + key));
          newMeta.Security.Add(new Coding("http://mysystem.com/sec", "5678-" + key));
          newMeta.Tag.Add(new Coding("http://mysystem.com/tag", "sometag2-" + key));       

          
          client.AddMeta(loc, newMeta);
          var pat3 = client.Read<Patient>(loc);

          // New and old meta should be present on instance
          verifyMeta(pat3.Meta, true, key);

          // New and old meta should be present on Meta()
          par = client.Meta(loc);
          verifyMeta(par.Meta, true, key);

          // New and old meta should be present when doing type Meta()
          par = client.Meta(ResourceType.Patient);
          verifyMeta(par.Meta, true, key);

          // New and old meta should be present when doing system Meta()
          par = client.Meta();
          verifyMeta(par.Meta, true, key);

          // Now, remove those new meta tags
          client.DeleteMeta(loc, newMeta);

          // Should no longer be present on instance
          var pat4 = client.Read<Patient>(loc);
          verifyMeta(pat4.Meta, false, key);

          // Should no longer be present when doing instance Meta()
          par = client.Meta(loc);
          verifyMeta(par.Meta, false, key);

          // Should no longer be present when doing type Meta()
          par = client.Meta(ResourceType.Patient);
          verifyMeta(par.Meta, false, key);

          // clear out the client that we created, no point keeping it around
          client.Delete(pat4);

          // Should no longer be present when doing System Meta()
          par = client.Meta();
          verifyMeta(par.Meta, false, key);
        }
Esempio n. 13
0
        public void CreateEditDelete()
        {
            var pat = (Patient)FhirParser.ParseResourceFromXml(File.ReadAllText(@"TestData\TestPatient.xml"));
            var key = new Random().Next();
            pat.Id = "NetApiCRUDTestPatient" + key;

            FhirClient client = new FhirClient(testEndpoint);

            var fe = client.Create(pat);
            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.Meta.VersionId);
            createdTestPatientUrl = fe.ResourceIdentity();

            fe.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
            var fe2 = client.Update(fe);

            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.ResourceIdentity(), fe2.ResourceIdentity());
            Assert.AreEqual(2, fe2.Identifier.Count);

            fe.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
            var fe3 = client.Update(fe);
            Assert.IsNotNull(fe3);
            Assert.AreEqual(3, fe3.Identifier.Count);

            client.Delete(fe3);

            try
            {
                // Get most recent version
                fe = client.Read<Patient>(fe.ResourceIdentity().WithoutVersion());
                Assert.Fail();
            }
            catch
            {
                Assert.IsTrue(client.LastResult.Status == HttpStatusCode.Gone.ToString());
            }
        }
Esempio n. 14
0
        public void CreateEditDelete()
        {
            FhirClient client = new FhirClient(testEndpoint);
            var pat = client.Read<Patient>("Patient/example");
            pat.Id = null;
            pat.Identifier.Clear();
            pat.Identifier.Add(new Identifier("http://hl7.org/test/2", "99999"));

            var fe = client.Create(pat);
            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.Meta.VersionId);
            createdTestPatientUrl = fe.ResourceIdentity();

            fe.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
            var fe2 = client.Update(fe);

            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.ResourceIdentity(), fe2.ResourceIdentity());
            Assert.AreEqual(2, fe2.Identifier.Count);

            fe.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
            var fe3 = client.Update(fe);
            Assert.IsNotNull(fe3);
            Assert.AreEqual(3, fe3.Identifier.Count);

            client.Delete(fe3);

            try
            {
                // Get most recent version
                fe = client.Read<Patient>(fe.ResourceIdentity().WithoutVersion());
                Assert.Fail();
            }
            catch
            {
                Assert.IsTrue(client.LastResult.Status == "410");
            }
        }
        public void ManipulateMeta()
        {
            FhirClient client = new FhirClient(testEndpoint);

            var pat = new Patient();

            pat.Meta = new Meta();
            var key = new Random().Next();

            pat.Meta.ProfileElement.Add(new FhirUri("http://someserver.org/fhir/StructureDefinition/XYZ1-" + key));
            pat.Meta.Security.Add(new Coding("http://mysystem.com/sec", "1234-" + key));
            pat.Meta.Tag.Add(new Coding("http://mysystem.com/tag", "sometag1-" + key));

            //Before we begin, ensure that our new tags are not actually used when doing System Meta()
            var wsm = client.Meta();

            Assert.IsNotNull(wsm);

            Assert.IsFalse(wsm.Profile.Contains("http://someserver.org/fhir/StructureDefinition/XYZ1-" + key));
            Assert.IsFalse(wsm.Security.Select(c => c.Code + "@" + c.System).Contains("1234-" + key + "@http://mysystem.com/sec"));
            Assert.IsFalse(wsm.Tag.Select(c => c.Code + "@" + c.System).Contains("sometag1-" + key + "@http://mysystem.com/tag"));

            Assert.IsFalse(wsm.Profile.Contains("http://someserver.org/fhir/StructureDefinition/XYZ2-" + key));
            Assert.IsFalse(wsm.Security.Select(c => c.Code + "@" + c.System).Contains("5678-" + key + "@http://mysystem.com/sec"));
            Assert.IsFalse(wsm.Tag.Select(c => c.Code + "@" + c.System).Contains("sometag2-" + key + "@http://mysystem.com/tag"));


            // First, create a patient with the first set of meta
            var pat2 = client.Create(pat);
            var loc  = pat2.ResourceIdentity(testEndpoint);

            // Meta should be present on created patient
            verifyMeta(pat2.Meta, false, key);

            // Should be present when doing instance Meta()
            var par = client.Meta(loc);

            verifyMeta(par, false, key);

            // Should be present when doing type Meta()
            par = client.Meta(ResourceType.Patient);
            verifyMeta(par, false, key);

            // Should be present when doing System Meta()
            par = client.Meta();
            verifyMeta(par, false, key);

            // Now add some additional meta to the patient

            var newMeta = new Meta();

            newMeta.ProfileElement.Add(new FhirUri("http://someserver.org/fhir/StructureDefinition/XYZ2-" + key));
            newMeta.Security.Add(new Coding("http://mysystem.com/sec", "5678-" + key));
            newMeta.Tag.Add(new Coding("http://mysystem.com/tag", "sometag2-" + key));


            client.AddMeta(loc, newMeta);
            var pat3 = client.Read <Patient>(loc);

            // New and old meta should be present on instance
            verifyMeta(pat3.Meta, true, key);

            // New and old meta should be present on Meta()
            par = client.Meta(loc);
            verifyMeta(par, true, key);

            // New and old meta should be present when doing type Meta()
            par = client.Meta(ResourceType.Patient);
            verifyMeta(par, true, key);

            // New and old meta should be present when doing system Meta()
            par = client.Meta();
            verifyMeta(par, true, key);

            // Now, remove those new meta tags
            client.DeleteMeta(loc, newMeta);

            // Should no longer be present on instance
            var pat4 = client.Read <Patient>(loc);

            verifyMeta(pat4.Meta, false, key);

            // Should no longer be present when doing instance Meta()
            par = client.Meta(loc);
            verifyMeta(par, false, key);

            // Should no longer be present when doing type Meta()
            par = client.Meta(ResourceType.Patient);
            verifyMeta(par, false, key);

            // clear out the client that we created, no point keeping it around
            client.Delete(pat4);

            // Should no longer be present when doing System Meta()
            par = client.Meta();
            verifyMeta(par, false, key);
        }
Esempio n. 16
0
        public void CreateEditDelete()
        {
            var furore = new Organization
            {
                Name       = "Furore",
                Identifier = new List <Identifier> {
                    new Identifier("http://hl7.org/test/1", "3141")
                },
                Telecom = new List <Contact> {
                    new Contact {
                        System = Contact.ContactSystem.Phone, Value = "+31-20-3467171"
                    }
                }
            };

            FhirClient client = new FhirClient(testEndpoint);
            var        tags   = new List <Tag> {
                new Tag("http://nu.nl/testname", Tag.FHIRTAGSCHEME_GENERAL, "TestCreateEditDelete")
            };

            var fe = client.Create <Organization>(furore, tags: tags, refresh: true);

            Assert.IsNotNull(furore);
            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.SelfLink);
            Assert.AreNotEqual(fe.Id, fe.SelfLink);
            Assert.IsNotNull(fe.Tags);
            Assert.AreEqual(1, fe.Tags.Count(), "Tag count on new organization record don't match");
            Assert.AreEqual(fe.Tags.First(), tags[0]);
            createdTestOrganizationUrl = fe.Id;

            fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
            var fe2 = client.Update(fe, refresh: true);

            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.SelfLink, fe2.SelfLink);
            Assert.AreEqual(2, fe2.Resource.Identifier.Count);

            Assert.IsNotNull(fe2.Tags);
            Assert.AreEqual(1, fe2.Tags.Count(), "Tag count on updated organization record don't match");
            Assert.AreEqual(fe2.Tags.First(), tags[0]);

            fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
            var fe3 = client.Update(fe2.Id, fe.Resource, refresh: true);

            Assert.IsNotNull(fe3);
            Assert.AreEqual(3, fe3.Resource.Identifier.Count);

            client.Delete(fe3);

            try
            {
                // Get most recent version
                fe = client.Read <Organization>(new ResourceIdentity(fe.Id));
                Assert.Fail();
            }
            catch
            {
                Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.Gone);
            }
        }
        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);
            }
        }
Esempio n. 18
0
 public ActionResult Delete(int id)
 {
     client.Delete("Person/" + id);
     return(NoContent());
 }
Esempio n. 19
0
        public void CreateEditDelete()
        {
            var furore = new Organization
            {
                Name = "Furore",
                Identifier = new List<Identifier> { new Identifier("http://hl7.org/test/1", "3141") },
                Telecom = new List<Contact> { new Contact { System = Contact.ContactSystem.Phone, Value = "+31-20-3467171" } }
            };

            FhirClient client = new FhirClient(testEndpoint);
            var tags = new List<Tag> { new Tag("http://nu.nl/testname", Tag.FHIRTAGSCHEME_GENERAL, "TestCreateEditDelete") };

            var fe = client.Create<Organization>(furore, tags:tags, refresh: true);

            Assert.IsNotNull(furore);
            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.SelfLink);
            Assert.AreNotEqual(fe.Id, fe.SelfLink);
			Assert.IsNotNull(fe.Tags);
			Assert.AreEqual(1, fe.Tags.Count(), "Tag count on new organization record don't match");
			Assert.AreEqual(fe.Tags.First(), tags[0]);
			createdTestOrganizationUrl = fe.Id;

            fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
            var fe2 = client.Update(fe, refresh: true);
            
            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.SelfLink, fe2.SelfLink);
            Assert.AreEqual(2, fe2.Resource.Identifier.Count);

            Assert.IsNotNull(fe2.Tags);
			Assert.AreEqual(1, fe2.Tags.Count(), "Tag count on updated organization record don't match");
            Assert.AreEqual(fe2.Tags.First(), tags[0]);

            fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
            var fe3 = client.Update(fe2.Id, fe.Resource, refresh: true);
            Assert.IsNotNull(fe3);
            Assert.AreEqual(3, fe3.Resource.Identifier.Count);

            client.Delete(fe3);

            try
            {
                // Get most recent version
                fe = client.Read<Organization>(new ResourceIdentity(fe.Id));
                Assert.Fail();
            }
            catch
            {
                Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.Gone);
            }
        }