public override async System.Threading.Tasks.Task WriteResponseBodyAsync(OutputFormatterWriteContext context)
        {
            using (StringWriter strWriter = new StringWriter())
                using (JsonWriter writer = new JsonTextWriter(strWriter))
                {
                    SummaryType summary = SummaryType.False;//;requestMessage.RequestSummary();

                    Type type = context.Object.GetType();
                    if (type == typeof(OperationOutcome))
                    {
                        Resource resource = context.Object as Resource;
                        jsonSerializer.Serialize(resource, writer, summary);
                    }
                    else if (typeof(Resource).IsAssignableFrom(type))
                    {
                        Resource resource = context.Object as Resource;
                        jsonSerializer.Serialize(resource, writer, summary);
                    }
                    else if (typeof(ServerFhirResponse).IsAssignableFrom(type))
                    {
                        ServerFhirResponse fhirResponse = (context.Object as ServerFhirResponse);
                        if (fhirResponse.HasBody)
                        {
                            jsonSerializer.Serialize(fhirResponse.Resource, writer, summary);
                        }
                    }

                    HttpResponse response = context.HttpContext.Response;
                    await response.WriteAsync(strWriter.ToString());
                }
        }
        public ServerFhirResponse Delete(string type, string id)

        {
            Key key = Key.Create(type, id);
            ServerFhirResponse response = fhirService.Delete(key);

            return(response);
        }
        public ServerFhirResponse Read(string type, string id)
        {
            ConditionalHeaderParameters parameters = new ConditionalHeaderParameters(Request);
            Key key = Key.Create(type, id);
            ServerFhirResponse response = fhirService.Read(key, parameters);

            return(response);
        }
Esempio n. 4
0
        public ServerFhirResponse GetFhirResponse(Entry entry, IKey key = null, IEnumerable <object> parameters = null)
        {
            if (entry == null)
            {
                return(Respond.NotFound(key));
            }
            if (entry.IsDeleted())
            {
                return(Respond.Gone(entry));
            }

            ServerFhirResponse response = null;

            return(response ?? Respond.WithResource(entry));
        }
        public void Shold_ReadPatients_When_KeyIsValid()
        {
            // Setup mock fhir client and patient response
            Mock <IFhirClient> mockClient = new Mock <IFhirClient>();
            Patient            res        = new Patient();

            res.Name.Add(HumanName.ForFamily("Doe").WithGiven("John"));
            mockClient.Setup(x => x.Read <DomainResource>(It.IsAny <string>(), It.IsAny <string>(), null)).Returns(res);

            // Create service to tests
            IFhirService service = new TestService(mockClient.Object);

            // Execute the request to read patient's data
            Key key = Key.Create("Patient");
            ServerFhirResponse response = service.Read(key);

            // Verify the response
            Assert.Equal(res.Name[0].Family, ((Patient)response.Resource).Name[0].Family);
        }
        public static Bundle.EntryComponent TranslateToSparseEntry(this Entry entry, ServerFhirResponse response = null)
        {
            var bundleEntry = new Bundle.EntryComponent();

            if (response != null)
            {
                bundleEntry.Response = new Bundle.ResponseComponent()
                {
                    Status                         = string.Format("{0} {1}", (int)response.StatusCode, response.StatusCode),
                    Location                       = response.Key != null?response.Key.ToString() : null,
                                              Etag = response.Key != null?ETag.Create(response.Key.VersionId).ToString() : null,
                                                         LastModified =
                                                             (entry != null && entry.Resource != null && entry.Resource.Meta != null)
                            ? entry.Resource.Meta.LastUpdated
                            : null
                };
            }

            SetBundleEntryResource(entry, bundleEntry);
            return(bundleEntry);
        }
        public static Bundle Append(this Bundle bundle, Entry entry, ServerFhirResponse response = null)
        {
            // API: The api should have a function for this. AddResourceEntry doesn't cut it.
            // Might TransactionBuilder be better suitable?

            Bundle.EntryComponent bundleEntry;
            switch (bundle.Type)
            {
            case Bundle.BundleType.History: bundleEntry = entry.ToTransactionEntry(); break;

            case Bundle.BundleType.Searchset: bundleEntry = entry.TranslateToSparseEntry(); break;

            case Bundle.BundleType.BatchResponse: bundleEntry = entry.TranslateToSparseEntry(response); break;

            case Bundle.BundleType.TransactionResponse: bundleEntry = entry.TranslateToSparseEntry(response); break;

            default: bundleEntry = entry.TranslateToSparseEntry(); break;
            }
            bundle.Entry.Add(bundleEntry);

            return(bundle);
        }