public FhirModel4.Bundle CreateTransactionBundle( FhirModel.Resource resource, string requestUrl, FhirModel.HTTPVerb requestMethod ) { var bundle = new FhirModel4.Bundle { Type = FhirModel.BundleType.Transaction }; bundle.Entry.Add(CreateTransactionBundleEntry(resource, requestUrl, requestMethod)); return(bundle); }
// 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); }