public FhirResponse InstanceOperation(string type, string id, string operation, Parameters parameters)
        {
            Key key = Key.Create(type, id);
            switch(operation.ToLower())
            {
                case "meta": return service.ReadMeta(key);
                case "meta-add": return service.AddMeta(key, parameters);
                case "meta-delete":
                case "document":
                case "$everything": // patient

                default: return Respond.WithError(HttpStatusCode.NotFound, "Unknown operation");
            }
        }
Example #2
0
        public void MinGetOrderWithBarCode()
        {
            //задаём ссылки
            string patient = References.patient;
            string pract = References.practitioner;

            //задаём ресурсы
            Order order = (new SetData()).SetOrder(patient, pract, References.organization);
            DiagnosticOrder diagnosticOrder = (new SetData()).SetDiagnosticOrder_Min(patient, pract, References.encounter,
                                                                 null, null);
            //задаём Bundle
            Bundle b = (new SetData()).SetBundleOrder(order, diagnosticOrder, null, null, null, null, null, null, null);

            string s = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(b);
            IRestResponse resp = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir?_format=json", s);

            Newtonsoft.Json.JsonConvert.DeserializeObject(resp.Content).ToString();
            string target = order.Target.Reference;
            target = target.Substring(target.IndexOf('/') + 1, target.Length - target.IndexOf('/') - 1);
            string orderMis = order.Identifier[0].Value;

            Parameters a = new Parameters();
            a.Add("TargetCode", new FhirString(target));
            a.Add("OrderMisID", new FhirString(orderMis));

            string s2 = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(a);
            IRestResponse resp2 = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir/$getorder?_format=json", s2);

            //Проверка на то, что возвращается НЕ пустой ответ!
            Parameters respGet = (Parameters)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(resp2.Content);

            if (resp2.StatusCode != System.Net.HttpStatusCode.OK || respGet.Parameter.Count == 0)
                Assert.Fail(resp2.Content);
            Assert.Pass(resp2.Content);
        }
Example #3
0
 public static void AffixTags(this Resource target, Parameters parameters)
 {
     if (target.Meta == null) target.Meta = new Meta();
     Meta meta = parameters.ExtractMeta().FirstOrDefault();
     if (meta != null)
     {
         target.Meta.Tag = AffixTags(target.Meta, meta).ToList();
     }
     
 }
Example #4
0
 public SearchResults Search(Parameters parameters)
 {
     List<BsonValue> keys = CollectKeys(parameters.WhichFilter);
     int numMatches = keys.Count();
     //RecursiveInclude(parameters.Includes, keys);
     SearchResults results = KeysToSearchResults(keys.Take(parameters.Limit));
     //results.UsedCriteria = parameters.UsedHttpQuery();
     results.MatchCount = numMatches;
     return results;
 }
Example #5
0
        public void _GetResult()
        {
            //задаём ссылки
            string patient = References.patient;
            string pract = References.practitioner;

            //задаём ресурсы
            Order order = (new SetData()).SetOrder(patient, pract, References.organization);
            DiagnosticOrder diagnosticOrder = (new SetData()).SetDiagnosticOrder_Min(patient, pract, References.encounter,
                                                                 null, null);
            //задаём Bundle
            Bundle b = (new SetData()).SetBundleOrder(order, diagnosticOrder, null, null, null, null, null, null, null);

            string s = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(b);
            IRestResponse resp = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir?_format=json", s);
            Bundle requestResult = (Bundle)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(resp.Content);

            //задаём ссылки
            string id = requestResult.Entry[0].Resource.Id;
            string orderId = "Order/" + id;
            string diagnosticOrderId = "DiagnosticOrder/" + requestResult.Entry[1].Resource.Id;

            //задаём ресурсы
            OrderResponse orderResp = (new SetData()).SetOrderResponseInProgress(orderId, References.organization);
            DiagnosticReport diagRep = (new SetData()).SetDiagnosticReport(patient, pract, diagnosticOrderId);
            Observation observ = (new SetData()).SetObservation_BundleResult_Reason(pract);

            //задаём Bundle
            Bundle bRes = (new SetData()).SetBundleResult(orderResp, diagRep, observ, null);
            s = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(bRes);
            resp = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir?_format=json", s);

            Newtonsoft.Json.JsonConvert.DeserializeObject(resp.Content).ToString();
            string source = order.Identifier[0].Assigner.Reference;
            source = source.Substring(source.IndexOf('/') + 1, source.Length - source.IndexOf('/') - 1);
            string target = order.Target.Reference;
            target = target.Substring(target.IndexOf('/') + 1, target.Length - target.IndexOf('/') - 1);
            string orderMis = order.Identifier[0].Value;

            Parameters a = new Parameters();
            a.Add("SourceCode", new FhirString(source));
            a.Add("TargetCode", new FhirString(target));
            a.Add("OrderMisID", new FhirString(order.Identifier[0].Value));

            string s2 = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(a);
            IRestResponse resp2 = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir/$getresult?_format=json", s2);

            //Проверка на то, что возвращается НЕ пустой ответ!
            Parameters respGet = (Parameters)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(resp2.Content);

            if (resp2.StatusCode != System.Net.HttpStatusCode.OK || respGet.Parameter.Count == 0)
                Assert.Fail(resp2.Content);
            Assert.Pass(resp2.Content);
        }
        [TestMethod, Ignore] //Server throws error: Access violation at address 000000000129D56C in module 'FHIRServer.exe'. Read of address 0000000000000000
        public void InvokeTestPatientGetEverything()
        {
            var client = new FhirClient(testEndpoint);
            var start = new FhirDateTime(2014,11,1);
            var end = new FhirDateTime(2015,1,1);
            var par = new Parameters().Add("start", start).Add("end", end);
            var bundle = (Bundle)client.InstanceOperation(ResourceIdentity.Build("Patient", "1"), "everything", par);
            Assert.IsTrue(bundle.Entry.Any());

            var bundle2 = client.FetchPatientRecord(ResourceIdentity.Build("Patient","1"), start, end);
            Assert.IsTrue(bundle2.Entry.Any());
        }
Example #7
0
        public FhirResponse AddMeta(Key key, Parameters parameters)
        {
            Interaction interaction = store.Get(key);

            if (interaction == null)
            {
                return Respond.NotFound(key);
            }
            else if (interaction.IsDeleted())
            {
                return Respond.Gone(interaction);
            }

            interaction.Resource.AffixTags(parameters);
            Store(interaction);

            return Respond.WithMeta(interaction);
        }
Example #8
0
        public Parameters Guidance(Parameters input)
        {
            Parameters outputParameters = null;
            using (var outputFile = GetType().Assembly.GetManifestResourceStream("GuidanceEngine.Examples.guidance-operation-response-example-v2.xml"))
            //using (var outputFile = File.Open("bin\\Examples\\guidance-operation-response-example-v2.xml", FileMode.Open))
            {
                using (var outputReader = XmlReader.Create(outputFile))
                {
                    outputParameters = FhirParser.ParseResource(outputReader) as Parameters;
                }
            }

            if (outputParameters == null)
            {
                throw new InvalidOperationException("Could not parse output parameters.");
            }

            return outputParameters;
        }
Example #9
0
        public void GetInjectedStatus()
        {
            //задаём ссылки
            string patient = References.patient;
            string pract = References.practitioner;

            //задаём ресурсы
            Order order = (new SetData()).SetOrder(patient, pract, References.organization);
            DiagnosticOrder diagnosticOrder = (new SetData()).SetDiagnosticOrder_Min(patient, pract, References.encounter,
                                                                null, null);

            //задаём Bundle
            Bundle b = (new SetData()).SetBundleOrder(order, diagnosticOrder, null, null, null, null, null, null, null);

            string s = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(b);
            IRestResponse resp = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir?_format=json", s);
            Bundle p = (Bundle)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(resp.Content);

            //задаём ссылки
            string id = p.Entry[0].Resource.Id;
            string orderId = "Order/" + id;

            //задаём ресурсы
            OrderResponse orderResp = (new SetData()).SetOrderResponseRejected(orderId, References.organization);

            //задаём Bundle
            Bundle bRes = (new SetData()).SetBundleResult(orderResp, null, null, null);
            s = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(bRes);
            resp = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir?_format=json", s);

            Parameters a = new Parameters();
            a.Add("OrderId", new FhirString(id));

            string s2 = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(a);
            IRestResponse resp2 = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir/$getstatus?_format=json", s2);
            if (resp2.Content.Contains("Rejected"))
                Assert.Pass(resp2.Content);
            else
                NUnit.Framework.Assert.Fail(resp2.Content);
        }
 public TransactionBuilder ServerOperation(string name, Parameters parameters)
 {
     var path = newRestUrl().AddPath(OPERATIONPREFIX + name);
     return EndpointOperation(path, parameters);
 }
Example #11
0
        public void CreateAndFullRepresentation()
        {
            FhirClient client = new FhirClient(testEndpoint);
            client.ReturnFullResource = true;       // which is also the default

            var pat = client.Read<Patient>("Patient/example");
            ResourceIdentity ri = pat.ResourceIdentity().WithBase(client.Endpoint);
            pat.Id = null;
            pat.Identifier.Clear();
            var patC = client.Create<Patient>(pat);
            Assert.IsNotNull(patC);

            client.ReturnFullResource = false;
            patC = client.Create<Patient>(pat);

            Assert.IsNull(patC);

            if (client.LastBody != null)
            {
                var returned = client.LastBodyAsResource;
                Assert.IsTrue(returned is OperationOutcome);
            }

            // Now validate this resource
            client.ReturnFullResource = true;       // which is also the default
            Parameters p = new Parameters();
          //  p.Add("mode", new FhirString("create"));
            p.Add("resource", pat);
            OperationOutcome ooI = (OperationOutcome)client.InstanceOperation(ri.WithoutVersion(), "validate", p);
            Assert.IsNotNull(ooI);
        }
Example #12
0
        public TransactionBuilder ResourceOperation(string resourceType, string id, string vid, string name, Parameters parameters, bool useGet = false)
        {
            var path = newRestUrl().AddPath(resourceType, id);
            if(vid != null) path.AddPath(HISTORY, vid);
            path.AddPath(OPERATIONPREFIX + name);

            return EndpointOperation(path, parameters, useGet);
        }
Example #13
0
 public TransactionBuilder TypeOperation(string resourceType, string name, Parameters parameters, bool useGet = false)
 {
     var path = newRestUrl().AddPath(resourceType, OPERATIONPREFIX + name);
     return EndpointOperation(path,parameters, useGet);
 }
Example #14
0
        public TransactionBuilder EndpointOperation(RestUrl endpoint, string name, Parameters parameters, bool useGet = false)
        {          
            var path = new RestUrl(endpoint).AddPath(OPERATIONPREFIX + name);

            return EndpointOperation(path, parameters, useGet);
        }
Example #15
0
        public TransactionBuilder EndpointOperation(RestUrl endpoint, Parameters parameters, bool useGet = false)
        {
            var entry = newEntry(useGet ? Bundle.HTTPVerb.GET : Bundle.HTTPVerb.POST);
            entry.Resource = parameters;
            var path = new RestUrl(endpoint);
            addEntry(entry, path);

            return this;
        }
Example #16
0
 public static Parameters Parameters(Definitions definitions, string resource, string query)
 {
     ParameterFactory factory = new ParameterFactory(definitions, resource);
     Parameters parameters = new Parameters();
     parameters += factory.ResourceParameter();
     parameters += factory.CreateParametersFromHttpQuery(resource, query);
     return parameters;
 }
Example #17
0
 public static Parameters Parameters(Definitions definitions, string resource, IEnumerable<Tuple<string, string>> query)
 {
     ParameterFactory factory = new ParameterFactory(definitions, resource);
     Parameters parameters = new Parameters();
     parameters += factory.ResourceParameter();
     parameters += factory.CreateParameters(resource, query);
     return parameters;
 }
Example #18
0
 public static FhirResponse WithMeta(Meta meta)
 {
     Parameters parameters = new Parameters();
     parameters.Add(typeof(Meta).Name, meta);
     return Respond.WithResource(parameters);
 }
Example #19
0
 public static Search.Parameters Parameters(Definitions definitions, string resource, IEnumerable<Hl7.Fhir.Search.Criterium> criteria)
 {
     ParameterFactory factory = new ParameterFactory(definitions, resource);
     Parameters parameters = new Parameters();
     parameters += factory.ResourceParameter();
     parameters += factory.CreateParameters(resource, criteria);
     return parameters;
 }
Example #20
0
        public void GetStatusWithOrderId()
        {
            //задаём ссылки
            string patient = References.patient;
            string pract = References.practitioner;

            //задаём ресурсы
            Order order = (new SetData()).SetOrder(patient, pract, References.organization);
            DiagnosticOrder diagnosticOrder = (new SetData()).SetDiagnosticOrder_Min(patient, pract, References.encounter,
                                                                null, null);

            //задаём Bundle
            Bundle b = (new SetData()).SetBundleOrder(order, diagnosticOrder, null, null, null, null, null, null, null);

            string s = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(b);
            IRestResponse resp = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir?_format=json", s);

            Parameters a = new Parameters();
            a.Add("OrderId", new FhirString("99e4270e-a713-4fab-8ecf-e19161ece69c"));

            string s2 = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(a);
            IRestResponse resp2 = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir/$getstatus?_format=json", s2);

            if (resp2.Content.Contains("Requested"))
                Assert.Pass(resp2.Content);
            else
                NUnit.Framework.Assert.Fail(resp2.Content);
        }
Example #21
0
        public void MinGetStatusReceived()
        {
            //задаём ссылки
            string patient = References.patient;
            string pract = References.practitioner;

            //задаём ресурсы
            Order order = (new SetData()).SetOrder(patient, pract, References.organization);
            DiagnosticOrder diagnosticOrder = (new SetData()).SetDiagnosticOrder_Min(patient, pract, References.encounter,
                                                                 null, null);
            //задаём Bundle
            Bundle b = (new SetData()).SetBundleOrder(order, diagnosticOrder, null, null, null, null, null, null, null);

            string s = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(b);
            IRestResponse resp = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir?_format=json", s);
            Bundle p = (Bundle)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(resp.Content);

            //задаём ссылки
            string id = p.Entry[0].Resource.Id;
            string orderId = "Order/" + id;

            Newtonsoft.Json.JsonConvert.DeserializeObject(resp.Content).ToString();
            string target = order.Target.Reference;
            target = target.Substring(target.IndexOf('/') + 1, target.Length - target.IndexOf('/') - 1);
            string orderMis = order.Identifier[0].Value;

            Parameters a = new Parameters();
            a.Add("TargetCode", new FhirString(target));
            a.Add("OrderMisID", new FhirString(orderMis));

            string s2 = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(a);
            IRestResponse resp2 = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir/$getorder?_format=json", s2);

            //Проверка на то, что возвращается НЕ пустой ответ!
            Parameters respGet = (Parameters)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(resp2.Content);

            if (resp2.StatusCode != System.Net.HttpStatusCode.OK || respGet.Parameter.Count == 0)
                Assert.Fail(resp2.Content + " Это упал GetOrder");

            var startIndex = resp2.Content.IndexOf("DiagnosticOrder");
            var endIndex = resp2.Content.IndexOf("\"", startIndex);
            var mys = resp2.Content.Substring(startIndex, endIndex - startIndex);
            var client = new RestClient() { BaseUrl = new Uri("http://192.168.8.93:2223/fhir/" + mys) };
            var request = new RestRequest(Method.GET) { RequestFormat = DataFormat.Json };
            request.AddHeader("Authorization", "N3 f0a258e5-92e4-47d3-9b6c-89362357b2b3");
            IRestResponse respPractVersion = client.Execute(request);

            a = new Parameters();
            a.Add("OrderId", new FhirString(id));

            s2 = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(a);
            resp2 = (new Program()).RequestExec(Method.POST, "http://192.168.8.93:2223/fhir/$getstatus?_format=json", s2);

            if (resp2.Content.Contains("Received"))
                Assert.Pass(resp2.Content);
            else
                NUnit.Framework.Assert.Fail(resp2.Content);
        }
Example #22
0
 public FhirResponse ServerOperation(string operation, Parameters parameters)
 {
     switch(operation.ToLower())
     {
         case "guidance": return Respond.WithResource(engine.Guidance(parameters));
         case "error": throw new Exception("This error is for testing purposes");
         default: return Respond.WithError(HttpStatusCode.NotFound, "Unknown operation");
     }
 }
Example #23
0
        public static SearchParams FromParameters(Parameters parameters)
        {
            var result = new SearchParams();

            foreach (var parameter in parameters.Parameter)
            {
                var name = parameter.Name;
                var value = parameter.Value;
                
                if(value != null && value is Primitive)
                {
                    result.Add(parameter.Name, PrimitiveTypeConverter.ConvertTo<string>(value));
                }
                else
                    if (value == null) throw Error.NotSupported("Can only convert primitive parameters to Uri parameters");
            }

            return result;
        }
Example #24
0
 public SearchResults Search(Parameters parameters)
 {
     return searcher.Search(parameters);
 }
Example #25
0
        public Parameters ToParameters()
        {
            var result = new Parameters();

            foreach (var parameter in ToUriParamList())
            {
                result.Add(parameter.Item1, new FhirString(parameter.Item2));
            }

            return result;
        }
Example #26
0
        internal static Parameters CreateQueryResource()
        {
            // Create new parameter resource
            Parameters res = new Parameters();

            // Allocate the logical resource Id - this is what the resource is referenced by
            res.Id = "7cb73a48-090d-469a-a2b2-04f1e6b11ea2";

            // Add the profile for this resource (from the FGM DMS)
            Meta metadata = new Meta();
            metadata.Profile = new string[] { "urn:fhir.nhs.uk:profile/NHS-FGM-QueryParameters" };
            res.Meta = metadata;

            // Add the first query parameter, this will always be this value (from the FGM DMS)
            Parameters.ParametersParameterComponent p1 = new Parameters.ParametersParameterComponent();
            p1.Name = "RiskIndicator";
            p1.Value = new FhirString("FGM");
            res.Parameter.Add(p1);

            // Add the second query parameter, the patient's NHS Number (from the FGM DMS)
            Parameters.ParametersParameterComponent p2 = new Parameters.ParametersParameterComponent();
            p2.Name = "NHSNumber";
            p2.Value = new FhirString("9999999999");
            res.Parameter.Add(p2);

            return res;
        }
Example #27
0
 public static Parameters Parameters(Definitions definitions, string resource)
 {
     ParameterFactory factory = new ParameterFactory(definitions, resource);
     Parameters parameters = new Parameters();
     parameters += factory.ResourceParameter();
     return parameters;
 }