Skip to content

Commit

Permalink
feat(app): add all not handled by guideline fallback case
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 20, 2024
1 parent 6f32805 commit 4b119d2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 67 deletions.
48 changes: 23 additions & 25 deletions app/integration_test/drugs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import 'package:mocktail/mocktail.dart';
import 'package:provider/provider.dart';

import 'fixtures/drugs/with_any_fallback_guideline.dart';
import 'fixtures/drugs/with_multiple_any_not_handled_fallback_guidelines.dart';
import 'fixtures/drugs/with_any_not_handled_guideline.dart';
// import 'fixtures/drugs/with_multiple_any_not_handled_fallback_guidelines.dart';
import 'fixtures/drugs/with_proper_guideline.dart';
import 'fixtures/drugs/without_guidelines.dart';
import 'fixtures/set_user_data_for_drug.dart';
import 'fixtures/set_user_data.dart';
import 'mocks/drug_cubit.dart';

void main() {
Expand All @@ -24,7 +25,7 @@ void main() {
UserData.instance.activeDrugNames = [];
UserData.instance.labData = null;
UserData.instance.genotypeResults = null;
setUserDataForDrug(drugWithProperGuideline);
setUserDataForGuideline(drugWithProperGuideline.guidelines.first);
mockDrugsCubit = MockDrugsCubit();
});

Expand Down Expand Up @@ -76,29 +77,26 @@ void main() {
);
});

testWidgets('test drug content with any not handled fallback guidelines', (tester) async {
// Work in progress; this should fail!
// Open TODOs:
// 1. Start with easy case (not pazopanib, add fixture for FDA w/ HLA-B)
// 2. Set user data for different guidelines and test that selected
// guidelines are different (may want to refactor set user data
// to be useful here)
// 3. Add all pazopanib guidelines for complex case
Future<void> testPerGuideline(Drug drug) async {
for (
final guideline in drug.guidelines
) {
await _expectDrugContent(
tester,
mockDrugsCubit,
drug: drug,
guideline: guideline,
);
testWidgets(
'test drug content with any not handled fallback guidelines',
(tester) async {
Future<void> testPerGuideline(Drug drug) async {
for (
final guideline in drug.guidelines
) {
setUserDataForGuideline(guideline);
await _expectDrugContent(
tester,
mockDrugsCubit,
drug: drug,
guideline: guideline,
);
}
}
}
// await testPerGuideline(drugWithAnyOtherFallbackGuideline);
await testPerGuideline(drugWithMultipleAnyNotHandledFallbackGuidelines);
});
await testPerGuideline(drugWithAnyNotHandledFallbackGuideline);
// await testPerGuideline(drugWithMultipleAnyNotHandledFallbackGuidelines);
},
);
});
}

Expand Down
57 changes: 57 additions & 0 deletions app/integration_test/fixtures/set_user_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:app/common/module.dart';

class _UserDataConfig {
_UserDataConfig({
required this.gene,
required this.lookupkey,
});
final String gene;
final String lookupkey;
final String phenotype = 'phenotype does not matter for test';
final String variant = 'variant does not matter for test';
final String allelesTested = 'allelesTested does not matter for test';
}

void setUserDataForGuideline(Guideline guideline) {
UserData.instance.labData = UserData.instance.labData ?? [];
UserData.instance.genotypeResults = UserData.instance.genotypeResults ?? {};
for (final gene in guideline.lookupkey.keys) {
final lookupkeys = guideline.lookupkey[gene]!;
if (lookupkeys.length != 1) {
debugPrint(
'Warning: using only first lookupkey of ${lookupkeys.length} to set '
'user data',
);
}
var lookupkey = lookupkeys.first;
if (lookupkey == '*' || lookupkey == '~') {
lookupkey = 'certainly not handled lookupkey';
}
final userDataConfig = _UserDataConfig(
gene: gene,
lookupkey: lookupkey,
);
// Need to be careful with non-unique genes here; e.g., is we want to use
// multiple HLA-B variants in the tests, we will need to check for the
// genotype key (which is in the current setup not possible without the
// variant)
UserData.instance.labData = UserData.instance.labData!.filter(
(labResult) => labResult.gene != gene
).toList();
UserData.instance.labData!.add(
LabResult(
gene: userDataConfig.gene,
variant: userDataConfig.variant,
phenotype: userDataConfig.phenotype,
allelesTested: userDataConfig.allelesTested,
),
);
UserData.instance.genotypeResults![userDataConfig.gene] = GenotypeResult(
gene: userDataConfig.gene,
phenotype: userDataConfig.phenotype,
variant: userDataConfig.variant,
allelesTested: userDataConfig.variant,
lookupkey: userDataConfig.lookupkey,
);
}
}
41 changes: 0 additions & 41 deletions app/integration_test/fixtures/set_user_data_for_drug.dart

This file was deleted.

8 changes: 7 additions & 1 deletion app/lib/common/models/drug/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension DrugExtension on Drug {
),
);
if (anyFallbackGuideline != null) return anyFallbackGuideline;
return guidelines.firstOrNullWhere(
final exactGuideline = guidelines.firstOrNullWhere(
(guideline) => guideline.lookupkey.all(
(gene, variants) => variants.any((variant) =>
variants.contains(UserData.lookupFor(
Expand All @@ -95,6 +95,12 @@ extension DrugExtension on Drug {
)),
),
);
if (exactGuideline != null) return exactGuideline;
return guidelines.firstOrNullWhere(
(guideline) => guideline.lookupkey.all(
(gene, variants) => variants.any((variant) => variant == '~')
),
);
}

Guideline? get userOrFirstGuideline => userGuideline ??
Expand Down

0 comments on commit 4b119d2

Please sign in to comment.