Skip to content

Commit

Permalink
refactor(#684): rename CpicLookup to LookupInformation
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Feb 7, 2024
1 parent 4fbe4bb commit 483c3f1
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/integration_test/drugs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void main() {
warningLevel: WarningLevel.green))
]);
UserData.instance.lookups = {
'CYP2C9': CpicLookup(
'CYP2C9': LookupInformation(
gene: 'CYP2C9',
phenotype: 'Normal Metabolizer',
variant: '*1/*1',
Expand Down
2 changes: 1 addition & 1 deletion 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(CpicLookup lookup) {
bool canBeInhibited(LookupInformation lookup) {
return inhibitableGenes.contains(lookup.gene) &&
lookup.lookupkey != '0.0';
}
2 changes: 1 addition & 1 deletion app/lib/common/models/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
Expand Down
4 changes: 2 additions & 2 deletions app/lib/common/models/userdata/userdata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class UserData {
UserData.instance.geneResults?[gene]?.allelesTested;

@HiveField(1)
Map<String, CpicLookup>? lookups;
Map<String, LookupInformation>? lookups;

static MapEntry<String, String>? overwrittenLookup(
String gene,
Expand Down Expand Up @@ -223,7 +223,7 @@ Future<void> initUserData() async {
try {
Hive.registerAdapter(UserDataAdapter());
Hive.registerAdapter(GeneResultAdapter());
Hive.registerAdapter(CpicLookupAdapter());
Hive.registerAdapter(LookupInformationAdapter());
} catch (e) {
return;
}
Expand Down
28 changes: 17 additions & 11 deletions app/lib/common/utilities/genome_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Future<Response> 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<void> _saveDiplotypeAndActiveDrugsResponse(
Response response,
ActiveDrugs activeDrugs,
Expand All @@ -46,32 +52,32 @@ Future<void> 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<dynamic>;
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<String, CpicLookup>.fromIterable(
final lookupsHashMap = HashMap<String, LookupInformation>.fromIterable(
lookups,
key: (lookup) => '${lookup.gene}__${lookup.variant}',
value: (lookup) => lookup,
);
// ignore: omit_local_variable_types
final Map<String, CpicLookup> matchingLookups = {};
final Map<String, LookupInformation> 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
Expand Down
1 change: 1 addition & 0 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'common/module.dart';

Future<void> main() async {
await initServices();
// Maybe refresh lookups on app start
await fetchAndSaveLookups();
runApp(
ChangeNotifierProvider(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/report/pages/gene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GenePage extends HookWidget {
initialFilter: FilterState.forGene(lookup.gene),
);

final CpicLookup lookup;
final LookupInformation lookup;
final DrugListCubit cubit;

@override
Expand Down
6 changes: 3 additions & 3 deletions app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 483c3f1

Please sign in to comment.