public void TestOperationEverything()
        {
            FhirClient client = new FhirClient(testEndpoint)
            {
                UseFormatParam  = true,
                PreferredFormat = ResourceFormat.Json
            };

            // GET operation $everything without parameters
            var loc = client.TypeOperation <Patient>("everything", null, true);

            Assert.IsNotNull(loc);

            // POST operation $everything without parameters
            loc = client.TypeOperation <Patient>("everything", null, false);
            Assert.IsNotNull(loc);

            // GET operation $everything with 1 parameter
            // This doesn't work yet. When an operation is used with primitive types then those parameters must be appended to the url as query parameters.
            // loc = client.TypeOperation<Patient>("everything", new Parameters().Add("start", new Date(2017, 10)), true);
            // Assert.IsNotNull(loc);

            // POST operation $everything with 1 parameter
            loc = client.TypeOperation <Patient>("everything", new Parameters().Add("start", new Date(2017, 10)), false);
            Assert.IsNotNull(loc);
        }
Beispiel #2
0
        public ValueSet ExpandValueSet(string valueSetID)
        {
            valuesetIdParameter.Value = new FhirUri(valueSetID);

            var parameters = new Parameters
            {
                Parameter = new List <Parameters.ParameterComponent>
                {
                    valuesetIdParameter,
                }
            };

            return((ValueSet)client.TypeOperation <ValueSet>("expand", parameters));
        }
Beispiel #3
0
        static void TestExpand()
        {
            //var json = new WebClient().DownloadString("https://r4.ontoserver.csiro.au/fhir/ValueSet/$expand?url=http://snomed.info/sct?fhir_vs=ecl/%3C394658006");

            // http://snomed.info/sct?fhir_vs=ecl%2F%3C394658006&count=1000&activeOnly=true
            var client = new FhirClient(
                "https://r4.ontoserver.csiro.au/fhir/");

            var p = new Parameters()
                    .Add("url", new FhirUri("http://snomed.info/sct?fhir_vs=ecl/<394658006"))
                    .Add("count", new Integer(1000))
                    .Add("activeOnly", new FhirBoolean(true));
            var result = client.TypeOperation <ValueSet>("expand", p, true);
        }
        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);
            }
        }
Beispiel #5
0
        private List <string> GenerateDrugFilter()
        {
            var          ecl         = textBox2.Text;
            const string Endpoint    = "https://ontoserver.csiro.au/stu3-latest";
            string       ValueSetURL = "http://snomed.info/sct?fhir_vs=ecl/" + ecl;

            //ExpandECL for Box2
            var client = new FhirClient(Endpoint);
            var url    = new FhirUri(ValueSetURL);
            var result = client.ExpandValueSet(url);

            var ids = new List <string>();

            foreach (var item in result.Expansion.Contains)
            {
                ids.Add(item.Code);
            }

            var translations = new List <string>();

            foreach (var id in ids)
            {
                //Reverse Translate
                var revsertTranslateParameters = new Parameters
                {
                    Parameter = new List <Parameters.ParameterComponent>
                    {
                        new Parameters.ParameterComponent
                        {
                            Name  = "url",
                            Value = new FhirUri("http://snomed.info/sct?fhir_cm=281000036105")
                        },
                        new Parameters.ParameterComponent
                        {
                            Name  = "system",
                            Value = new FhirUri("http://snomed.info/sct")
                        },
                        new Parameters.ParameterComponent
                        {
                            Name  = "code",
                            Value = new FhirString(id)
                        },
                        new Parameters.ParameterComponent
                        {
                            Name  = "target",
                            Value = new FhirUri("http://snomed.info/sct")
                        },
                        new Parameters.ParameterComponent
                        {
                            Name  = "reverse",
                            Value = new FhirBoolean(true)
                        }
                    }
                };


                var transResult = (Parameters)client.TypeOperation <ConceptMap>("translate", revsertTranslateParameters);
                //if there's a map
                //if (transResult.Parameter[0].Value.Equals("true"))
                //{
                foreach (var match in transResult.Parameter.Where <Parameters.ParameterComponent>(e => e.Name == "match"))
                {
                    //var coding = match.Part.Where<Parameters.ParameterComponent>(e => e.Name == "concept");
                    //This workds
                    //var coding1 = match.Part[1].Value;
                    var valueCoding = match.Part.Where <Parameters.ParameterComponent>(p => p.Name.Equals("concept")).FirstOrDefault();

                    var coding = (Coding)valueCoding.Value;

                    translations.Add(coding.Code);
                }
                //}
            }

            //Expand the AMT ingredients
            string AMT_ecl = "http://snomed.info/sct?fhir_vs=ecl/<<30425011000036101:<<762951001=(";


            foreach (var item in translations)
            {
                AMT_ecl = AMT_ecl + item + " OR ";
            }
            //close the expression
            AMT_ecl = AMT_ecl + "123456 OR 123456)";

            var AMT_url = new FhirUri(AMT_ecl);
            var AMTs    = client.ExpandValueSet(AMT_url);

            var filtered = new List <string>();

            foreach (var item in AMTs.Expansion.Contains)
            {
                filtered.Add(item.Code);
            }


            return(filtered);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var client = new FhirClient(Endpoint);
            //var filter = new FhirString("inr");
            var url    = new FhirUri(ValueSetURL);
            var result = client.ExpandValueSet(url);

            Console.WriteLine(result.Expansion.Total + " results total");
            Console.WriteLine(result.Expansion.Contains.FirstOrDefault().Display);

            //var dict = VStoDictionary(result);


            Console.WriteLine("Let's try translate!");
            #region TRANSLATE
            var revsertTranslateParameters = new Parameters
            {
                Parameter = new List <Parameters.ParameterComponent>
                {
                    new Parameters.ParameterComponent
                    {
                        Name  = "url",
                        Value = new FhirUri("http://snomed.info/sct?fhir_cm=281000036105")
                    },
                    new Parameters.ParameterComponent
                    {
                        Name  = "system",
                        Value = new FhirUri("http://snomed.info/sct")
                    },
                    new Parameters.ParameterComponent
                    {
                        Name  = "code",
                        Value = new FhirString("419442005")
                    },
                    new Parameters.ParameterComponent
                    {
                        Name  = "target",
                        Value = new FhirUri("http://snomed.info/sct")
                    },
                    new Parameters.ParameterComponent
                    {
                        Name  = "reverse",
                        Value = new FhirBoolean(true)
                    }
                }
            };

            var transResult = (Parameters)client.TypeOperation <ConceptMap>("translate", revsertTranslateParameters);

            //
            Console.WriteLine(transResult.Parameter.First().Name + " : " + transResult.Parameter.First().Value.ToString());

            foreach (var match in transResult.Parameter.Where <Parameters.ParameterComponent>(e => e.Name == "match"))
            {
                //var coding = match.Part.Where<Parameters.ParameterComponent>(e => e.Name == "concept");
                //This workds
                //var coding1 = match.Part[1].Value;
                var valueCoding = match.Part.Where <Parameters.ParameterComponent>(p => p.Name.Equals("concept")).FirstOrDefault();

                var coding = (Coding)valueCoding.Value;

                Console.WriteLine(coding.Code + " " + coding.Display);
            }
            #endregion TRANSLATE

            #region search
            var substanceECL    = "http://snomed.info/sct?fhir_vs=ecl/<<105590001";
            var resultSizeLimit = 5;
            var searchFilter    = "morphi";


            var Newresult = client.ExpandValueSet(new FhirUri(substanceECL), new FhirString(searchFilter));

            var x = Newresult.Expansion.Contains;
            foreach (var item in x)
            {
                Console.WriteLine(item.Code + " | " + item.Display);
            }


            #endregion search

            Console.WriteLine("Done");



            Console.ReadKey();
        }