diff --git a/app/integration_test/drugs_test.dart b/app/integration_test/drugs_test.dart index 9a25b506..bfb0b225 100644 --- a/app/integration_test/drugs_test.dart +++ b/app/integration_test/drugs_test.dart @@ -49,7 +49,7 @@ void main() { warningLevel: WarningLevel.green)) ]); UserData.instance.lookups = { - 'CYP2C9': CpicLookup( + 'CYP2C9': LookupInformation( gene: 'CYP2C9', phenotype: 'Normal Metabolizer', variant: '*1/*1', diff --git a/app/lib/common/models/drug/drug_inhibitors.dart b/app/lib/common/models/drug/drug_inhibitors.dart index 4f0bedd2..a5e00579 100644 --- a/app/lib/common/models/drug/drug_inhibitors.dart +++ b/app/lib/common/models/drug/drug_inhibitors.dart @@ -83,7 +83,7 @@ List inhibitorsFor(String gene) { return _drugInhibitorsPerGene[gene] ?? []; } -bool canBeInhibited(CpicLookup lookup) { +bool canBeInhibited(LookupInformation lookup) { return inhibitableGenes.contains(lookup.gene) && lookup.lookupkey != '0.0'; } diff --git a/app/lib/common/models/module.dart b/app/lib/common/models/module.dart index c1f60b2e..b7af9bf7 100644 --- a/app/lib/common/models/module.dart +++ b/app/lib/common/models/module.dart @@ -5,7 +5,7 @@ export 'drug/drug_inhibitors.dart'; export 'drug/guideline.dart'; export 'drug/warning_level.dart'; export 'metadata.dart'; -export 'userdata/cpic_lookup.dart'; export 'userdata/gene_result.dart'; export 'userdata/genotype.dart'; +export 'userdata/lookup_information.dart'; export 'userdata/userdata.dart'; diff --git a/app/lib/common/models/userdata/cpic_lookup.dart b/app/lib/common/models/userdata/lookup_information.dart similarity index 78% rename from app/lib/common/models/userdata/cpic_lookup.dart rename to app/lib/common/models/userdata/lookup_information.dart index b6ba59fa..3585181c 100644 --- a/app/lib/common/models/userdata/cpic_lookup.dart +++ b/app/lib/common/models/userdata/lookup_information.dart @@ -3,20 +3,20 @@ import 'package:hive/hive.dart'; import 'genotype.dart'; -part 'cpic_lookup.g.dart'; +part 'lookup_information.g.dart'; @HiveType(typeId: 2) @JsonSerializable() -class CpicLookup implements Genotype { - CpicLookup({ +class LookupInformation implements Genotype { + LookupInformation({ required this.gene, required this.phenotype, required this.variant, required this.lookupkey, }); - factory CpicLookup.fromJson(dynamic json) { - return _$CpicLookupFromJson({ + factory LookupInformation.fromJson(dynamic json) { + return _$LookupInformationFromJson({ ...json, // transform lookupkey map to string 'lookupkey': json['lookupkey'][json['genesymbol']], diff --git a/app/lib/common/models/userdata/userdata.dart b/app/lib/common/models/userdata/userdata.dart index 5ad8efe9..309be5ce 100644 --- a/app/lib/common/models/userdata/userdata.dart +++ b/app/lib/common/models/userdata/userdata.dart @@ -118,7 +118,7 @@ class UserData { UserData.instance.geneResults?[gene]?.allelesTested; @HiveField(1) - Map? lookups; + Map? lookups; static MapEntry? overwrittenLookup( String gene, @@ -223,7 +223,7 @@ Future initUserData() async { try { Hive.registerAdapter(UserDataAdapter()); Hive.registerAdapter(GeneResultAdapter()); - Hive.registerAdapter(CpicLookupAdapter()); + Hive.registerAdapter(LookupInformationAdapter()); } catch (e) { return; } diff --git a/app/lib/common/utilities/genome_data.dart b/app/lib/common/utilities/genome_data.dart index 2386ce4c..d3a7b3a6 100644 --- a/app/lib/common/utilities/genome_data.dart +++ b/app/lib/common/utilities/genome_data.dart @@ -21,6 +21,12 @@ Future getDiplotypes(String? token, String url) async { return get(Uri.parse(url), headers: {'Authorization': 'Bearer $token'}); } +String getGenotypeKey(Genotype genotype) { + // If gene is unique return gene; else return gene plus first part of variant + // (before space) + return genotype.gene; +} + Future _saveDiplotypeAndActiveDrugsResponse( Response response, ActiveDrugs activeDrugs, @@ -46,32 +52,32 @@ Future fetchAndSaveLookups() async { if (response.statusCode != 200) throw Exception(); // the returned json is a list of lookups which we wish to individually map - // to a concrete CpicLookup instance, hence the cast to a List + // to a concrete LookupInformation instance, hence the cast to a List final json = jsonDecode(response.body) as List; - final lookups = json.map(CpicLookup.fromJson); - final usersDiplotypes = UserData.instance.geneResults; - if (usersDiplotypes == null) throw Exception(); + final lookups = json.map(LookupInformation.fromJson); + final geneResults = UserData.instance.geneResults; + if (geneResults == null) throw Exception(); // use a HashMap for better time complexity - final lookupsHashMap = HashMap.fromIterable( + final lookupsHashMap = HashMap.fromIterable( lookups, key: (lookup) => '${lookup.gene}__${lookup.variant}', value: (lookup) => lookup, ); // ignore: omit_local_variable_types - final Map matchingLookups = {}; + final Map matchingLookups = {}; // extract the matching lookups - for (final diplotype in usersDiplotypes.values) { + for (final geneResult in geneResults.values) { // the gene and the genotype build the key for the hashmap - final key = '${diplotype.gene}__${diplotype.variant}'; + final key = '${geneResult.gene}__${geneResult.variant}'; final lookup = lookupsHashMap[key]; if (lookup == null) continue; // uncomment to print literal mismatches between lab/CPIC phenotypes - // if (diplotype.phenotype != lookup.phenotype) { + // if (geneResult.phenotype != lookup.phenotype) { // print( - // 'Lab phenotype ${diplotype.phenotype} for ${diplotype.gene} (${diplotype.genotype}) is "${lookup.phenotype}" for CPIC'); + // 'Lab phenotype ${geneResult.phenotype} for ${geneResult.gene} (${geneResult.genotype}) is "${lookup.phenotype}" for CPIC'); // } - matchingLookups[diplotype.gene] = lookup; + matchingLookups[geneResult.gene] = lookup; } // uncomment to make user have CYP2D6 lookupkey 0.0 diff --git a/app/lib/main.dart b/app/lib/main.dart index bfb57465..d868f73c 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -5,6 +5,7 @@ import 'common/module.dart'; Future main() async { await initServices(); + // Maybe refresh lookups on app start await fetchAndSaveLookups(); runApp( ChangeNotifierProvider( diff --git a/app/lib/report/pages/gene.dart b/app/lib/report/pages/gene.dart index dce53273..0e50c15a 100644 --- a/app/lib/report/pages/gene.dart +++ b/app/lib/report/pages/gene.dart @@ -10,7 +10,7 @@ class GenePage extends HookWidget { initialFilter: FilterState.forGene(lookup.gene), ); - final CpicLookup lookup; + final LookupInformation lookup; final DrugListCubit cubit; @override diff --git a/app/lib/report/pages/report.dart b/app/lib/report/pages/report.dart index 1bd669a1..bc878563 100644 --- a/app/lib/report/pages/report.dart +++ b/app/lib/report/pages/report.dart @@ -17,8 +17,8 @@ class ReportPage extends StatelessWidget { final notTestedString = context.l10n.general_not_tested; final userLookus = CachedDrugs.instance.allGuidelineGenes.map( (gene) => UserData.instance.lookups![gene] ?? - // Add CpicLookup for unmatched lookup - CpicLookup( + // Add LookupInformation for unmatched lookup + LookupInformation( gene: gene, // phenotype will be overwritten with phenotype from lab or inhibited // phenotype using PhenotypeInformation in GeneCard and GenePage @@ -57,7 +57,7 @@ class ReportPage extends StatelessWidget { class GeneCard extends StatelessWidget { const GeneCard(this.lookup, { super.key }); - final CpicLookup lookup; + final LookupInformation lookup; @override Widget build(BuildContext context) {