Skip to content

Commit

Permalink
feat(#684): introduce GenotypeResult
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Feb 12, 2024
1 parent 483c3f1 commit d709260
Show file tree
Hide file tree
Showing 21 changed files with 280 additions and 214 deletions.
2 changes: 1 addition & 1 deletion app/generate_screenshots/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void main() {

// Part before runApp in lib/main.dart
await initServices();
await fetchAndSaveLookups();
await updateGenotypeResults();

// Load the app
await tester.pumpWidget(
Expand Down
81 changes: 42 additions & 39 deletions app/integration_test/drugs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,52 @@ void main() {
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.onlyPumps;

final testDrug = Drug(
id: '1',
version: 1,
name: 'Ibuprofen',
rxNorm: 'rxnorm',
annotations: DrugAnnotations(
drugclass: 'NSAID',
indication: 'indication',
brandNames: ['brand name', 'another brand name']),
guidelines: [
Guideline(
id: '1',
version: 1,
lookupkey: {
'CYP2C9': ['2']
},
externalData: [
GuidelineExtData(
source: 'CPIC',
guidelineName: 'cpic name',
guidelineUrl: 'cpic url',
implications: {'CYP2C9': 'normal metabolization'},
recommendation: 'default dose',
comments: 'comments')
],
annotations: GuidelineAnnotations(
id: '1',
version: 1,
name: 'Ibuprofen',
rxNorm: 'rxnorm',
annotations: DrugAnnotations(
drugclass: 'NSAID',
indication: 'indication',
brandNames: ['brand name', 'another brand name']),
guidelines: [
Guideline(
id: '1',
version: 1,
lookupkey: {
'CYP2C9': ['2']
},
externalData: [
GuidelineExtData(
source: 'CPIC',
guidelineName: 'cpic name',
guidelineUrl: 'cpic url',
implications: {'CYP2C9': 'normal metabolization'},
recommendation: 'default dose',
implication: 'nothing',
warningLevel: WarningLevel.green))
]);
UserData.instance.lookups = {
'CYP2C9': LookupInformation(
gene: 'CYP2C9',
phenotype: 'Normal Metabolizer',
variant: '*1/*1',
lookupkey: '2')
};
UserData.instance.geneResults = {
'CYP2C9': GeneResult(
comments: 'comments')
],
annotations: GuidelineAnnotations(
recommendation: 'default dose',
implication: 'nothing',
warningLevel: WarningLevel.green))
]);
UserData.instance.geneResults = [
GeneResult(
gene: 'CYP2C9',
phenotype: 'Normal Metabolizer',
variant: '*1/*1',
allelesTested: '1')
};
allelesTested: '1',
),
];
UserData.instance.genotypeResults = {
'CYP2C9': GenotypeResult(
gene: UserData.instance.geneResults![0].gene,
phenotype: UserData.instance.geneResults![0].phenotype,
variant: UserData.instance.geneResults![0].variant,
allelesTested: UserData.instance.geneResults![0].variant,
lookupkey: '2',
),
};
final testDrugWithoutGuidelines = Drug(
id: '2',
version: 1,
Expand Down
2 changes: 1 addition & 1 deletion app/integration_test/main_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() {

binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.onlyPumps;

UserData.instance.lookups = {};
UserData.instance.genotypeResults = {};

CachedDrugs.instance.version = 1;
CachedDrugs.instance.drugs = List.empty();
Expand Down
8 changes: 6 additions & 2 deletions app/lib/common/models/drug/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ extension DrugExtension on Drug {
Guideline? get userOrFirstGuideline => userGuideline ??
(guidelines.isNotEmpty ? guidelines.first : null);

List<String> get guidelineGenes => guidelines.isNotEmpty
? guidelines.first.lookupkey.keys.toList()
List<String> get guidelineGenotypes => guidelines.isNotEmpty
? guidelines.first.lookupkey.keys.flatMap(
(gene) => guidelines.first.lookupkey[gene]!.map((variant) =>
GenotypeKey(gene, variant).value
).toList()
).toList()
: [];

WarningLevel get warningLevel =>
Expand Down
6 changes: 3 additions & 3 deletions app/lib/common/models/drug/drug_inhibitors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ List<String> inhibitorsFor(String gene) {
return _drugInhibitorsPerGene[gene] ?? [];
}

bool canBeInhibited(LookupInformation lookup) {
return inhibitableGenes.contains(lookup.gene) &&
lookup.lookupkey != '0.0';
bool canBeInhibited(GenotypeResult genotypeResult) {
return inhibitableGenes.contains(genotypeResult.gene) &&
genotypeResult.lookupkey != '0.0';
}
3 changes: 3 additions & 0 deletions app/lib/common/models/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ export 'drug/warning_level.dart';
export 'metadata.dart';
export 'userdata/gene_result.dart';
export 'userdata/genotype.dart';
export 'userdata/genotype_key.dart';
export 'userdata/genotype_result.dart';
export 'userdata/lookup_information.dart';
export 'userdata/phenotype_information.dart';
export 'userdata/userdata.dart';
6 changes: 3 additions & 3 deletions app/lib/common/models/userdata/genotype.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
abstract class Genotype{
Genotype({
const Genotype({
required this.gene,
required this.variant,
});

String gene;
String variant;
final String gene;
final String variant;
}
27 changes: 27 additions & 0 deletions app/lib/common/models/userdata/genotype_key.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import '../../module.dart';

class GenotypeKey implements Genotype {
GenotypeKey(this.gene, this.variant);

factory GenotypeKey.fromGenotype(Genotype genotype) =>
GenotypeKey(genotype.gene, genotype.variant);

@override
String gene;

@override
String variant;

String get value {
final geneResults = UserData.instance.geneResults!.where(
(geneResult) => geneResult.gene == gene
);
if (geneResults.length > 1) {
return '$gene ${variant.split(' ').first}';
}
return gene;
}

static String extractGene(String genotypeKey) =>
genotypeKey.split(' ').first;
}
59 changes: 59 additions & 0 deletions app/lib/common/models/userdata/genotype_result.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:hive/hive.dart';

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

part 'genotype_result.g.dart';

@HiveType(typeId: 2)
class GenotypeResult implements Genotype {
GenotypeResult({
required this.gene,
required this.variant,
required this.phenotype,
required this.lookupkey,
required this.allelesTested,
});

factory GenotypeResult.fromGenotypeData(
GeneResult labResult,
LookupInformation lookup,
) => GenotypeResult(
gene: labResult.gene,
variant: labResult.variant,
phenotype: labResult.phenotype,
lookupkey: lookup.lookupkey,
allelesTested: labResult.allelesTested,
);

factory GenotypeResult.missingResult(String gene, BuildContext context) =>
GenotypeResult(
gene: gene,
variant: context.l10n.general_not_tested,
phenotype: context.l10n.general_not_tested,
lookupkey: context.l10n.general_not_tested,
allelesTested: context.l10n.general_not_tested,
);

@override
@HiveField(0)
String gene;
@override
@HiveField(1)
String variant;
@HiveField(2)
String phenotype;
@HiveField(3)
String lookupkey;
@HiveField(4)
String allelesTested;

String get key => GenotypeKey.fromGenotype(this).value;
}

extension FindGenotypeResultByKey on Map<String, GenotypeResult> {
GenotypeResult findOrMissing(String genotypeKey, BuildContext context) =>
this[genotypeKey] ?? GenotypeResult.missingResult(
GenotypeKey.extractGene(genotypeKey),
context,
);
}
29 changes: 6 additions & 23 deletions app/lib/common/models/userdata/lookup_information.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hive/hive.dart';

import 'genotype.dart';

part 'lookup_information.g.dart';

@HiveType(typeId: 2)
@JsonSerializable()
class LookupInformation implements Genotype {
LookupInformation({
required this.gene,
Expand All @@ -16,28 +9,18 @@ class LookupInformation implements Genotype {
});

factory LookupInformation.fromJson(dynamic json) {
return _$LookupInformationFromJson({
...json,
// transform lookupkey map to string
'lookupkey': json['lookupkey'][json['genesymbol']],
});
return LookupInformation(
gene: json['genesymbol'] as String,
variant: json['diplotype'] as String,
phenotype: json['generesult'] as String,
lookupkey: json['lookupkey'][json['genesymbol']] as String,
);
}

@override
@HiveField(0)
@JsonKey(name: 'genesymbol')
String gene;

@override
@HiveField(1)
@JsonKey(name: 'diplotype')
String variant;

@HiveField(2)
@JsonKey(name: 'generesult')
String phenotype;

@HiveField(3)
@JsonKey(name: 'lookupkey')
String lookupkey;
}
11 changes: 11 additions & 0 deletions app/lib/common/models/userdata/phenotype_information.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class PhenotypeInformation {
PhenotypeInformation({
required this.phenotype,
this.adaptionText,
this.overwrittenPhenotypeText,
});

String phenotype;
String? adaptionText;
String? overwrittenPhenotypeText;
}
Loading

0 comments on commit d709260

Please sign in to comment.