Introduction
In the rapidly evolving landscape of healthcare, efficient and accurate documentation is paramount. From patient histories to treatment plans, every detail matters. However, the sheer volume of information can overwhelm healthcare professionals, leading to errors or oversights. Fortunately, advancements in artificial intelligence (AI) are offering solutions to streamline this process.
One such solution is demonstrated through a Multi-Turn Chat Application, which leverages Google's AI Platform to enhance medical documentation. Let's delve into how this application works and its potential benefits for healthcare providers.
The Multi-Turn Chat Application
using System;
using System.Threading.Tasks;
using Google.Cloud.AIPlatform.V1;
using System.Collections.Generic;
using System.Linq;
using static Google.Rpc.Context.AttributeContext.Types;
public class MultiTurnChatSample
{
public async Task<string> GenerateContent(
string projectId = "YOUR_PROJECT_ID",
string location = "YOUR_LOCATION",
string publisher = "YOUR_PUBLISHER",
string model = "YOUR_MODEL",
string jsonKeyFilePath = "YOUR_JSON_KEY_FILE_PATH"
)
{
// Specify the path to your service account key file
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", jsonKeyFilePath);
// Create a chat session to keep track of the context
ChatSession chatSession = new ChatSession($"projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}", location);
// Input string to be divided into chunks
string input = "YOUR_INPUT_STRING"; // Update with your input string
// Split the input string into chunks of 20 words
List<string> chunks = SplitIntoChunks(input, 20);
string formattedResponse = "";
int i = 1;
// Iterate through each chunk and process
foreach (var chunk in chunks)
{
Console.WriteLine($"\nInput Segment-{i} : {chunk}");
// Send the chunk to Gemini and receive the response
string response = await chatSession.SendMessageAsync($"correct spelling and formatting the text: {chunk}");
Console.WriteLine($"Out Segment -{i}: {response}");
i++;
// Append the response to the formattedResponse string
formattedResponse += response + "\n";
}
Console.WriteLine("====================================");
Console.WriteLine($"Final result {formattedResponse}");
return formattedResponse;
}
// Helper method to split the input string into chunks of specified size
private List<string> SplitIntoChunks(string input, int chunkSize)
{
List<string> chunks = new List<string>();
string[] words = input.Split(' ');
for (int i = 0; i < words.Length; i += chunkSize)
{
chunks.Add(string.Join(" ", words.Skip(i).Take(chunkSize)));
}
return chunks;
}
private class ChatSession
{
private readonly string _modelPath;
private readonly PredictionServiceClient _predictionServiceClient;
public ChatSession(string modelPath, string location)
{
_modelPath = modelPath;
// Create a prediction service client
_predictionServiceClient = new PredictionServiceClientBuilder
{
Endpoint = $"{location}-aiplatform.googleapis.com"
}.Build();
}
public async Task<string> SendMessageAsync(string prompt)
{
// Create a request to generate content
var generateContentRequest = new GenerateContentRequest
{
Model = _modelPath,
Contents =
{
new Content
{
Role = "USER",
Parts = { new Part { Text = prompt } }
}
},
GenerationConfig = new GenerationConfig
{
Temperature = 0,
TopP = 0,
MaxOutputTokens = 2048
}
};
// Make a non-streaming request, get a response
GenerateContentResponse response = await _predictionServiceClient.GenerateContentAsync(generateContentRequest);
// Return the text from the response
return response.Candidates[0].Content.Parts[0].Text;
}
}
static async Task Main(string[] args)
{
// Specify the path to your service account key file
string jsonKeyFilePath = "YOUR_JSON_KEY_FILE_PATH";
var chatSample = new MultiTurnChatSample();
var response = await chatSample.GenerateContent(jsonKeyFilePath: jsonKeyFilePath);
Console.WriteLine(response);
}
}
Output
##Chronic Conditions Follow-Up: Patient with Ischemic Cardiomyopathy
**Patient:** This pleasant lady is well known to me, with a history of coronary bypass surgery and ischemic cardiomyopathy. She experienced a drop in ejection fraction last year and subsequently received a CRT-D (cardiac resynchronization therapy device with defibrillator). Following the procedure, she had some hypotension and kidney issues, which have since resolved. Her ejection fraction has also improved to 45% on the last echocardiogram. Today, she presents for a follow-up and feels well, except for some mild increased swelling. Her creatinine, which was previously in the 2 range, has decreased to 1.19 today. Her BMP remains high, but she is doing quite well physically and denies any significant shortness of breath.
**Assessment:**
1. **Ischemic Cardiomyopathy:** Ejection fraction dropped to 30% but improved to 45% with CRT-D, as per the last echocardiogram. She is due for another echocardiogram in three months.
2. **Chronic Combined Systolic and Diastolic Heart Failure:** Currently Class II, with mild fluid overload. We will increase torsemide to 30 mg daily.
3. **Biventricular ICD in place.**
4. **Left Bundle Branch Block.**
5. **Coronary Artery Disease:** Status post coronary bypass surgery. Recent cardiac catheterization showed two out of four grafts open. No chest pain.
6. **Hypertension:** She had some low blood pressure episodes previously, but it is now higher again. We will continue the current regimen but consider increasing Coreg to the maximum dose again in the future.
7. **Hyperlipidemia.**
8. **Chronic Kidney Disease:** Currently improved, with creatinine at 1.19 today.
9. **Paroxysmal Atrial Fibrillation:** Very short episodes, less than 1% burden, on aspirin and Plavix.
**Plan:**
* Increase torsemide to 30 mg daily.
* Follow up in three months with BMP, BNP, and an echocardiogram.
Benefits and Applications
-
Improved Documentation Accuracy: By leveraging AI, the application ensures that medical documentation is grammatically correct and formatted appropriately, reducing the risk of misinterpretation or errors.
-
Time Efficiency: Healthcare professionals can save significant time by automating the documentation review process. This allows them to focus more on patient care rather than tedious administrative tasks.
-
Consistency: The AI-driven correction ensures consistency in documentation standards across healthcare facilities, leading to better communication and collaboration among healthcare teams.
-
Scalability: As the volume of medical data continues to grow, scalable solutions like this chat application can adapt to increasing demands without compromising on accuracy or efficiency.
Conclusion
The Multi-Turn Chat Application exemplifies the synergy between AI technology and healthcare documentation. By automating the correction and formatting of medical text, it not only improves efficiency but also enhances the quality and accuracy of patient records. As AI continues to advance, such applications hold immense potential to revolutionize various aspects of healthcare delivery, ultimately benefiting both patients and healthcare providers.
😊Please consider liking and following me for more articles and if you find this content helpful.👍