Skip to content

Commit

Permalink
refactor(#684): rename gene results to avoid confision with genotype …
Browse files Browse the repository at this point in the history
…results
  • Loading branch information
tamslo committed Feb 12, 2024
1 parent d709260 commit eb38c44
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions app/integration_test/drugs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ void main() {
implication: 'nothing',
warningLevel: WarningLevel.green))
]);
UserData.instance.geneResults = [
GeneResult(
UserData.instance.labData = [
LabResult(
gene: 'CYP2C9',
phenotype: 'Normal Metabolizer',
variant: '*1/*1',
Expand All @@ -58,10 +58,10 @@ void main() {
];
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,
gene: UserData.instance.labData![0].gene,
phenotype: UserData.instance.labData![0].phenotype,
variant: UserData.instance.labData![0].variant,
allelesTested: UserData.instance.labData![0].variant,
lookupkey: '2',
),
};
Expand Down
4 changes: 2 additions & 2 deletions app/lib/common/models/drug/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ extension DrugExtension on Drug {

Guideline? get userGuideline => guidelines.firstOrNullWhere(
(guideline) => guideline.lookupkey.all(
(gene, geneResults) =>
geneResults.contains(UserData.lookupFor(gene, drug: name))
(gene, variants) =>
variants.contains(UserData.lookupFor(gene, drug: name))
),
);

Expand Down
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,10 +5,10 @@ export 'drug/drug_inhibitors.dart';
export 'drug/guideline.dart';
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/lab_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_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class GenotypeKey implements Genotype {
String variant;

String get value {
final geneResults = UserData.instance.geneResults!.where(
(geneResult) => geneResult.gene == gene
final geneData = UserData.instance.labData!.where(
(labData) => labData.gene == gene
);
if (geneResults.length > 1) {
if (geneData.length > 1) {
return '$gene ${variant.split(' ').first}';
}
return gene;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/common/models/userdata/genotype_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GenotypeResult implements Genotype {
});

factory GenotypeResult.fromGenotypeData(
GeneResult labResult,
LabResult labResult,
LookupInformation lookup,
) => GenotypeResult(
gene: labResult.gene,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import 'package:hive/hive.dart';
import 'package:http/http.dart';
import 'genotype.dart';

part 'gene_result.g.dart';
part 'lab_result.g.dart';

@HiveType(typeId: 1)
@JsonSerializable()
class GeneResult implements Genotype {
GeneResult({
class LabResult implements Genotype {
LabResult({
required this.gene,
required this.variant,
required this.phenotype,
required this.allelesTested,
});

factory GeneResult.fromJson(dynamic json) => _$GeneResultFromJson(json);
Map<String, dynamic> toJson() => _$GeneResultToJson(this);
factory LabResult.fromJson(dynamic json) => _$LabResultFromJson(json);
Map<String, dynamic> toJson() => _$LabResultToJson(this);

@override
@HiveField(0)
Expand All @@ -37,7 +37,7 @@ class GeneResult implements Genotype {
}

// assumes http reponse from lab server
List<GeneResult> geneResultsFromHTTPResponse(Response resp) {
List<LabResult> labDataFromHTTPResponse(Response resp) {
final json = jsonDecode(resp.body)['diplotypes'] as List<dynamic>;
return json.map<GeneResult>(GeneResult.fromJson).toList();
return json.map<LabResult>(LabResult.fromJson).toList();
}
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 @@ -34,7 +34,7 @@ class UserData {
}

@HiveField(0)
List<GeneResult>? geneResults;
List<LabResult>? labData;
@HiveField(1)
// hive can't deal with sets so we have to use a list :(
List<String>? activeDrugNames;
Expand Down Expand Up @@ -210,7 +210,7 @@ Future<void> initUserData() async {
// session which has not yet been written to local storage.
try {
Hive.registerAdapter(UserDataAdapter());
Hive.registerAdapter(GeneResultAdapter());
Hive.registerAdapter(LabResultAdapter());
Hive.registerAdapter(GenotypeResultAdapter());
} catch (e) {
return;
Expand Down
16 changes: 8 additions & 8 deletions app/lib/common/utilities/genome_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Future<void> _saveDiplotypeAndActiveDrugsResponse(
Response response,
ActiveDrugs activeDrugs,
) async {
// parse response to list of user's geneResults
final geneResults =
geneResultsFromHTTPResponse(response);
// parse response to list of user's labData
final labData =
labDataFromHTTPResponse(response);
final activeDrugList = activeDrugsFromHTTPResponse(response);

UserData.instance.geneResults = geneResults;
UserData.instance.labData = labData;
await UserData.save();
await activeDrugs.setList(activeDrugList);
// invalidate cached drugs because lookups may have changed and we need to
Expand All @@ -54,7 +54,7 @@ Future<void> updateGenotypeResults() async {
final genotypeResults = <String, GenotypeResult>{};
// we know that labData is present because we check this in
// shouldUpdateGenotypeResults
for (final labResult in UserData.instance.geneResults!) {
for (final labResult in UserData.instance.labData!) {
final key = '${labResult.gene}__${labResult.variant}';
final lookup = lookupsHashMap[key];
if (lookup == null) continue;
Expand All @@ -72,13 +72,13 @@ Future<void> updateGenotypeResults() async {

bool shouldUpdateGenotypeResults() {
final genotypeResultsPresent =
UserData.instance.geneResults?.isNotEmpty ?? false;
final labDataPresent = UserData.instance.geneResults?.isNotEmpty ?? false;
UserData.instance.labData?.isNotEmpty ?? false;
final labDataPresent = UserData.instance.labData?.isNotEmpty ?? false;
return (!genotypeResultsPresent || _isOutDated()) && labDataPresent;
}

bool shouldFetchDiplotypes() {
return UserData.instance.geneResults == null;
return UserData.instance.labData == null;
}

bool _isOutDated() {
Expand Down

0 comments on commit eb38c44

Please sign in to comment.