Beispiel #1
0
        private static async Task RuleDataAsync(FhirRest.FhirR4Client fhirClient)
        {
            var srchParams = new SearchParams()
                             .Where("title=All Labs")
                             .LimitTo(10)
                             .SummaryOnly()
                             .OrderBy("title",
                                      SortOrder.Descending);

            var bundle = fhirClient.Search <FhirModel4.List>(srchParams);
            var list   = bundle.Entry.FirstOrDefault()?.Resource as FhirModel4.List;

            if (list != null)
            {
                var listResource = fhirClient.Read <FhirModel4.List>(FhirRest.ResourceIdentity.Build("List", list.Id));

                Console.WriteLine($"List Summary Narrative: {listResource.Text.Div}");
                var tasks = new List <Task <FhirModel4.Patient> >();

                foreach (var entryComponent in listResource.Entry)
                {
                    var resourceReference = entryComponent.Item;
                    tasks.Add(fhirClient.ReadAsync <FhirModel4.Patient>(resourceReference.Url));
                }
                await Task.WhenAll(tasks);

                foreach (var task in tasks)
                {
                    var patient = task.Result;
                    Console.WriteLine(
                        $"NAME: {patient.Name[ 0 ].Given.FirstOrDefault()} {patient.Name[ 0 ].Family.FirstOrDefault()}");
                }
            }
        }
Beispiel #2
0
        private static void FetchClaims(FhirRest.FhirR4Client fhirClient, string [] query)
        {
            var result = fhirClient.Search <FhirModel4.Claim>(query, null, 50);

            Console.WriteLine($"total claims = " + result.Total);

            while (result != null)
            {
                foreach (var e in result.Entry)
                {
                    var claim     = (FhirModel4.Claim)e.Resource;
                    var diagnosis = (claim.Diagnosis.FirstOrDefault()?.Diagnosis as FhirModel.CodeableConcept)?.Coding.FirstOrDefault()?.Code;

                    Console.WriteLine(
                        $"Claim Diagnosis: { diagnosis }");
                    var service = (claim.Item.FirstOrDefault()?.ProductOrService as FhirModel.CodeableConcept)?.Coding.FirstOrDefault()?.Code;
                    Console.WriteLine($"Service: { service }");

                    var extension = claim.GetExtensions("http://careevolution.com/fhirextensions#claim-status").FirstOrDefault();
                    var status    = ((FhirModel.CodeableConcept)extension?.Value)?.Coding.FirstOrDefault()?.Display;
                    Console.WriteLine(
                        $"Claim Status: {status}");
                }

                Console.WriteLine("Fetching more results...");
                result = fhirClient.Continue(result);
            }

            Console.WriteLine("No more claims.");
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            /*
             * Authentication requirements to obtain an access token:
             *
             *      - see https://fhir.docs.careevolution.com/overview/authentication.html
             *
             * The example code below illustrates how to:
             *
             *      using FhirRest.FhirClient:
             *      1.  search for patients
             *      2.  post a resource (DiagnosticReport) for an existing patient
             *      3.  use a FHIR transaction( http://hl7.org/fhir/R4/http.html#transaction ) to POST a FHIR bundle containing
             *              a DiagnosticReport resource + its Patient resource.
             *      4.  read a patient resource, search for claims.  search for diagnostic reports and read contained observations
             *      5.  async calls to get rule data and patients
             *
             *      using HttpClient and json string:
             *      1.  POST the DiagnosticReport resource json string to FhirEndpoint .../api/fhir/DiagnosticReport
             *
             */
            var fhirEndPoint  = FhirServer + "api/fhir-r4";
            var fhirClient    = new FhirRest.FhirR4Client(fhirEndPoint);
            var conformance   = fhirClient.Metadata();
            var tokenEndpoint = conformance.Rest[0].Security.Extension[0].Extension.FirstOrDefault(e => e.Url.Equals("token"))?.Value;

            var accessToken = AccessTokenHelper.GetAccessToken(FhirServer, tokenEndpoint?.ToString());

            fhirClient.OnBeforeRequest += (object sender, FhirRest.BeforeRequestEventArgs eventArgs) =>
            {
                eventArgs.RawRequest.Headers.Add("Authorization", $"Bearer {accessToken}");
            };
            fhirClient.OnAfterResponse += (object sender, FhirRest.AfterResponseEventArgs e) =>
            {
                Console.WriteLine("Received response with status: " + e.RawResponse.StatusCode);
            };

            var patients = GetPatients(fhirClient, "TestFhirPost");

            PostDiagnosticReportForExistingPatient(fhirClient, patients);

            var patient = PostDiagnosticReportForNewPatient(fhirClient);

            PostJsonReport(accessToken, fhirEndPoint, patient.Id);

            PatientData(fhirClient);

            RuleDataAsync(fhirClient).Wait();

            Console.WriteLine("All done.");

            Console.ReadLine();
        }
Beispiel #4
0
        private static List <FhirModel4.Patient> GetPatients(FhirRest.FhirR4Client fhirClient, string family)
        {
            var srch = new FhirRest.SearchParams()
                       .Where($"family={family}")
                       .LimitTo(20)
                       .SummaryOnly()
                       .OrderBy("birthdate",
                                FhirRest.SortOrder.Descending);

            var bundle = fhirClient.Search <FhirModel4.Patient>(srch);

            return(bundle.Entry.Select(b => b.Resource as FhirModel4.Patient).ToList());
        }
Beispiel #5
0
        private static void PostDiagnosticReportForExistingPatient(FhirRest.FhirR4Client fhirClient, List <FhirModel4.Patient> patients)
        {
            foreach (var patient in patients)
            {
                var writeable = patient.Identifier.Any(i => i.System == FhirIdSystem);
                if (!writeable)
                {
                    continue;
                }

                var report = CreateReport(DateTime.Now);
                report.Subject = new FhirModel.ResourceReference
                {
                    Reference = "Patient/" + patient.Id
                };
                var createdReport = fhirClient.Create(report);
                Console.WriteLine($"Diagnostic Report Posted.  New Resource Reference = DiagnosticReport/" + createdReport.Id);
            }
        }
Beispiel #6
0
        // post via fhir rest client using bundle transaction returns location url with newly created ID's.
        private static FhirModel4.Patient PostDiagnosticReportForNewPatient(FhirRest.FhirR4Client fhirClient)
        {
            var patientIdentifier = Guid.NewGuid().ToString();
            var patient           = CreatePatient(patientIdentifier);
            var report            = CreateReport(DateTime.Now);

            // create bundle transaction
            var bundle = new FhirModel4.Bundle {
                Type = FhirModel.BundleType.Transaction
            };

            var patientEntry = CreateTransactionBundleEntry(patient, "Patient", FhirModel.HTTPVerb.POST);

            report.Subject = new FhirModel.ResourceReference(patientEntry.FullUrl);

            var reportEntry = CreateTransactionBundleEntry(report, "DiagnosticReport", FhirModel.HTTPVerb.POST);

            bundle.Entry.Add(patientEntry);
            bundle.Entry.Add(reportEntry);

            FhirModel4.Bundle boo;

            var bundleResponse = fhirClient.Transaction(bundle);

            foreach (var bundleResponseEntry in bundleResponse.Entry)
            {
                Console.WriteLine("response status = " + bundleResponseEntry.Response.Status);
                Console.WriteLine("location = " + bundleResponseEntry.Response.Location);

                var resource = fhirClient.Get(bundleResponseEntry.Response.Location);
                if (resource is FhirModel4.Patient)
                {
                    patient = (FhirModel4.Patient)resource;
                }
                else if (resource is FhirModel4.DiagnosticReport)
                {
                    report = (FhirModel4.DiagnosticReport)resource;
                }
            }

            return(patient);
        }
Beispiel #7
0
        private static void FetchDiagnosticReports(FhirRest.FhirR4Client fhirClient, string[] query)
        {
            var result = fhirClient.Search <FhirModel4.DiagnosticReport>(query, null, 50);

            Console.WriteLine($"total reports = " + result.Total);

            while (result != null)
            {
                foreach (var e in result.Entry)
                {
                    var report = (FhirModel4.DiagnosticReport)e.Resource;

                    Console.WriteLine($"Report LastUpdated: {report.Meta.LastUpdated}");
                    Console.WriteLine($"Report Status: {report.Status}");
                    Console.WriteLine($"Report Category: {report.Category.FirstOrDefault()?.Coding.FirstOrDefault()?.Display}");
                    var observations = report.Result;
                    foreach (var resourceReference in observations)
                    {
                        var resource = fhirClient.Read <FhirModel4.Observation>(resourceReference.Url);
                        Console.WriteLine($"Observation date: {resource.Effective}");
                        if (resource.Value is FhirModel.Quantity)
                        {
                            var value = (FhirModel.Quantity)resource.Value;
                            Console.WriteLine($"Observation value: {value.Value}");
                            Console.WriteLine($"Observation units: {value.Unit}");
                        }
                        else
                        {
                            Console.WriteLine($"Observation value: {(( FhirString )resource.Value ).Value}");
                        }
                    }
                }

                Console.WriteLine("Fetching more results...");
                result = fhirClient.Continue(result);
            }

            Console.WriteLine("No more reports.");
        }
Beispiel #8
0
        private static void PatientData(FhirRest.FhirR4Client fhirClient)
        {
            // search for patient as we don't have a patient ID
            var patients = GetPatients(fhirClient, "JEPPESEN");

            if (!patients.Any())
            {
                return;
            }

            var patientResource = fhirClient.Read <FhirModel4.Patient>(FhirRest.ResourceIdentity.Build("Patient", patients.FirstOrDefault()?.Id));

            Console.WriteLine($" patient name =" + patientResource.Name.FirstOrDefault());
            Console.WriteLine($" patient birthdate =" + patientResource.BirthDate);
            Console.WriteLine($" patient gender =" + patientResource.Gender);

            var query = new string[] { $"patient._id={patientResource.Id}" };

            FetchClaims(fhirClient, query);

            FetchDiagnosticReports(fhirClient, query);
        }