|
| 1 | +# How to extract the description of a Clinical Guidance inference using a synchronous call |
| 2 | + |
| 3 | +In this sample it is shown how you can construct a request, add a configuration, create a client, send a synchronous request and use the result returned to extract clinical guidance information from radiology reports, display findings codes, present guidance information, and recommendation proposals. |
| 4 | + |
| 5 | +## Creating a PatientRecord with Details, Encounter, and Document Content |
| 6 | +To create a comprehensive patient record, instantiate a `PatientRecord` object with the patient’s details, encounter information, and document content. This record includes the patient’s birth date, sex, encounter class, period, and associated clinical documents, such as radiology reports. The `PatientRecord` object is then populated with these details to ensure all relevant patient information is accurately captured and organized. |
| 7 | +```C# Snippet:Guidance_Sync_Tests_Samples_CreatePatientRecord |
| 8 | +string id = "patient_id2"; |
| 9 | +PatientDetails patientInfo = new() |
| 10 | +{ |
| 11 | + BirthDate = new System.DateTime(1959, 11, 11), |
| 12 | + Sex = PatientSex.Female, |
| 13 | +}; |
| 14 | +PatientEncounter encounter = new("encounterid1") |
| 15 | +{ |
| 16 | + Class = EncounterClass.InPatient, |
| 17 | + Period = new TimePeriod |
| 18 | + { |
| 19 | + Start = new System.DateTime(2021, 08, 28), |
| 20 | + End = new System.DateTime(2021, 08, 28) |
| 21 | + } |
| 22 | +}; |
| 23 | +List<PatientEncounter> encounterList = new() { encounter }; |
| 24 | +ClinicalDocumentContent documentContent = new(DocumentContentSourceType.Inline, DOC_CONTENT); |
| 25 | +PatientDocument patientDocument = new(ClinicalDocumentContentType.Note, "doc2", documentContent) |
| 26 | +{ |
| 27 | + ClinicalType = ClinicalDocumentType.RadiologyReport, |
| 28 | + CreatedAt = new System.DateTime(2021, 08, 28), |
| 29 | + AdministrativeMetadata = CreateDocumentAdministrativeMetadata() |
| 30 | +}; |
| 31 | +PatientRecord patientRecord = new(id); |
| 32 | +patientRecord.Details = patientInfo; |
| 33 | +patientRecord.Encounters.Add(encounter); |
| 34 | +patientRecord.PatientDocuments.Add(patientDocument); |
| 35 | +``` |
| 36 | + |
| 37 | +## Specifying Document Content for Patient Record |
| 38 | +To define the document content for a patient record, create a constant string `DOC_CONTENT` that includes detailed clinical history, comparison, technique, findings, and impression sections. This content provides comprehensive information about the patient’s medical history, the techniques used in the examination, and the findings from the radiology report. This structured document content is essential for accurate and thorough patient records. |
| 39 | +```C# Snippet:Guidance_Sync_Tests_Samples_Doc_Content |
| 40 | +private const string DOC_CONTENT = "History:" + |
| 41 | + "\r\n Left renal tumor with thin septations." + |
| 42 | + "\r\n Findings:" + |
| 43 | + "\r\n There is a right kidney tumor with nodular calcification."; |
| 44 | +``` |
| 45 | + |
| 46 | +## Creating Ordered Procedures for Patient Record |
| 47 | +To add ordered procedures to a patient record, instantiate a `DocumentAdministrativeMetadata` object and create a `FhirR4Coding` object with the relevant procedure details. This includes the display name, code, and system. Then, create a `FhirR4CodeableConcept` object and add the coding to it. Finally, create an `OrderedProcedure` object with a description and code, and add it to the `OrderedProcedures` list of the `DocumentAdministrativeMetadata` object. This process ensures that the ordered procedures are accurately documented and associated with the patient record. |
| 48 | +```C# Snippet:Guidance_Sync_Tests_Samples_CreateDocumentAdministrativeMetadata |
| 49 | +DocumentAdministrativeMetadata documentAdministrativeMetadata = new DocumentAdministrativeMetadata(); |
| 50 | + |
| 51 | +FhirR4Coding coding = new() |
| 52 | +{ |
| 53 | + Display = "US PELVIS COMPLETE", |
| 54 | + Code = "USPELVIS", |
| 55 | + System = "Http://hl7.org/fhir/ValueSet/cpt-all" |
| 56 | +}; |
| 57 | + |
| 58 | +FhirR4CodeableConcept codeableConcept = new(); |
| 59 | +codeableConcept.Coding.Add(coding); |
| 60 | + |
| 61 | +OrderedProcedure orderedProcedure = new() |
| 62 | +{ |
| 63 | + Description = "US PELVIS COMPLETE", |
| 64 | + Code = codeableConcept |
| 65 | +}; |
| 66 | + |
| 67 | +documentAdministrativeMetadata.OrderedProcedures.Add(orderedProcedure); |
| 68 | +``` |
| 69 | + |
| 70 | +## Creating and Configuring ModelConfiguration for Radiology Insights |
| 71 | +To set up a `RadiologyInsightsModelConfiguration`, instantiate the configuration object and specify the locale, whether to include evidence, and the inference options. Additionally, define the expected response inference types by adding them to the `InferenceTypes` list. This configuration ensures that the radiology insights model is tailored to the specific requirements and expected outcomes of the analysis. |
| 72 | +```C# Snippet:Guidance_Sync_Tests_Samples_CreateModelConfiguration |
| 73 | +RadiologyInsightsModelConfiguration radiologyInsightsModelConfiguration = new() |
| 74 | +{ |
| 75 | + Locale = "en-US", |
| 76 | + IncludeEvidence = true, |
| 77 | + InferenceOptions = radiologyInsightsInferenceOptions |
| 78 | +}; |
| 79 | +radiologyInsightsModelConfiguration.InferenceTypes.Add(RadiologyInsightsInferenceType.Guidance); |
| 80 | +``` |
| 81 | + |
| 82 | +## Adding Inference Options to ModelConfiguration for Radiology Insights |
| 83 | +To configure the inference options for the radiology insights model, create instances of `RadiologyInsightsInferenceOptions`, `FollowupRecommendationOptions`, and `FindingOptions`. Set the desired properties for follow-up recommendations and findings, such as including recommendations with no specified modality, including recommendations in references, and providing focused sentence evidence. Assign these options to the `RadiologyInsightsInferenceOptions` object, ensuring that the model configuration is tailored to provide detailed and relevant insights. |
| 84 | +```C# Snippet:Guidance_Sync_Tests_Samples_CreateRadiologyInsightsInferenceOptions |
| 85 | +RadiologyInsightsInferenceOptions radiologyInsightsInferenceOptions = new(); |
| 86 | +FollowupRecommendationOptions followupRecommendationOptions = new(); |
| 87 | +FindingOptions findingOptions = new(); |
| 88 | +followupRecommendationOptions.IncludeRecommendationsWithNoSpecifiedModality = true; |
| 89 | +followupRecommendationOptions.IncludeRecommendationsInReferences = true; |
| 90 | +followupRecommendationOptions.ProvideFocusedSentenceEvidence = true; |
| 91 | +findingOptions.ProvideFocusedSentenceEvidence = true; |
| 92 | +radiologyInsightsInferenceOptions.FollowupRecommendationOptions = followupRecommendationOptions; |
| 93 | +radiologyInsightsInferenceOptions.FindingOptions = findingOptions; |
| 94 | +``` |
| 95 | + |
| 96 | +## Adding PatientRecord and ModelConfiguration to RadiologyInsightsData |
| 97 | +To integrate the patient record and model configuration into `RadiologyInsightsData`, create a list of `PatientRecord` objects and initialize it with the patient record. Then, instantiate `RadiologyInsightsData` with this list. Finally, set the Configuration property of `RadiologyInsightsData` to the model configuration created using the `CreateConfiguration` method. This ensures that the data object is fully prepared with both patient information and the necessary configuration for radiology insights analysis. |
| 98 | +```C# Snippet:Guidance_Sync_Tests_Samples_AddRecordAndConfiguration |
| 99 | +List<PatientRecord> patientRecords = new() { patientRecord }; |
| 100 | +RadiologyInsightsData radiologyInsightsData = new(patientRecords); |
| 101 | +radiologyInsightsData.Configuration = CreateConfiguration(); |
| 102 | +``` |
| 103 | + |
| 104 | +## Initializing RadiologyInsights Client with Default Azure Credentials |
| 105 | +Create a `RadiologyInsightsClient` by initializing TokenCredential using the default Azure credentials. |
| 106 | +```C# Snippet:Guidance_Sync_Tests_Samples_TokenCredential |
| 107 | +Uri endpointUri = new Uri(endpoint); |
| 108 | +TokenCredential cred = new DefaultAzureCredential(); |
| 109 | +RadiologyInsightsClient client = new RadiologyInsightsClient(endpointUri, cred); |
| 110 | +``` |
| 111 | + |
| 112 | +## Sending Synchronous Requests with RadiologyInsights Client |
| 113 | +Send a synchronous request using the `RadiologyInsightsClient` along with the job id and radiologyInsightsjob. |
| 114 | +```C# Snippet:Guidance_Sync_Tests_Samples_synccall |
| 115 | +RadiologyInsightsJob radiologyInsightsjob = GetRadiologyInsightsJob(); |
| 116 | +var jobId = "job" + DateTimeOffset.Now.ToUnixTimeMilliseconds(); |
| 117 | +Operation<RadiologyInsightsInferenceResult> operation = client.InferRadiologyInsights(WaitUntil.Completed, jobId, radiologyInsightsjob); |
| 118 | +``` |
| 119 | + |
| 120 | +## Displaying Guidance Inferences from Radiology Insights |
| 121 | +Below code retrieves clinical guidance inferences from radiology report analysis results and displays key information for each guidance inference found. It extracts and displays finding codes, identifiers, present guidance information, rankings, recommendation proposals, and any missing guidance information - providing a comprehensive view of the clinical guidance derived from the radiology report. |
| 122 | +```C# Snippet:Guidance_Sync_Tests_Samples_GuidanceInference |
| 123 | +RadiologyInsightsInferenceResult responseData = operation.Value; |
| 124 | +IReadOnlyList<RadiologyInsightsInference> inferences = responseData.PatientResults[0].Inferences; |
| 125 | + |
| 126 | +foreach (RadiologyInsightsInference inference in inferences) |
| 127 | +{ |
| 128 | + if (inference is GuidanceInference guidanceInference) |
| 129 | + { |
| 130 | + Console.WriteLine("Guidance Inference found: "); |
| 131 | + |
| 132 | + FindingInference findingInference = guidanceInference.Finding; |
| 133 | + FhirR4Observation finding = findingInference.Finding; |
| 134 | + if (finding.Code != null) |
| 135 | + { |
| 136 | + Console.WriteLine(" Finding Code: "); |
| 137 | + DisplayCodes(finding.Code, 2); |
| 138 | + } |
| 139 | + |
| 140 | + Console.WriteLine(" Identifier: "); |
| 141 | + DisplayCodes(guidanceInference.Identifier, 2); |
| 142 | + |
| 143 | + foreach (var presentInfo in guidanceInference.PresentGuidanceInformation) |
| 144 | + { |
| 145 | + Console.WriteLine(" Present Guidance Information: "); |
| 146 | + DisplayPresentGuidanceInformation(presentInfo); |
| 147 | + } |
| 148 | + |
| 149 | + Console.WriteLine($" Ranking: {guidanceInference.Ranking}"); |
| 150 | + IReadOnlyList<FollowupRecommendationInference> recommendationProposals = guidanceInference.RecommendationProposals; |
| 151 | + foreach (FollowupRecommendationInference recommendationProposal in recommendationProposals) |
| 152 | + { |
| 153 | + Console.WriteLine($" Recommendation Proposal: {recommendationProposal.RecommendedProcedure.Kind}"); |
| 154 | + } |
| 155 | + |
| 156 | + foreach (var missingInfo in guidanceInference.MissingGuidanceInformation) |
| 157 | + { |
| 158 | + Console.WriteLine($" Missing Guidance Information: {missingInfo}"); |
| 159 | + } |
| 160 | + } |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +## Display FHIR R4 Coding Information |
| 165 | +Below code iterates through a list of FHIR R4 codings and displays their key components. |
| 166 | +```C# Snippet:Guidance_Sync_Sync_Tests_Samples_DisplayCodes |
| 167 | +IList<FhirR4Coding> codingList = codeableConcept.Coding; |
| 168 | +if (codingList != null) |
| 169 | +{ |
| 170 | + foreach (FhirR4Coding fhirR4Coding in codingList) |
| 171 | + { |
| 172 | + Console.WriteLine(initialBlank + "Coding: " + fhirR4Coding.Code + ", " + fhirR4Coding.Display + " (" + fhirR4Coding.System + ")"); |
| 173 | + } |
| 174 | +} |
| 175 | +``` |
| 176 | + |
| 177 | +## Display Present Guidance Information and Measurements |
| 178 | +Below code displays comprehensive guidance information including present values, size measurements, and dimensional data from radiology findings. |
| 179 | +```C# Snippet:Guidance_Sync_Tests_Samples_DisplayPresentGuidanceInformation |
| 180 | +if (guidanceInfo.PresentGuidanceValues != null) |
| 181 | +{ |
| 182 | + foreach (var value in guidanceInfo.PresentGuidanceValues) |
| 183 | + { |
| 184 | + Console.WriteLine($" Present Guidance Value: {value}"); |
| 185 | + } |
| 186 | +} |
| 187 | + |
| 188 | +if (guidanceInfo.Sizes != null) |
| 189 | +{ |
| 190 | + foreach (var size in guidanceInfo.Sizes) |
| 191 | + { |
| 192 | + if (size.ValueQuantity != null) |
| 193 | + { |
| 194 | + Console.WriteLine(" Size ValueQuantity: "); |
| 195 | + DisplayQuantityOutput(size.ValueQuantity); |
| 196 | + } |
| 197 | + if (size.ValueRange != null) |
| 198 | + { |
| 199 | + if (size.ValueRange.Low != null) |
| 200 | + { |
| 201 | + Console.WriteLine($" Size ValueRange: min {size.ValueRange.Low}"); |
| 202 | + } |
| 203 | + if (size.ValueRange.High != null) |
| 204 | + { |
| 205 | + Console.WriteLine($" Size ValueRange: max {size.ValueRange.High}"); |
| 206 | + } |
| 207 | + } |
| 208 | + } |
| 209 | +} |
| 210 | + |
| 211 | +if (guidanceInfo.MaximumDiameterAsInText != null) |
| 212 | +{ |
| 213 | + Console.WriteLine(" Maximum Diameter As In Text: "); |
| 214 | + DisplayQuantityOutput(guidanceInfo.MaximumDiameterAsInText); |
| 215 | +} |
| 216 | + |
| 217 | +if (guidanceInfo.Extension != null) |
| 218 | +{ |
| 219 | + Console.WriteLine(" Extension: "); |
| 220 | + DisplaySectionInfo(guidanceInfo); |
| 221 | +} |
| 222 | +``` |
| 223 | + |
| 224 | +## Display Quantity Values and Units |
| 225 | +Below code outputs the numeric value and unit of measurement from a quantity object. It checks for both components separately since either could be null. |
| 226 | +```C# Snippet:Guidance_Sync_Tests_Samples_DisplayQuantityOutput |
| 227 | +if (quantity.Value != null) |
| 228 | +{ |
| 229 | + Console.WriteLine($" Value: {quantity.Value}"); |
| 230 | +} |
| 231 | +if (quantity.Unit != null) |
| 232 | +{ |
| 233 | + Console.WriteLine($" Unit: {quantity.Unit}"); |
| 234 | +} |
| 235 | +``` |
| 236 | + |
| 237 | +## Display Section Information from Extensions |
| 238 | +Below code processes extension data within guidance information, specifically looking for sections and their associated details. |
| 239 | +```C# Snippet:Guidance_Sync_Tests_Samples_DisplaySectionInfo |
| 240 | +if (guidanceInfo.Extension != null) |
| 241 | +{ |
| 242 | + foreach (var ext in guidanceInfo.Extension) |
| 243 | + { |
| 244 | + if (ext.Url == "section") |
| 245 | + { |
| 246 | + Console.WriteLine(" Section:"); |
| 247 | + if (ext.Extension != null) |
| 248 | + { |
| 249 | + foreach (var subextension in ext.Extension) |
| 250 | + { |
| 251 | + if (subextension.Url != null && subextension.ValueString != null) |
| 252 | + { |
| 253 | + Console.WriteLine($" {subextension.Url}: {subextension.ValueString}"); |
| 254 | + } |
| 255 | + } |
| 256 | + } |
| 257 | + } |
| 258 | + } |
| 259 | +} |
| 260 | +``` |
0 commit comments