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());
        }
示例#2
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);
      
    }
示例#3
0
        public void GetCapabilityStatement()
        {
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(_baseAddress, false);
            var result = clientFhir.CapabilityStatement();

            Assert.IsNotNull(result, "Should be a capability statement returned");
            Assert.IsNotNull(result.FhirVersion, "Should at least report the version of fhir active");
        }
示例#4
0
        private FhirClient GetClient(string accessToken)
        {
            var client = new Hl7.Fhir.Rest.FhirClient(_configuration["Authentication:Microsoft:Resource"]);

            client.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) =>
            {
                e.RawRequest.Headers.Add("Authorization", $"Bearer {accessToken}");
            };
            client.PreferredFormat = ResourceFormat.Json;
            return(client);
        }
示例#5
0
        public static FhirClient GetClientAsync(string accessToken)
        {
            var client = new Hl7.Fhir.Rest.FhirClient(_fhirServerUrl);

            client.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) =>
            {
                e.RawRequest.Headers.Add("Authorization", $"Bearer {accessToken}");
            };
            client.PreferredFormat = ResourceFormat.Json;
            return(client);
        }
        public ActionResult UpdateResource(Models.UpdateResourceViewModel model)
        {
            try
            {
                var patientID = model.patientID;

                //Create a client to send to the server at a given endpoint.
                var FhirClient     = new Hl7.Fhir.Rest.FhirClient(OpenFHIRUrl);
                var ResourceUpdate = ("/Patient/" + patientID);

                //Reading the data at the given location("URL")
                model.patientRead = FhirClient.Read <Patient>(ResourceUpdate);

                //using Json serializer to get the data in Json format
                FhirJsonSerializer fhirJsonSerializer = new FhirJsonSerializer();

                //Serializing the existing patient
                string oldDetails = fhirJsonSerializer.SerializeToString(model.patientRead);
                model.patientDetailsOld = JValue.Parse(oldDetails).ToString();

                //Updating the changes to the existing Resource

                model.patientFullnameUpdate        = new HumanName();
                model.patientFullnameUpdate.Use    = HumanName.NameUse.Official;
                model.patientFullnameUpdate.Prefix = new string[] { model.patientPrefixUpdate };
                model.patientFullnameUpdate.Given  = new string[] { model.patientFirstnameUpdate };
                model.patientFullnameUpdate.Family = model.patientFamilyNameUpdate;
                model.patientRead.Name             = new List <HumanName>();
                model.patientRead.Name.Add(model.patientFullnameUpdate);
                model.patientRead.Gender    = model.patientGenderUpdate == "Male" ? AdministrativeGender.Male : AdministrativeGender.Female;
                model.patientRead.BirthDate = model.patientDateOfBirthUpdate;

                //Sending the updated changes to the endpoint
                model.patientupdate = FhirClient.Update <Patient>(model.patientRead);

                // Serializing the updated patient details
                string Updatedetails = fhirJsonSerializer.SerializeToString(model.patientupdate);
                model.patientDetailsUpdated = JValue.Parse(Updatedetails).ToString();
            }
            catch (FhirOperationException FhirOpExec)
            {
                var response     = FhirOpExec.Outcome;
                var errorDetails = fhirJsonSerializer.SerializeToString(response);
                model.ResourceRawJsonData = JValue.Parse(errorDetails).ToString();
            }
            catch (WebException ex)
            {
                var response = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
                var error    = JsonConvert.DeserializeObject(response);
                model.ResourceRawJsonData = error.ToString();
            }

            return(View(model));
        }
示例#7
0
        private Hl7.Fhir.Rest.FhirClient GetClient()
        {
            var    client = new Hl7.Fhir.Rest.FhirClient(Configuration["FhirServerUrl"]);
            string token  = null;           // await _easyAuthProxy.GetAadAccessToken();

            client.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) =>
            {
                e.RawRequest.Headers.Add("Authorization", $"Bearer {token}");
            };
            client.PreferredFormat = ResourceFormat.Json;
            return(client);
        }
示例#8
0
        public static FhirClient CreateClientConnection(IConfiguration _configuration)
        {
            //The fhir server end point address
            string ServiceRootUrl = _configuration["FhirServerUrl"];
            //Create a client to send to the server at a given endpoint.
            var FhirClient = new Hl7.Fhir.Rest.FhirClient(ServiceRootUrl);

            // increase timeouts since the server might be powered down
            FhirClient.Timeout = Convert.ToInt32(_configuration["FhirClientTimeout"]);

            return(FhirClient);
        }
示例#9
0
        public void WholeSystemHistory()
        {
            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(_baseAddress, false);

            // Create a Patient
            Patient p = new Patient();

            p.Id   = "pat1"; // if you support this format for the IDs (client allocated ID)
            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/2", "Other Org");
            clientFhir.Update(p);

            // Create an Organization
            Organization org = new Organization();

            org.Id   = "2";
            org.Name = "Other Org";
            clientFhir.Update(org);

            // Load the whole history
            var result = clientFhir.WholeSystemHistory();

            Console.WriteLine($"Total All Resources: {result.Total}");
            foreach (var item in result.Entry)
            {
                Console.WriteLine($"{item.FullUrl}");
            }

            Assert.IsNotNull(result.Total, "There should be a total count");
            Assert.IsNotNull(result.Meta, "History Bundle should have an Meta created");
            Assert.IsNotNull(result.Meta.LastUpdated, "History Bundle should have the creation date populated");
            Assert.IsTrue(result.Total.Value > 0, "Should be at least 1 item in the history");
            Assert.AreEqual(result.Total.Value, result.Entry.Count, "Should be matching total and entry counts");

            // Load the Organization type history
            var resultOrgs = clientFhir.TypeHistory <Organization>();

            Console.WriteLine($"Total Org Resources: {resultOrgs.Total}");
            foreach (var item in resultOrgs.Entry)
            {
                Console.WriteLine($"{item.FullUrl}");
            }

            Assert.IsNotNull(resultOrgs.Total, "There should be a total count");
            Assert.IsNotNull(resultOrgs.Meta, "History Bundle should have an Meta created");
            Assert.IsNotNull(resultOrgs.Meta.LastUpdated, "History Bundle should have the creation date populated");
            Assert.IsTrue(resultOrgs.Total.Value > 0, "Should be at least 1 item in the history");
            Assert.AreEqual(resultOrgs.Total.Value, resultOrgs.Entry.Count, "Should be matching total and entry counts");
            Assert.IsTrue(resultOrgs.Total.Value < result.Total.Value, "Should be less orgs than the whole system entry count");
        }
示例#10
0
        public Hl7.Fhir.Model.Patient FHIR_SearchByIdentifier(ref Patient_FHIR pf)
        {
            string Identifier = pf.Identifier;

            Hl7.Fhir.Model.Patient patient = new  Hl7.Fhir.Model.Patient();
            var client = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint_PatientInfo);

            client.PreferredFormat = ResourceFormat.Json;
            Bundle bu = client.Search <Hl7.Fhir.Model.Patient> (new string[]
                                                                { "identifier=" + Identifier,
                                                                  "_revinclude=AllergyIntolerance:patient",
                                                                  "_revinclude=Condition:subject",
                                                                  "_revinclude=MedicationRequest:subject",
                                                                  "_revinclude=Immunization:patient",
                                                                  "_revinclude=CarePlan:subject" });

            foreach (Bundle.EntryComponent entry in bu.Entry)
            {
                string ResourceType = entry.Resource.TypeName;
                if (ResourceType == "Patient")
                {
                    patient = (Patient)entry.Resource;
                }
                else if (ResourceType == "AllergyIntolerance")
                {
                    var allergy = (AllergyIntolerance)entry.Resource;
                    pf.Allergies.Add(allergy);
                }
                else if (ResourceType == "Condition")
                {
                    var condition = (Condition)entry.Resource;
                    pf.Conditions.Add(condition);
                }
                else if (ResourceType == "MedicationRequest")
                {
                    var medication = (MedicationRequest)entry.Resource;
                    pf.Medications.Add(medication);
                }
                else if (ResourceType == "Immunization")
                {
                    var immunization = (Immunization)entry.Resource;
                    pf.Immunizations.Add(immunization);
                }
                else if (ResourceType == "CarePlan")
                {
                    var careplan = (CarePlan)entry.Resource;
                    pf.CarePlans.Add(careplan);
                }
            }
            return(patient);
        }
示例#11
0
        public Hl7.Fhir.Model.Patient GetPatientByBusId(string patientId)
        {
            var srvConfig     = _integrationServicesConfiguration.GetConfigurationService(IntegrationServicesConfiguration.ConfigurationServicesName.BUS);
            var baseUrl       = srvConfig.BaseURL;
            var getPatientUrl = srvConfig.GetEndPoint(IntegrationService.ConfigurationEndPointName.PATIENT_GET).URL + $"/{patientId}";

            var client = new Hl7.Fhir.Rest.FhirClient(baseUrl);

            client.OnBeforeRequest += OnBeforeRequestFhirServer;
            client.OnAfterResponse += OnAfterResponseFhirServer;

            var ret = client.Read <Hl7.Fhir.Model.Patient>(getPatientUrl);

            return(ret);
        }
示例#12
0
        public System.Collections.Generic.List <Hl7.Fhir.Model.Immunization> FHIR_SearchImmunizations(string PatientId)
        {
            System.Collections.Generic.List <Hl7.Fhir.Model.Immunization> Ms = new System.Collections.Generic.List <Hl7.Fhir.Model.Immunization>();
            var client = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint_PatientInfo);

            client.PreferredFormat = ResourceFormat.Json;
            Bundle bu = client.Search <Hl7.Fhir.Model.Immunization> (new string[]
                                                                     { "patient=" + PatientId });

            foreach (Bundle.EntryComponent ent in bu.Entry)
            {
                Immunization m = (Immunization)ent.Resource;
                Ms.Add(m);
            }
            return(Ms);
        }
        public static OperationOutcome ValidateCreate(this FhirClient client, DomainResource resource, FhirUri profile = null)
        {
            if (resource == null)
            {
                throw Error.ArgumentNull("resource");
            }

            var par = new Parameters().Add("resource", resource).Add("mode", new Code("create"));

            if (profile != null)
            {
                par.Add("profile", profile);
            }

            return(expect <OperationOutcome>(client.TypeOperation(Operation.VALIDATE_RESOURCE, resource.TypeName, par)));
        }
        public static async Task <OperationOutcome> ValidateCreateAsync(this FhirClient client, DomainResource resource, FhirUri profile = null)
        {
            if (resource == null)
            {
                throw Error.ArgumentNull(nameof(resource));
            }

            var par = new Parameters().Add("resource", resource).Add("mode", new Code("create"));

            if (profile != null)
            {
                par.Add("profile", profile);
            }

            return(OperationResult <OperationOutcome>(await client.TypeOperationAsync(RestOperation.VALIDATE_RESOURCE, resource.TypeName, par).ConfigureAwait(false)));
        }
示例#15
0
        public System.Collections.Generic.List <Hl7.Fhir.Model.AllergyIntolerance> FHIR_SearchAllergies(string PatientId)
        {
            System.Collections.Generic.List <Hl7.Fhir.Model.AllergyIntolerance> As = new System.Collections.Generic.List <Hl7.Fhir.Model.AllergyIntolerance>();
            var client = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint_PatientInfo);

            client.PreferredFormat = ResourceFormat.Json;
            Bundle bu = client.Search <Hl7.Fhir.Model.AllergyIntolerance> (new string[]
                                                                           { "patient=" + PatientId });

            foreach (Bundle.EntryComponent ent in bu.Entry)
            {
                AllergyIntolerance a = (AllergyIntolerance)ent.Resource;
                As.Add(a);
            }
            return(As);
        }
        public static Parameters ConceptLookup(this FhirClient client, Coding coding, FhirDateTime date = null)
        {
            if (coding == null)
            {
                throw Error.ArgumentNull("coding");
            }

            var par = new Parameters();

            par.Add("coding", coding);
            if (date != null)
            {
                par.Add("date", date);
            }

            return(expect <Parameters>(client.TypeOperation <ValueSet>(Operation.CONCEPT_LOOKUP, par)));
        }
示例#17
0
        public void CreatePatient()
        {
            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");
        }
示例#18
0
        public static Results ExpandValueSet(string valueset, string filter)
        {
            Results returnValueSet = new Results();

            switch (valueset)
            {
            case "top-2000-lab-observations-us":
                var client = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint_LOINC);

                client.OnBeforeRequest += (object msender, BeforeRequestEventArgs mer) =>
                {
                    mer.RawRequest.Headers.Add("Authorization", "Basic " + "YWJoaWppdGd1bGFiOiFJbmRpYW5hMDAx");
                };

                var response = client.ExpandValueSet(ResourceIdentity.Build("ValueSet", valueset), filter: new FhirString(filter));
                var ValueSet = response.Expansion.Contains.Select(vs => new Result {
                    id = vs.Code, text = vs.Display
                });
                returnValueSet.results = ValueSet;
                break;

            case "ucum":
                var clientRest = new RestClient(FHIR_EndPoint_UCUM);
                var request    = new RestRequest("/ValueSet/ucum/$expand", Method.GET);
                request.AddQueryParameter("filter", filter);
                request.AddQueryParameter("_format", "json");
                var responseJson = clientRest.Execute(request).Content;

                //var result = JsonConvert.DeserializeObject<ValueSet>(responseJson);
                var      parser = new Hl7.Fhir.Serialization.FhirJsonParser();
                ValueSet result = parser.Parse <ValueSet>(responseJson);
                ValueSet = result.Expansion.Contains.Select(vs => new Result {
                    id = vs.Code, text = vs.Display
                });
                returnValueSet.results = ValueSet;
                break;

            default:
                returnValueSet.results = new List <Result>();
                break;
            }

            return(returnValueSet);
        }
        private void SearchAllergies(string PatientId)
        {
            WorkingMessage();
            listAllergies.Items.Clear();
            string FHIR_EndPoint = this.txtFHIREndpoint.Text.ToString();
            var    client        = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint);

            try
            {
                var p = new Hl7.Fhir.Rest.SearchParams();
                p.Add("patient", PatientId);

                var results = client.Search <AllergyIntolerance>(p);
                this.UseWaitCursor   = false;
                lblErrorMessage.Text = "";
                while (results != null)
                {
                    if (results.Total == 0)
                    {
                        lblErrorMessage.Text = "No allergies found";
                    }

                    foreach (var entry in results.Entry)
                    {
                        var    Alrgy   = (AllergyIntolerance)entry.Resource;
                        string Content = Alrgy.Code.Coding[0].Display
                                         + " / " + Alrgy.VerificationStatus.Coding[0].Code
                                         + " (" + Alrgy.ClinicalStatus.Coding[0].Code + ")";
                        listAllergies.Items.Add(Content);
                    }
                    // get the next page of results
                    results = client.Continue(results);
                }
            }
            catch (Exception err)
            {
                lblErrorMessage.Text = "Error:" + err.Message.ToString();
            }
            if (lblErrorMessage.Text != "")
            {
                lblErrorMessage.Visible = true;
            }
        }
示例#20
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);
            }
        }
        public static ValueSet ExpandValueSet(this FhirClient client, ValueSet vs, FhirString filter = null, FhirDateTime date = null)
        {
            if (vs == null)
            {
                throw Error.ArgumentNull("vs");
            }

            var par = new Parameters().Add("valueSet", vs);

            if (filter != null)
            {
                par.Add("filter", filter);
            }
            if (date != null)
            {
                par.Add("date", date);
            }

            return(expect <ValueSet>(client.TypeOperation <ValueSet>(Operation.EXPAND_VALUESET, par)));
        }
        public static Parameters Validate(this FhirClient client, String valueSetId, FhirUri system, Code code, FhirString display = null)
        {
            if (code == null)
            {
                throw new ArgumentNullException("code");
            }
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }

            var par = new Parameters().Add("code", code).Add("system", system);

            if (display != null)
            {
                par.Add("display", display);
            }

            return(validateCodeForValueSetId(client, valueSetId, par));
        }
        public static ValueSet ExpandValueSet(this FhirClient client, FhirUri identifier, FhirString filter = null, FhirDateTime date = null)
        {
            if (identifier == null)
            {
                throw Error.ArgumentNull("identifier");
            }

            var par = new Parameters();

            par.Add("identifier", identifier);
            if (filter != null)
            {
                par.Add("filter", filter);
            }
            if (date != null)
            {
                par.Add("date", date);
            }

            return(expect <ValueSet>(client.TypeOperation <ValueSet>(EXPAND_VALUESET, par)));
        }
        public static async Task <ValueSet> ExpandValueSetAsync(this FhirClient client, ValueSet vs, FhirString filter = null, FhirDateTime date = null)
        {
            if (vs == null)
            {
                throw Error.ArgumentNull(nameof(vs));
            }

            var par = new Parameters().Add("valueSet", vs);

            if (filter != null)
            {
                par.Add("filter", filter);
            }
            if (date != null)
            {
                par.Add("date", date);
            }

            return((await client.TypeOperationAsync <ValueSet>(RestOperation.EXPAND_VALUESET, par).ConfigureAwait(false))
                   .OperationResult <ValueSet>());
        }
        public static OperationOutcome ValidateUpdate(this FhirClient client, DomainResource resource, string id, FhirUri profile = null)
        {
            if (id == null)
            {
                throw Error.ArgumentNull("id");
            }
            if (resource == null)
            {
                throw Error.ArgumentNull("resource");
            }

            var par = new Parameters().Add("resource", resource).Add("mode", new Code("update"));

            if (profile != null)
            {
                par.Add("profile", profile);
            }

            var loc = ResourceIdentity.Build(resource.TypeName, id);

            return(expect <OperationOutcome>(client.InstanceOperation(loc, Operation.VALIDATE_RESOURCE, par)));
        }
        public static ValueSet ExpandValueSet(this FhirClient client, Uri valueset, FhirString filter = null, FhirDateTime date = null)
        {
            if (valueset == null)
            {
                throw Error.ArgumentNull("valuesetLocation");
            }

            var par = new Parameters();

            if (filter != null)
            {
                par.Add("filter", filter);
            }
            if (date != null)
            {
                par.Add("date", date);
            }

            ResourceIdentity id = new ResourceIdentity(valueset);

            return(expect <ValueSet>(client.InstanceOperation(id.WithoutVersion().MakeRelative(), Operation.EXPAND_VALUESET, par)));
        }
        public static async Task <OperationOutcome> ValidateUpdateAsync(this FhirClient client, DomainResource resource, string id, FhirUri profile = null)
        {
            if (id == null)
            {
                throw Error.ArgumentNull(nameof(id));
            }
            if (resource == null)
            {
                throw Error.ArgumentNull(nameof(resource));
            }

            var par = new Parameters().Add("resource", resource).Add("mode", new Code("update"));

            if (profile != null)
            {
                par.Add("profile", profile);
            }

            var loc = ResourceIdentity.Build(resource.TypeName, id);

            return(OperationResult <OperationOutcome>(await client.InstanceOperationAsync(loc, RestOperation.VALIDATE_RESOURCE, par).ConfigureAwait(false)));
        }
        public static async Task <ValueSet> ExpandValueSetAsync(this FhirClient client, Uri valueset, FhirString filter = null, FhirDateTime date = null)
        {
            if (valueset == null)
            {
                throw Error.ArgumentNull(nameof(valueset));
            }

            var par = new Parameters();

            if (filter != null)
            {
                par.Add("filter", filter);
            }
            if (date != null)
            {
                par.Add("date", date);
            }

            ResourceIdentity id = new ResourceIdentity(valueset);

            return((await client.InstanceOperationAsync(id.WithoutVersion().MakeRelative(), RestOperation.EXPAND_VALUESET, par).ConfigureAwait(false))
                   .OperationResult <ValueSet>());
        }
示例#29
0
        public void ReadPatient()
        {
            Patient p = new Patient();

            p.Id   = "pat1"; // if you support this format for the IDs (client allocated ID)
            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/2", "Other Org");

            Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(_baseAddress, false);
            var result = clientFhir.Update <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");

            // read the record to check that it can be loaded
            result = clientFhir.Read <Patient>("Patient/pat1");
            Assert.AreEqual(p.Id, 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");

            try
            {
                var p4 = clientFhir.Read <Patient>("Patient/missing-client-id");
                Assert.Fail("Should have received an exception running this");
            }
            catch (Hl7.Fhir.Rest.FhirOperationException ex)
            {
                // This was the expected outcome
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
        public static Parameters ConceptLookup(this FhirClient client, Code code, FhirUri system, FhirString version = null, FhirDateTime date = null)
        {
            if (code == null)
            {
                throw Error.ArgumentNull("code");
            }
            if (system == null)
            {
                throw Error.ArgumentNull("system");
            }

            var par = new Parameters().Add("code", code).Add("system", system);

            if (version != null)
            {
                par.Add("version", version);
            }
            if (date != null)
            {
                par.Add("date", date);
            }

            return(expect <Parameters>(client.TypeOperation <ValueSet>(Operation.CONCEPT_LOOKUP, par)));
        }