Skip to content

Commit

Permalink
feat(app): manually build indeterminate guideline for FDA fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Feb 27, 2025
1 parent ca59946 commit e88fa68
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/integration_test/drugs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void main() {
findsOneWidget,
);
expect(
find.textContaining(context.l10n.drugs_page_no_guidelines_text),
find.textContaining(context.l10n.drugs_page_no_guidelines_recommendation_text),
findsOneWidget,
);
if (drug.guidelines.isNotEmpty) {
Expand Down
34 changes: 31 additions & 3 deletions app/lib/common/models/drug/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hive/hive.dart';
import 'package:trotter/trotter.dart';

import '../../../app.dart';
import '../../module.dart';

part 'drug.g.dart';
Expand Down Expand Up @@ -106,7 +107,7 @@ extension DrugExtension on Drug {
),
);
if (partialGuidelines.isEmpty) return null;
final guidelineGenes = guidelines.first.lookupkey.keys.toList();
final guidelineGenes = guidelines.first.genes;
Guideline? partiallyHandledGuideline;
var currentMatchingNumber = guidelineGenes.length - 1;
while (currentMatchingNumber > 0 && partiallyHandledGuideline == null) {
Expand Down Expand Up @@ -142,13 +143,40 @@ extension DrugExtension on Drug {
if (exactGuideline != null) return exactGuideline;
final partiallyHandledGuideline = _getPartiallyHandledGuideline();
if (partiallyHandledGuideline != null) return partiallyHandledGuideline;
return guidelines.firstOrNullWhere(
final completelyUnhandledGuideline = guidelines.firstOrNullWhere(
(guideline) => guideline.lookupkey.all(
(gene, variants) => variants.any(
(variant) => variant == SpecialLookup.anyNotHandled.value
)
),
)
);
final context = PharMeApp.navigatorKey.currentContext;
if (
completelyUnhandledGuideline != null &&
completelyUnhandledGuideline.isFdaGuideline &&
context != null
) {
final isCompletelyIndeterminateResult = guidelineGenotypes.map(
(genotypeKey) => UserData.instance.genotypeResults?[genotypeKey]
).all(
(genotypeResult) =>
genotypeResult != null &&
genotypeResult.phenotypeDisplayString(context) == indeterminateResult
);
if (isCompletelyIndeterminateResult) {
final indeterminateFdaFallbackGuideline = Guideline.fromJson(
completelyUnhandledGuideline.toJson(),
);
indeterminateFdaFallbackGuideline.annotations.implication =
context.l10n.drugs_page_fda_indeterminate_implication_text(name);
indeterminateFdaFallbackGuideline.annotations.recommendation =
context.l10n.drugs_page_no_guidelines_recommendation_text;
indeterminateFdaFallbackGuideline.annotations.warningLevel =
WarningLevel.none;
return indeterminateFdaFallbackGuideline;
}
}
return completelyUnhandledGuideline;
}

Guideline? get userOrFirstGuideline => userGuideline ??
Expand Down
8 changes: 7 additions & 1 deletion app/lib/common/models/drug/guideline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ part 'guideline.g.dart';

@HiveType(typeId: 8)
@JsonSerializable()
class Guideline {
class Guideline {
Guideline({
required this.id,
required this.version,
Expand All @@ -16,6 +16,12 @@ class Guideline {
});
factory Guideline.fromJson(dynamic json) => _$GuidelineFromJson(json);

Map<String,dynamic> toJson() => _$GuidelineToJson(this);

bool get isFdaGuideline => externalData.first.source == 'FDA';

List<String> get genes => lookupkey.keys.toList();

@HiveField(0)
@JsonKey(name: '_id')
String id;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/common/utilities/pdf_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ List<pw.Widget> _buildUserPart(
final userGuidelineText = drug.userGuideline != null
? '${drug.userGuideline?.annotations.implication} '
'${drug.userGuideline?.annotations.recommendation}'
: buildContext.l10n.drugs_page_no_guidelines_text;
: buildContext.l10n.drugs_page_no_guidelines_recommendation_text;
return [
_buildSubheading(buildContext.l10n.pdf_heading_user_data),
_buildTextBlockSpacer(),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/drug/widgets/annotation_cards/guideline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class GuidelineAnnotationCard extends StatelessWidget {
WidgetSpan(child: SizedBox(height: PharMeTheme.mediumSpace * 1.3)),
TextSpan(
text:
implicationText ?? context.l10n.drugs_page_no_guidelines_text,
implicationText ?? context.l10n.drugs_page_no_guidelines_recommendation_text,
style: drug.warningLevel != WarningLevel.none
? TextStyle(fontWeight: FontWeight.bold)
: TextStyle(fontStyle: FontStyle.italic)
Expand Down
16 changes: 14 additions & 2 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,20 @@
},
"drugs_page_header_guideline": "Gene-based clinical guideline",
"@drugs_page_header_guideline": {},
"drugs_page_no_guidelines_text": "Standard dosing may apply; no recommendation based on your genes can be made at this time. Consult your pharmacist or doctor for more information.",
"@drugs_page_no_guidelines_text": {},
"drugs_page_no_guidelines_recommendation_text": "Standard dosing may apply; no recommendation based on your genes can be made at this time. Consult your pharmacist or doctor for more information.",
"@drugs_page_no_guidelines_recommendation_text": {
"description": "This should resemble the 'none' recommendation text from Anni"
},
"drugs_page_fda_indeterminate_implication_text": "More information is needed to comment on your genes' influence on {drugName}. We will keep you informed when the guidelines are updated.",
"@drugs_page_fda_indeterminate_implication_text": {
"description": "This should resemble the 'none' implication text from Anni",
"placeholders": {
"drugName": {
"type": "String",
"example": "ibuprofen"
}
}
},
"drugs_page_sources_description": "Tap here to view the full expert guideline published by {source}",
"@drugs_page_sources_description": {
"placeholders": {
Expand Down

0 comments on commit e88fa68

Please sign in to comment.