Пример #1
1
        public Bundle SetBundleResult(OrderResponse orderResp, DiagnosticReport diagReport, Observation observ, Practitioner pract)
        {
            Bundle bundle = new Bundle();
            bundle.Meta = new Meta() { Profile = new string[] { MetaBundleResult } };
            bundle.Entry = new List<Bundle.BundleEntryComponent>();
            if (orderResp != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = orderResp,
                    Transaction = new Bundle.BundleEntryTransactionComponent { Method = Bundle.HTTPVerb.POST, Url = "OrderResponse" }
                };
                bundle.Entry.Add(component);
            }
            if (diagReport != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = diagReport,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "DiagnosticReport" }
                };
                bundle.Entry.Add(component);
            }
            if (observ != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent()
                {
                    Resource = observ,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "Observation" }
                };
                bundle.Entry.Add(component);
            }
            //необязательный параметр
            if (pract != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = pract,
                    Transaction = new Bundle.BundleEntryTransactionComponent { Method = Bundle.HTTPVerb.POST, Url = "Practitioner" }
                };
                bundle.Entry.Add(component);
            }

            return bundle;
        }
Пример #2
0
        public static Bundle.BundleEntryComponent TranslateToSparseEntry(this Interaction interaction)
        {
            var entry = new Bundle.BundleEntryComponent();

            ConnectResource(interaction, entry);
            return entry;
        }
Пример #3
0
 public static void Append(this Bundle bundle, Resource resource)
 {
     var entry = new Bundle.BundleEntryComponent();
     entry.Resource = resource;
     entry.Base = bundle.Base;
     bundle.Entry.Add(entry);
 }
Пример #4
0
        private static Bundle.BundleEntryComponent CreateEntryForResource(Resource resource)
        {
            var entry = new Bundle.BundleEntryComponent();
            entry.Resource = resource;
//            entry.FullUrl = resource.ResourceIdentity().ToString();
            entry.FullUrl = resource.ExtractKey().ToUriString();
            return entry;
        }
        private Bundle.BundleEntryComponent newEntry(Bundle.HTTPVerb method)
        {
            var newEntry = new Bundle.BundleEntryComponent();
            newEntry.Transaction = new Bundle.BundleEntryTransactionComponent();
            newEntry.Transaction.Method = method;

            return newEntry;
        }
Пример #6
0
        private Bundle.BundleEntryComponent newEntry(Bundle.HTTPVerb method)
        {
            var newEntry = new Bundle.BundleEntryComponent();
            newEntry.Request = new Bundle.BundleEntryRequestComponent();
            newEntry.Request.Method = method;

            return newEntry;
        }
Пример #7
0
 public static void Append(this Bundle bundle, Bundle.HTTPVerb method, Resource resource)
 {
     var entry = new Bundle.BundleEntryComponent();
     entry.Resource = resource;
     entry.Base = bundle.Base;
     if (entry.Transaction == null) entry.Transaction = new Bundle.BundleEntryTransactionComponent();
     entry.Transaction.Method = method;
     bundle.Entry.Add(entry);
 }
Пример #8
0
        public static ResourceIdentity GetResourceLocation(this Bundle.BundleEntryComponent entry, string baseUrl = null)
        {
            if (entry.Resource == null)
            {
                return(null);
            }

            var url = entry.Base ?? baseUrl;

            return(entry.Resource.ResourceIdentity(url));
        }
Пример #9
0
        public static Bundle.BundleEntryComponent AddResourceEntry(this Bundle b, Resource r, string fullUrl)
        {
            var newEntry = new Bundle.BundleEntryComponent()
            {
                Resource = r, FullUrl = fullUrl
            };

            b.Entry.Add(newEntry);

            return(newEntry);
        }
Пример #10
0
        public static Bundle.BundleEntryComponent ToTransactionEntry(this Interaction interaction)
        {
            var entry = new Bundle.BundleEntryComponent();

            if (entry.Request == null)
            {
                entry.Request = new Bundle.BundleEntryRequestComponent();
            }
            entry.Request.Method = interaction.Method;
            entry.Request.Url = interaction.Key.ToUri().ToString();

            ConnectResource(interaction, entry);

            return entry;
        }
Пример #11
0
        internal static string BuildUrlForEntry(this Bundle.BundleEntryComponent entry, string baseUrl = null)
        {
            var url = entry.Base ?? baseUrl;

            if (url != null && !url.EndsWith("/"))
            {
                url += "/";
            }

            if (entry.Deleted != null)
            {
                return(url + entry.Deleted.Type + "/" + entry.Deleted.Id);
            }
            else
            {
                return(url + entry.Resource.TypeName + "/" + entry.Resource.Id);
            }
        }
        internal static Bundle.BundleEntryComponent ToBundleEntry(this HttpWebResponse response, byte[] body)
        {
            var result = new Bundle.BundleEntryComponent();

            result.Response = new Bundle.BundleEntryResponseComponent();
            result.Response.Status = ((int)response.StatusCode).ToString();
            result.Response.SetHeaders(response.Headers);

            var contentType = getContentType(response);
            var charEncoding = getCharacterEncoding(response);

            result.Response.Location = response.Headers[HttpUtil.LOCATION] ?? response.Headers[HttpUtil.CONTENTLOCATION];

#if PORTABLE45
            if (!String.IsNullOrEmpty(response.Headers[HttpUtil.LASTMODIFIED]))
                    result.Response.LastModified = DateTimeOffset.Parse(response.Headers[HttpUtil.LASTMODIFIED]);
#else
            result.Response.LastModified = response.LastModified;
#endif
            result.Response.Etag = getETag(response);                     

            if (body != null)
            {
                result.Response.SetBody(body);

                if (IsBinaryResponse(response.ResponseUri.OriginalString))
                    result.Resource = makeBinaryResource(body, contentType);
                else
                {
                    var bodyText = DecodeBody(body, charEncoding);
                    var resource = parseResource(bodyText, contentType);
                    result.Resource = resource;

                    if (result.Response.Location != null)
                        result.Resource.ResourceBase = new ResourceIdentity(result.Response.Location).BaseUri;
                }
            }

            return result;
        }
Пример #13
0
        public static bool IsTargetOf(this Bundle.BundleEntryComponent entry, string reference)
        {
            // From the spec: If the reference is version specific (either relative or absolute), then remove the version from the URL
            // before matching fullUrl, and then match the version based on Resource.meta.versionId.

            if (reference == null)
            {
                throw Error.ArgumentNull("reference");
            }
            if (!new Uri(reference, UriKind.RelativeOrAbsolute).IsAbsoluteUri)
            {
                throw Error.Argument("reference", "uri should be absolute");
            }

            string referencedVersion = ResourceIdentity.IsRestResourceIdentity(reference) ? (new ResourceIdentity(reference).VersionId) : null;

            reference = referencedVersion != null ? (new ResourceIdentity(reference).WithoutVersion().ToString()) : reference;
            var refRestUrl = new RestUrl(reference);

            return(refRestUrl.IsSameUrl(new RestUrl(entry.FullUrl)) &&
                   (referencedVersion == null || (entry.HasResource() && entry.Resource.VersionId == referencedVersion)));
        }
Пример #14
0
        public static Bundle.BundleEntryComponent TranslateToSparseEntry(this Interaction interaction)
        {
            var entry = new Bundle.BundleEntryComponent();

            if (interaction.HasResource())
            {
                entry.Resource = interaction.Resource;
                interaction.Key.ApplyTo(entry.Resource);
            }
            return entry;
        }
Пример #15
0
        public static Bundle.BundleEntryComponent ToTransactionEntry(this Interaction interaction)
        {
            var entry = new Bundle.BundleEntryComponent();

            if (entry.Transaction == null)
            {
                entry.Transaction = new Bundle.BundleEntryTransactionComponent();
            }
            entry.Transaction.Method = interaction.Method;
            entry.Transaction.Url = interaction.Key.ToUri().ToString();

            if (interaction.HasResource())
            {
                entry.Resource = interaction.Resource;
                interaction.Key.ApplyTo(entry.Resource);
            }

            return entry;
        }
Пример #16
0
 public static bool HasResource(this Bundle.BundleEntryComponent entry)
 {
     return(entry.Resource != null);
 }
Пример #17
0
 public static ResourceIdentity GetResourceLocation(this Bundle.BundleEntryComponent entry, string baseUrl = null)
 {
     return(entry.FullUrl != null ?  new ResourceIdentity(entry.FullUrl) : null);
 }
Пример #18
0
        public void BundleOrder_PutEncounter()
        {
            //задаём ссылки
            string patient = References.patient;
            string pract = References.practitioner;
            string enc = "b111e27a-7bb2-478d-8bc1-db08ad009c19";

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

            //Гетаем encounter, чтобы узнать VersionId
            var client = new RestClient() { BaseUrl = new Uri("http://192.168.8.93:2223/fhir/" + References.encounter) };
            var request = new RestRequest(Method.GET) { RequestFormat = DataFormat.Json };
            request.AddHeader("Authorization", "N3 f0a258e5-92e4-47d3-9b6c-89362357b2b3");
            IRestResponse respEncountVersion = client.Execute(request);

            // тут происходит магия (проблема с кодировкой)
            var encod = new UTF8Encoding(false).GetString(respEncountVersion.RawBytes, 3, respEncountVersion.RawBytes.Length - 3);
            Encounter encountAnsw = (Encounter)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromXml(encod);

            //собственно тут достаём этот VersionId
            string versionId = encountAnsw.Meta.VersionId;

            //а тут задаём обновлённый encounter
            Encounter encounterUpdate = (new SetData()).SetEncounter(patient, new string[] { Ids.condition_min }, References.organization);
            encounterUpdate.Id = enc;
            encounterUpdate.Meta = new Meta { VersionId = versionId };
            encounterUpdate.Reason[0].Coding[0] = new Coding { System = Dictionary.REASON, Code = "2", Version = "1" };
            encounterUpdate.Status = Encounter.EncounterState.Onleave;

            //задаём Bundle
            Bundle b = (new SetData()).SetBundleOrder(order, diagnosticOrder, null, null, condition, null, null, null, null);
            Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
            {
                Resource = encounterUpdate,
                Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.PUT, Url = References.encounter }
            };
            b.Entry.Add(component);

            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);
            string bundleAnsw = Newtonsoft.Json.JsonConvert.DeserializeObject(resp.Content).ToString();

            if (resp.StatusCode != System.Net.HttpStatusCode.OK)
                Assert.Fail(resp.Content);
            Assert.Pass(resp.Content);
        }
Пример #19
0
        public void BundleResult_PutPractitioner()
        {
            //задаём ссылки
            string pract = "ab1af9a5-91b0-4c7f-aba7-6eb4b8f43aab";
            string patient = References.patient;

            //задаём ресурсы
            Order order = (new SetData()).SetOrder(patient, "Practitioner/" + pract, References.organization);
            DiagnosticOrder diagnosticOrder = (new SetData()).SetDiagnosticOrder_Min(patient, "Practitioner/" + 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()).SetOrderResponse(orderId, References.organization);
            DiagnosticReport diagRep = (new SetData()).SetDiagnosticReport(patient, pract, diagnosticOrderId);
            Observation observ = (new SetData()).SetObservation_BundleResult_Reason(pract);

            //Гетаем врача, чтобы узнать VersionId
            var client = new RestClient() { BaseUrl = new Uri("http://192.168.8.93:2223/fhir/Practitioner/" + pract) };
            var request = new RestRequest(Method.GET) { RequestFormat = DataFormat.Json };
            request.AddHeader("Authorization", "N3 f0a258e5-92e4-47d3-9b6c-89362357b2b3");
            IRestResponse respPractVersion = client.Execute(request);

            // тут происходит магия (проблема с кодировкой)
            var encod = new UTF8Encoding(false).GetString(respPractVersion.RawBytes, 3, respPractVersion.RawBytes.Length - 3);
            Practitioner practAnsw = (Practitioner)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromXml(encod);

            //собственно тут достаём этот VersionId
            string versionId = practAnsw.Meta.VersionId;

            //а тут задаём обновлённого врача
            Practitioner practitioner = (new SetData()).SetPractitioner();
            practitioner.Id = pract;
            practitioner.Name.Family = new List<string> { "FamilyName" + DateTime.Now };
            practitioner.Meta = new Meta { VersionId = versionId };

            //задаём Bundle
            Bundle bRes = (new SetData()).SetBundleResult(orderResp, diagRep, observ, null);
            Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
            {
                Resource = practitioner,
                Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.PUT, Url = References.practitioner }
            };
            bRes.Entry.Add(component);

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

            if (resp.StatusCode != System.Net.HttpStatusCode.OK)
                Assert.Fail(resp.Content);
            Assert.Pass(resp.Content);
        }
Пример #20
0
        public Bundle SetBundleOrder(Order order, DiagnosticOrder diagnosticOrder,
                                     Specimen specimen, Encounter encounter, Condition condition,
                                     Observation observation, Practitioner practitioner, Coverage coverage, Patient patient)
        {
            Bundle bundle = new Bundle();
            bundle.Meta = new Meta() { Profile = new string[] { MetaBundleOrder } };
            bundle.Entry = new List<Bundle.BundleEntryComponent>();

            if (order != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = order,
                    Transaction = new Bundle.BundleEntryTransactionComponent { Method = Bundle.HTTPVerb.POST, Url = "Order" }
                };
                bundle.Entry.Add(component);
            }

            if (diagnosticOrder != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = diagnosticOrder,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "DiagnosticOrder" }
                };
                bundle.Entry.Add(component);
            }

            if (specimen != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = specimen,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "Specimen" }
                };
                bundle.Entry.Add(component);
            }

            if (encounter != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = encounter,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "Encounter" }
                };
                bundle.Entry.Add(component);
            }

            if (condition != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = condition,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "Condition" }
                };
                bundle.Entry.Add(component);
            }

            if (observation != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = observation,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "Observation" }
                };
                bundle.Entry.Add(component);
            }

            if (practitioner != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = practitioner,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "Practitioner" }
                };
                bundle.Entry.Add(component);
            }
            if (coverage != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = coverage,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "Coverage" }
                };
                bundle.Entry.Add(component);
            }
            if (patient != null)
            {
                Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent
                {
                    Resource = patient,
                    Transaction = new Bundle.BundleEntryTransactionComponent() { Method = Bundle.HTTPVerb.POST, Url = "Patient" }
                };
                bundle.Entry.Add(component);
            }
            return bundle;
        }