Skip to content

Commit

Permalink
fix(#684): adapt getting lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Feb 7, 2024
1 parent 54e1ea8 commit 4fbe4bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 6 additions & 4 deletions app/lib/common/models/userdata/cpic_lookup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class CpicLookup implements Genotype {
required this.lookupkey,
});

factory CpicLookup.fromJson(Map<String, dynamic> 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
Expand Down
8 changes: 3 additions & 5 deletions app/lib/common/utilities/genome_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ Future<void> 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<dynamic>;
final lookups =
json.map((e) => CpicLookup.fromJson(e as Map<String, dynamic>));
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<String, CpicLookup>.fromIterable(
lookups,
key: (lookup) => '${lookup.gene}__${lookup.genotype}',
key: (lookup) => '${lookup.gene}__${lookup.variant}',
value: (lookup) => lookup,
);
// ignore: omit_local_variable_types
Expand Down Expand Up @@ -89,8 +88,7 @@ Future<void> 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() {
Expand Down

0 comments on commit 4fbe4bb

Please sign in to comment.