From 4fbe4bb41c49b426f6086680fc3c249d713f7ae0 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Wed, 7 Feb 2024 14:13:05 +0100 Subject: [PATCH] fix(#684): adapt getting lookups --- app/lib/common/models/userdata/cpic_lookup.dart | 10 ++++++---- app/lib/common/utilities/genome_data.dart | 8 +++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/lib/common/models/userdata/cpic_lookup.dart b/app/lib/common/models/userdata/cpic_lookup.dart index 2be142ec..b6ba59fa 100644 --- a/app/lib/common/models/userdata/cpic_lookup.dart +++ b/app/lib/common/models/userdata/cpic_lookup.dart @@ -15,10 +15,12 @@ class CpicLookup implements Genotype { required this.lookupkey, }); - factory CpicLookup.fromJson(Map json) { - // transform lookupkey map to string - json['lookupkey'] = json['lookupkey'][json['genesymbol']]; - return _$CpicLookupFromJson(json); + factory CpicLookup.fromJson(dynamic json) { + return _$CpicLookupFromJson({ + ...json, + // transform lookupkey map to string + 'lookupkey': json['lookupkey'][json['genesymbol']], + }); } @override diff --git a/app/lib/common/utilities/genome_data.dart b/app/lib/common/utilities/genome_data.dart index e69830cb..2386ce4c 100644 --- a/app/lib/common/utilities/genome_data.dart +++ b/app/lib/common/utilities/genome_data.dart @@ -48,15 +48,14 @@ Future fetchAndSaveLookups() async { // 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 final json = jsonDecode(response.body) as List; - final lookups = - json.map((e) => CpicLookup.fromJson(e as Map)); + final lookups = json.map(CpicLookup.fromJson); final usersDiplotypes = UserData.instance.geneResults; if (usersDiplotypes == null) throw Exception(); // use a HashMap for better time complexity final lookupsHashMap = HashMap.fromIterable( lookups, - key: (lookup) => '${lookup.gene}__${lookup.genotype}', + key: (lookup) => '${lookup.gene}__${lookup.variant}', value: (lookup) => lookup, ); // ignore: omit_local_variable_types @@ -89,8 +88,7 @@ Future fetchAndSaveLookups() async { bool shouldFetchLookups() { final lookupsPresent = UserData.instance.lookups?.isNotEmpty ?? false; final diplotypesPresent = UserData.instance.geneResults?.isNotEmpty ?? false; - final result = (_isOutDated() || !lookupsPresent) && diplotypesPresent; - return result; + return (_isOutDated() || !lookupsPresent) && diplotypesPresent; } bool shouldFetchDiplotypes() {