-
-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add persistent transcription history with reusable insights viewer #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Shweta-281
wants to merge
17
commits into
AOSSIE-Org:main
Choose a base branch
from
Shweta-281:feat/transcription-history
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e2b4c9a
feat: add structured medical insights with Gemini AI JSON parsing
Shweta-281 5aa0dd4
update transcription_screen file
Shweta-281 ef025b8
fix error
Shweta-281 cd9b7a3
fix error
Shweta-281 8558d4e
fix error
Shweta-281 b6f38e8
fix: resolve overflow and update UI for structured medical insights
Shweta-281 1e160e1
fix issue
Shweta-281 8584cbc
fix transciption_screen file
Shweta-281 a363425
fix transciption_screen file
Shweta-281 64da1f2
fix transciption_screen file
Shweta-281 906b7c3
fix transciption_screen file
Shweta-281 8795c59
fix transciption_screen file
Shweta-281 56050f6
feat: add persistent transcription history with structured insights
Shweta-281 b5eab34
feat: add persistent transcription history with structured insights
Shweta-281 916c566
feat: add persistent transcription history with structured insights
Shweta-281 12cce52
feat: add persistent transcription history with structured insights
Shweta-281 f1ec913
feat: add persistent transcription history with structured insights
Shweta-281 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,45 @@ | ||
| import 'dart:convert'; | ||
| import '../domain/medical_insights.dart'; | ||
| import 'package:doc_pilot_new_app_gradel_fix/services/chatbot_service.dart'; | ||
|
|
||
| class GeminiService { | ||
| final ChatbotService _chatbotService = ChatbotService(); | ||
|
|
||
| Future<String> generateSummary(String transcription) async { | ||
| return await _chatbotService.getGeminiResponse( | ||
| "Generate a summary of the conversation based on this transcription: $transcription", | ||
| ); | ||
| Future<MedicalInsights> generateInsights(String transcription) async { | ||
| final prompt = """ | ||
| Extract structured medical information from the conversation. | ||
|
|
||
| Return ONLY valid JSON in this format: | ||
| { | ||
| "summary": "short summary", | ||
| "symptoms": ["symptom1", "symptom2"], | ||
| "medicines": ["medicine1", "medicine2"] | ||
| } | ||
|
|
||
| Conversation: | ||
| $transcription | ||
| """; | ||
|
|
||
| final response = await _chatbotService.getGeminiResponse(prompt); | ||
|
|
||
| try { | ||
| final cleaned = _extractJson(response); | ||
| final jsonData = json.decode(cleaned); | ||
| return MedicalInsights.fromJson(jsonData); | ||
| } catch (e) { | ||
| throw Exception('Failed to parse Gemini JSON response'); | ||
| } | ||
| } | ||
|
|
||
| Future<String> generatePrescription(String transcription) async { | ||
| await Future.delayed(const Duration(seconds: 3)); | ||
| return await _chatbotService.getGeminiResponse( | ||
| "Generate a prescription based on the conversation in this transcription: $transcription", | ||
| ); | ||
| // Handles messy AI responses | ||
| String _extractJson(String response) { | ||
| final start = response.indexOf('{'); | ||
| final end = response.lastIndexOf('}'); | ||
|
|
||
| if (start != -1 && end != -1) { | ||
| return response.substring(start, end + 1); | ||
| } | ||
|
|
||
| throw Exception('Invalid JSON format from AI'); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
lib/features/transcription/data/local_storage_service.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import 'dart:convert'; | ||
| import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
| import '../domain/transcription_history_model.dart'; | ||
|
|
||
| class LocalStorageService { | ||
| static const String _key = "transcription_history_secure"; | ||
| final _storage = const FlutterSecureStorage(); | ||
|
|
||
| // Internal helper to get RAW list without reversing (prevents corruption) | ||
| Future<List<TranscriptionHistoryModel>> _getRawList() async { | ||
| try { | ||
| final jsonStr = await _storage.read(key: _key); | ||
| if (jsonStr == null) return []; | ||
| final List<dynamic> decoded = jsonDecode(jsonStr); | ||
| return decoded.map((item) => TranscriptionHistoryModel.fromJson(item)).toList(); | ||
| } catch (_) { return []; } | ||
| } | ||
|
|
||
| Future<void> save(TranscriptionHistoryModel item) async { | ||
| final list = await _getRawList(); // Get chronological order | ||
| list.add(item); | ||
| await _storage.write(key: _key, value: jsonEncode(list.map((e) => e.toJson()).toList())); | ||
| } | ||
|
|
||
| Future<List<TranscriptionHistoryModel>> getAll() async { | ||
| final list = await _getRawList(); | ||
| return list.reversed.toList(); // Reverse ONLY for UI display | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| class MedicalInsights { | ||
| final String summary; | ||
| final List<String> symptoms; | ||
| final List<String> medicines; | ||
|
|
||
| MedicalInsights({ | ||
| required this.summary, | ||
| required this.symptoms, | ||
| required this.medicines, | ||
| }); | ||
|
|
||
| factory MedicalInsights.fromJson(Map<String, dynamic> json) { | ||
| return MedicalInsights( | ||
| // Coerce summary to String regardless of what the AI sends | ||
| summary: json['summary']?.toString() ?? '', | ||
|
|
||
| // Safely parse lists to avoid 'type is not a subtype' errors | ||
| symptoms: _parseList(json['symptoms']), | ||
| medicines: _parseList(json['medicines']), | ||
| ); | ||
| } | ||
|
|
||
| /// Helper to filter nulls and force elements to strings | ||
| static List<String> _parseList(dynamic jsonValue) { | ||
| if (jsonValue is! List) return []; | ||
| return jsonValue | ||
| .where((item) => item != null) | ||
| .map((item) => item.toString()) | ||
| .toList(); | ||
| } | ||
|
|
||
| Map<String, dynamic> toJson() { | ||
| return { | ||
| 'summary': summary, | ||
| 'symptoms': symptoms, | ||
| 'medicines': medicines, | ||
| }; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
lib/features/transcription/domain/transcription_history_model.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import 'medical_insights.dart'; | ||
|
|
||
| class TranscriptionModel { | ||
| final String rawTranscript; | ||
| final String summary; | ||
| final String prescription; | ||
| final MedicalInsights? insights; | ||
|
|
||
| const TranscriptionModel({ | ||
| this.rawTranscript = '', | ||
| this.summary = '', | ||
| this.prescription = '', | ||
| this.insights, | ||
| }); | ||
|
|
||
| TranscriptionModel copyWith({ | ||
| String? rawTranscript, | ||
| String? summary, | ||
| String? prescription, | ||
| MedicalInsights? insights, | ||
| }) { | ||
| return TranscriptionModel( | ||
| rawTranscript: rawTranscript ?? this.rawTranscript, | ||
| summary: summary ?? this.summary, | ||
| prescription: prescription ?? this.prescription, | ||
| insights: insights ?? this.insights, | ||
| ); | ||
| } | ||
| } |
51 changes: 34 additions & 17 deletions
51
lib/features/transcription/domain/transcription_model.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,40 @@ | ||
| class TranscriptionModel { | ||
| final String rawTranscript; | ||
| import 'medical_insights.dart'; | ||
|
|
||
| class TranscriptionHistoryModel { | ||
| final String transcript; | ||
| final String summary; | ||
| final String prescription; | ||
| final List<String> symptoms; | ||
| final List<String> medicines; | ||
| final DateTime createdAt; | ||
|
|
||
| const TranscriptionModel({ | ||
| this.rawTranscript = '', | ||
| this.summary = '', | ||
| this.prescription = '', | ||
| const TranscriptionHistoryModel({ | ||
| required this.transcript, | ||
| required this.summary, | ||
| required this.symptoms, | ||
| required this.medicines, | ||
| required this.createdAt, | ||
| }); | ||
|
|
||
| TranscriptionModel copyWith({ | ||
| String? rawTranscript, | ||
| String? summary, | ||
| String? prescription, | ||
| }) { | ||
| return TranscriptionModel( | ||
| rawTranscript: rawTranscript ?? this.rawTranscript, | ||
| summary: summary ?? this.summary, | ||
| prescription: prescription ?? this.prescription, | ||
| factory TranscriptionHistoryModel.fromJson(Map<String, dynamic> json) { | ||
| return TranscriptionHistoryModel( | ||
| transcript: json['transcript'] ?? '', | ||
| summary: json['summary'] ?? '', | ||
| // FIXED: Use null-coalescing and casting to prevent crashes on missing lists | ||
| symptoms: (json['symptoms'] as List?)?.map((e) => e.toString()).toList() ?? [], | ||
| medicines: (json['medicines'] as List?)?.map((e) => e.toString()).toList() ?? [], | ||
| createdAt: json['createdAt'] != null | ||
| ? DateTime.parse(json['createdAt']) | ||
| : DateTime.now(), | ||
Shweta-281 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
| } | ||
|
|
||
| Map<String, dynamic> toJson() { | ||
| return { | ||
| 'transcript': transcript, | ||
| 'summary': summary, | ||
| 'symptoms': symptoms, | ||
| 'medicines': medicines, | ||
| 'createdAt': createdAt.toIso8601String(), | ||
| }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.