diff --git a/app/lib/common/models/drug/drug.dart b/app/lib/common/models/drug/drug.dart index 0de678f0..ab12020f 100644 --- a/app/lib/common/models/drug/drug.dart +++ b/app/lib/common/models/drug/drug.dart @@ -154,13 +154,30 @@ extension DrugExtension on Drug { Guideline? get userOrFirstGuideline => userGuideline ?? (guidelines.isNotEmpty ? guidelines.first : null); - List get guidelineGenotypes => guidelines.isNotEmpty - ? guidelines.first.lookupkey.keys.flatMap( - (gene) => guidelines.first.lookupkey[gene]!.map((variant) => - GenotypeKey(gene, variant).value - ).toList().toSet() - ).toList() - : []; + List get guidelineGenotypes { + if (guidelines.isEmpty) return []; + final genotypeKeys = {}; + 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; diff --git a/app/lib/common/models/userdata/genotype_key.dart b/app/lib/common/models/userdata/genotype_key.dart index 6609ff0e..96f34a1f 100644 --- a/app/lib/common/models/userdata/genotype_key.dart +++ b/app/lib/common/models/userdata/genotype_key.dart @@ -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'; @@ -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; } \ No newline at end of file diff --git a/app/lib/common/models/userdata/genotype_result.dart b/app/lib/common/models/userdata/genotype_result.dart index 2ff2e1b6..804e519d 100644 --- a/app/lib/common/models/userdata/genotype_result.dart +++ b/app/lib/common/models/userdata/genotype_result.dart @@ -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); } diff --git a/app/lib/drug/widgets/annotation_cards/guideline.dart b/app/lib/drug/widgets/annotation_cards/guideline.dart index 6bdfd6b3..e26fa122 100644 --- a/app/lib/drug/widgets/annotation_cards/guideline.dart +++ b/app/lib/drug/widgets/annotation_cards/guideline.dart @@ -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(