Skip to content

Commit

Permalink
fix(app): do not use missing lookup values for guideline genotypes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 24, 2024
1 parent aaa723d commit 01c4cbf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
31 changes: 24 additions & 7 deletions app/lib/common/models/drug/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,30 @@ extension DrugExtension on Drug {
Guideline? get userOrFirstGuideline => userGuideline ??
(guidelines.isNotEmpty ? guidelines.first : null);

List<String> get guidelineGenotypes => guidelines.isNotEmpty
? guidelines.first.lookupkey.keys.flatMap(
(gene) => guidelines.first.lookupkey[gene]!.map((variant) =>
GenotypeKey(gene, variant).value
).toList().toSet()
).toList()
: [];
List<String> get guidelineGenotypes {
if (guidelines.isEmpty) return [];
final genotypeKeys = <String, GenotypeKey>{};
final lookupGeneCount = guidelines.first.lookupkey.keys.length;
for (final guideline in guidelines) {
if (genotypeKeys.length == lookupGeneCount) break;
for (final lookupEntry in guideline.lookupkey.entries) {
final gene = lookupEntry.key;
GenotypeKey? genotypeKey;
if (isGeneUnique(gene)) {
genotypeKey = GenotypeKey(gene, null);
} else {
for (final variant in lookupEntry.value) {
if (variant == SpecialLookup.noResult.value) continue;
genotypeKey = GenotypeKey(gene, variant);
}
}
if (genotypeKey != null) {
genotypeKeys[genotypeKey.value] = genotypeKey;
}
}
}
return genotypeKeys.values.map((genotypeKey) => genotypeKey.value).toList();
}

WarningLevel get warningLevel =>
userGuideline?.annotations.warningLevel ?? WarningLevel.none;
Expand Down
26 changes: 13 additions & 13 deletions app/lib/common/models/userdata/genotype_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,14 @@ class GenotypeKey implements Genotype {
@override
String? variant;

bool get isGeneUnique {
final isDefinedAsNonUnique = definedNonUniqueGenes.contains(gene);
if (isDefinedAsNonUnique){
return false;
}
final labData = UserData.instance.labData ?? [];
return labData.where(
(labData) => labData.gene == gene
).length <= 1;
}

// heavily relies on "non-unique" gene HLA-B, for which the variant is
// in the format "[allele] [positive/negative]" (which currently is the only)
// relevant case for "non-unique" genes)
String? get allele => variant != null
? isGeneUnique ? variant : variant!.split(' ').first
? isGeneUnique(gene) ? variant : variant!.split(' ').first
: null;

String get value => isGeneUnique
String get value => isGeneUnique(gene)
? gene
: '$gene $allele';

Expand All @@ -43,4 +32,15 @@ class GenotypeKey implements Genotype {
? genotypeKey.removePrefix(relevantGenotypeParts.first)
: null;
}
}

bool isGeneUnique(String gene) {
final isDefinedAsNonUnique = definedNonUniqueGenes.contains(gene);
if (isDefinedAsNonUnique){
return false;
}
final labData = UserData.instance.labData ?? [];
return labData.where(
(labData) => labData.gene == gene
).length <= 1;
}
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 @@ -63,7 +63,7 @@ class GenotypeResult implements Genotype {
bool removeAllele = false,
}) {
final displayString = text ?? context.l10n.general_not_tested;
return !removeAllele || key.isGeneUnique
return !removeAllele || isGeneUnique(key.gene)
? displayString
: _removeAlleleOrNull(displayString);
}
Expand Down
7 changes: 6 additions & 1 deletion app/lib/drug/widgets/annotation_cards/guideline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ class GuidelineAnnotationCard extends StatelessWidget {
];
} else {
final genotypeResults = drug.guidelineGenotypes.map((genotypeKey) =>
UserData.instance.genotypeResults![genotypeKey]!
UserData.instance.genotypeResults![genotypeKey] ??
// Should not be null but to be safe
GenotypeResult.missingResult(
GenotypeKey.extractGene(genotypeKey),
variant: GenotypeKey.maybeExtractVariant(genotypeKey),
)
).toList();
final geneDescriptions = genotypeResults.map((genotypeResult) =>
TableRowDefinition(
Expand Down

0 comments on commit 01c4cbf

Please sign in to comment.