terraphim_types 1.16.34

Core types crate for Terraphim AI
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
//! Medical type definitions for clinical and biomedical knowledge graphs.
//!
//! This module provides strongly-typed node and edge types for medical/biomedical
//! knowledge graphs, covering entities and relationships from clinical workflows,
//! molecular biology (PrimeKG), and drug-disease interactions.
//!
//! # Features
//!
//! This module is gated behind the `medical` feature flag.
//!
//! # Examples
//!
//! ```
//! use terraphim_types::medical_types::{MedicalNodeType, MedicalEdgeType, MedicalNodeMetadata};
//!
//! let node_type = MedicalNodeType::Disease;
//! let edge_type = MedicalEdgeType::Treats;
//!
//! assert_eq!(node_type.to_string(), "disease");
//! assert_eq!(edge_type.to_string(), "treats");
//!
//! let metadata = MedicalNodeMetadata::default();
//! assert!(metadata.metadata.is_empty());
//! ```

use ahash::AHashMap;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};

/// Node types for medical/biomedical knowledge graphs.
///
/// Covers clinical entities (diseases, drugs, symptoms), molecular biology
/// entities (genes, proteins, pathways), and ontology concepts.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum MedicalNodeType {
    /// Generic concept node (default)
    #[default]
    Concept,
    /// A disease or medical condition
    Disease,
    /// A pharmaceutical drug
    Drug,
    /// A gene
    Gene,
    /// A genetic variant
    Variant,
    /// A medical procedure
    Procedure,
    /// A treatment regimen
    Treatment,
    /// A clinical symptom
    Symptom,
    /// A protein
    Protein,
    /// A biological process (Gene Ontology)
    BiologicalProcess,
    /// A molecular function (Gene Ontology)
    MolecularFunction,
    /// A cellular component (Gene Ontology)
    CellularComponent,
    /// A biological pathway
    Pathway,
    /// An anatomical structure
    Anatomy,
    /// A phenotype or observable trait
    Phenotype,
    /// An enzyme
    Enzyme,
    /// A drug transporter
    Transporter,
    /// A drug carrier
    Carrier,
    /// A drug target
    Target,
    /// A metabolite
    Metabolite,
    /// An environmental or chemical exposure
    Exposure,
    /// A chemical compound
    Chemical,
    /// A side effect
    SideEffect,
    /// A tissue type
    Tissue,
    /// A cell type
    CellType,
    /// An organism
    Organism,
    /// A term from a formal ontology
    OntologyTerm,
}

impl Display for MedicalNodeType {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        let s = match self {
            Self::Concept => "concept",
            Self::Disease => "disease",
            Self::Drug => "drug",
            Self::Gene => "gene",
            Self::Variant => "variant",
            Self::Procedure => "procedure",
            Self::Treatment => "treatment",
            Self::Symptom => "symptom",
            Self::Protein => "protein",
            Self::BiologicalProcess => "biological_process",
            Self::MolecularFunction => "molecular_function",
            Self::CellularComponent => "cellular_component",
            Self::Pathway => "pathway",
            Self::Anatomy => "anatomy",
            Self::Phenotype => "phenotype",
            Self::Enzyme => "enzyme",
            Self::Transporter => "transporter",
            Self::Carrier => "carrier",
            Self::Target => "target",
            Self::Metabolite => "metabolite",
            Self::Exposure => "exposure",
            Self::Chemical => "chemical",
            Self::SideEffect => "side_effect",
            Self::Tissue => "tissue",
            Self::CellType => "cell_type",
            Self::Organism => "organism",
            Self::OntologyTerm => "ontology_term",
        };
        write!(f, "{}", s)
    }
}

/// Edge types for medical/biomedical knowledge graphs.
///
/// Organized by category:
/// - Core relationships (IsA, Treats, Causes, etc.)
/// - PrimeKG molecular relationships (AssociatedWith, InteractsWith, etc.)
/// - Clinical workflow temporal relationships (OccursBefore, OccursAfter, etc.)
/// - Severity and probability relationships (Exacerbates, Alleviates, etc.)
/// - Diagnostic relationships (Diagnoses, Confirms, etc.)
/// - Clinical course relationships (ProgressesTo, ResolvesTo, etc.)
/// - Treatment detail relationships (AdministeredVia, CombinedWith, etc.)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum MedicalEdgeType {
    // -- Core relationships --
    /// Subsumption / taxonomy relationship
    IsA,
    /// Drug treats disease
    Treats,
    /// Entity causes condition
    Causes,
    /// Drug is contraindicated for condition
    Contraindicates,
    /// Drug is metabolized by enzyme
    MetabolizedBy,
    /// Entity has phenotype
    HasPhenotype,
    /// Entity has genetic variant
    HasVariant,
    /// Entity is part of another entity
    PartOf,
    /// Generic relationship (default)
    #[default]
    RelatedTo,

    // -- PrimeKG molecular relationships --
    /// General association
    AssociatedWith,
    /// General linkage
    LinkedTo,
    /// Molecular interaction
    InteractsWith,
    /// Entity has associated gene
    HasGene,
    /// Entity has associated protein
    HasProtein,
    /// Drug has enzyme interaction
    HasEnzyme,
    /// Drug has transporter interaction
    HasTransporter,
    /// Drug has carrier interaction
    HasCarrier,
    /// Drug has target interaction
    HasTarget,
    /// Drug has side effect
    HasSideEffect,
    /// Drug has indication
    HasIndication,
    /// Drug has contraindication
    HasContraindication,
    /// Drug has off-label use
    HasOffLabelUse,
    /// Entity has effect
    HasEffect,
    /// Entity has exposure
    HasExposure,
    /// Entity has symptom
    HasSymptom,
    /// Entity has anatomy association
    HasAnatomy,
    /// Entity has pathway association
    HasPathway,
    /// Entity has molecular function
    HasMolecularFunction,
    /// Entity has biological process
    HasBiologicalProcess,
    /// Entity has cellular component
    HasCellularComponent,
    /// Entity has tissue association
    HasTissue,
    /// Entity has cell type association
    HasCellType,
    /// Gene/protein is expressed in tissue
    Expresses,
    /// Entity regulates another
    Regulates,
    /// Entity participates in process
    ParticipatesIn,
    /// Entity upregulates another
    Upregulates,
    /// Entity downregulates another
    Downregulates,
    /// Molecule binds to target
    BindsTo,
    /// Enzyme catalyzes reaction
    Catalyzes,
    /// Transporter moves substrate
    Transports,
    /// Entity inhibits another
    Inhibits,
    /// Entity activates another
    Activates,
    /// Entity modulates another
    Modulates,
    /// Entities are similar
    SimilarTo,
    /// Entity is derived from another
    DerivedFrom,
    /// Entity is a member of a group
    MemberOf,

    // -- Clinical workflow: Temporal --
    /// Event occurs before another
    OccursBefore,
    /// Event occurs after another
    OccursAfter,
    /// Events are concurrent
    ConcurrentWith,
    /// Event follows another
    Follows,

    // -- Severity / probability --
    /// Entity exacerbates a condition
    Exacerbates,
    /// Entity alleviates a condition
    Alleviates,
    /// Entity predisposes to a condition
    PredisposesTo,
    /// Entity protects against a condition
    ProtectsAgainst,

    // -- Diagnostic --
    /// Test diagnoses condition
    Diagnoses,
    /// Test confirms condition
    Confirms,
    /// Test rules out condition
    RulesOut,
    /// Finding suggests condition
    Suggests,
    /// Finding indicates condition
    Indicates,

    // -- Clinical course --
    /// Condition progresses to another
    ProgressesTo,
    /// Condition resolves to state
    ResolvesTo,
    /// Condition recurs as another
    RecursAs,
    /// Condition complicates another
    Complicates,

    // -- Treatment detail --
    /// Drug administered via route
    AdministeredVia,
    /// Drug combined with another
    CombinedWith,
    /// Drug is an alternative to another
    AlternativesTo,
    /// Drug synergizes with another
    SynergizesWith,
    /// Drug antagonizes another
    Antagonizes,
}

impl Display for MedicalEdgeType {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        let s = match self {
            // Core relationships
            Self::IsA => "is_a",
            Self::Treats => "treats",
            Self::Causes => "causes",
            Self::Contraindicates => "contraindicates",
            Self::MetabolizedBy => "metabolized_by",
            Self::HasPhenotype => "has_phenotype",
            Self::HasVariant => "has_variant",
            Self::PartOf => "part_of",
            Self::RelatedTo => "related_to",
            // PrimeKG molecular
            Self::AssociatedWith => "associated_with",
            Self::LinkedTo => "linked_to",
            Self::InteractsWith => "interacts_with",
            Self::HasGene => "has_gene",
            Self::HasProtein => "has_protein",
            Self::HasEnzyme => "has_enzyme",
            Self::HasTransporter => "has_transporter",
            Self::HasCarrier => "has_carrier",
            Self::HasTarget => "has_target",
            Self::HasSideEffect => "has_side_effect",
            Self::HasIndication => "has_indication",
            Self::HasContraindication => "has_contraindication",
            Self::HasOffLabelUse => "has_off_label_use",
            Self::HasEffect => "has_effect",
            Self::HasExposure => "has_exposure",
            Self::HasSymptom => "has_symptom",
            Self::HasAnatomy => "has_anatomy",
            Self::HasPathway => "has_pathway",
            Self::HasMolecularFunction => "has_molecular_function",
            Self::HasBiologicalProcess => "has_biological_process",
            Self::HasCellularComponent => "has_cellular_component",
            Self::HasTissue => "has_tissue",
            Self::HasCellType => "has_cell_type",
            Self::Expresses => "expresses",
            Self::Regulates => "regulates",
            Self::ParticipatesIn => "participates_in",
            Self::Upregulates => "upregulates",
            Self::Downregulates => "downregulates",
            Self::BindsTo => "binds_to",
            Self::Catalyzes => "catalyzes",
            Self::Transports => "transports",
            Self::Inhibits => "inhibits",
            Self::Activates => "activates",
            Self::Modulates => "modulates",
            Self::SimilarTo => "similar_to",
            Self::DerivedFrom => "derived_from",
            Self::MemberOf => "member_of",
            // Clinical workflow: Temporal
            Self::OccursBefore => "occurs_before",
            Self::OccursAfter => "occurs_after",
            Self::ConcurrentWith => "concurrent_with",
            Self::Follows => "follows",
            // Severity / probability
            Self::Exacerbates => "exacerbates",
            Self::Alleviates => "alleviates",
            Self::PredisposesTo => "predisposes_to",
            Self::ProtectsAgainst => "protects_against",
            // Diagnostic
            Self::Diagnoses => "diagnoses",
            Self::Confirms => "confirms",
            Self::RulesOut => "rules_out",
            Self::Suggests => "suggests",
            Self::Indicates => "indicates",
            // Clinical course
            Self::ProgressesTo => "progresses_to",
            Self::ResolvesTo => "resolves_to",
            Self::RecursAs => "recurs_as",
            Self::Complicates => "complicates",
            // Treatment detail
            Self::AdministeredVia => "administered_via",
            Self::CombinedWith => "combined_with",
            Self::AlternativesTo => "alternatives_to",
            Self::SynergizesWith => "synergizes_with",
            Self::Antagonizes => "antagonizes",
        };
        write!(f, "{}", s)
    }
}

/// Metadata container for medical nodes.
///
/// Stores arbitrary key-value metadata associated with a medical knowledge
/// graph node, such as source database identifiers, confidence scores,
/// or provenance information.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct MedicalNodeMetadata {
    /// Arbitrary key-value metadata
    pub metadata: AHashMap<String, String>,
}

impl MedicalNodeMetadata {
    /// Create a new empty metadata container
    pub fn new() -> Self {
        Self {
            metadata: AHashMap::new(),
        }
    }

    /// Insert a key-value pair into the metadata
    pub fn insert(&mut self, key: String, value: String) {
        self.metadata.insert(key, value);
    }

    /// Get a value by key
    pub fn get(&self, key: &str) -> Option<&String> {
        self.metadata.get(key)
    }

    /// Check if the metadata is empty
    pub fn is_empty(&self) -> bool {
        self.metadata.is_empty()
    }

    /// Get the number of metadata entries
    pub fn len(&self) -> usize {
        self.metadata.len()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_medical_node_type_default() {
        let node_type = MedicalNodeType::default();
        assert_eq!(node_type, MedicalNodeType::Concept);
    }

    #[test]
    fn test_medical_edge_type_default() {
        let edge_type = MedicalEdgeType::default();
        assert_eq!(edge_type, MedicalEdgeType::RelatedTo);
    }

    #[test]
    fn test_medical_node_type_display() {
        assert_eq!(MedicalNodeType::Concept.to_string(), "concept");
        assert_eq!(MedicalNodeType::Disease.to_string(), "disease");
        assert_eq!(MedicalNodeType::Drug.to_string(), "drug");
        assert_eq!(MedicalNodeType::Gene.to_string(), "gene");
        assert_eq!(MedicalNodeType::Variant.to_string(), "variant");
        assert_eq!(MedicalNodeType::Procedure.to_string(), "procedure");
        assert_eq!(MedicalNodeType::Treatment.to_string(), "treatment");
        assert_eq!(MedicalNodeType::Symptom.to_string(), "symptom");
        assert_eq!(MedicalNodeType::Protein.to_string(), "protein");
        assert_eq!(
            MedicalNodeType::BiologicalProcess.to_string(),
            "biological_process"
        );
        assert_eq!(
            MedicalNodeType::MolecularFunction.to_string(),
            "molecular_function"
        );
        assert_eq!(
            MedicalNodeType::CellularComponent.to_string(),
            "cellular_component"
        );
        assert_eq!(MedicalNodeType::Pathway.to_string(), "pathway");
        assert_eq!(MedicalNodeType::Anatomy.to_string(), "anatomy");
        assert_eq!(MedicalNodeType::Phenotype.to_string(), "phenotype");
        assert_eq!(MedicalNodeType::Enzyme.to_string(), "enzyme");
        assert_eq!(MedicalNodeType::Transporter.to_string(), "transporter");
        assert_eq!(MedicalNodeType::Carrier.to_string(), "carrier");
        assert_eq!(MedicalNodeType::Target.to_string(), "target");
        assert_eq!(MedicalNodeType::Metabolite.to_string(), "metabolite");
        assert_eq!(MedicalNodeType::Exposure.to_string(), "exposure");
        assert_eq!(MedicalNodeType::Chemical.to_string(), "chemical");
        assert_eq!(MedicalNodeType::SideEffect.to_string(), "side_effect");
        assert_eq!(MedicalNodeType::Tissue.to_string(), "tissue");
        assert_eq!(MedicalNodeType::CellType.to_string(), "cell_type");
        assert_eq!(MedicalNodeType::Organism.to_string(), "organism");
        assert_eq!(MedicalNodeType::OntologyTerm.to_string(), "ontology_term");
    }

    #[test]
    fn test_medical_edge_type_display() {
        // Core relationships
        assert_eq!(MedicalEdgeType::IsA.to_string(), "is_a");
        assert_eq!(MedicalEdgeType::Treats.to_string(), "treats");
        assert_eq!(MedicalEdgeType::Causes.to_string(), "causes");
        assert_eq!(
            MedicalEdgeType::Contraindicates.to_string(),
            "contraindicates"
        );
        assert_eq!(MedicalEdgeType::MetabolizedBy.to_string(), "metabolized_by");
        assert_eq!(MedicalEdgeType::HasPhenotype.to_string(), "has_phenotype");
        assert_eq!(MedicalEdgeType::HasVariant.to_string(), "has_variant");
        assert_eq!(MedicalEdgeType::PartOf.to_string(), "part_of");
        assert_eq!(MedicalEdgeType::RelatedTo.to_string(), "related_to");

        // PrimeKG molecular
        assert_eq!(
            MedicalEdgeType::AssociatedWith.to_string(),
            "associated_with"
        );
        assert_eq!(MedicalEdgeType::InteractsWith.to_string(), "interacts_with");
        assert_eq!(MedicalEdgeType::HasGene.to_string(), "has_gene");
        assert_eq!(MedicalEdgeType::HasProtein.to_string(), "has_protein");
        assert_eq!(MedicalEdgeType::HasEnzyme.to_string(), "has_enzyme");
        assert_eq!(
            MedicalEdgeType::HasTransporter.to_string(),
            "has_transporter"
        );
        assert_eq!(MedicalEdgeType::HasCarrier.to_string(), "has_carrier");
        assert_eq!(MedicalEdgeType::HasTarget.to_string(), "has_target");
        assert_eq!(
            MedicalEdgeType::HasSideEffect.to_string(),
            "has_side_effect"
        );
        assert_eq!(MedicalEdgeType::HasIndication.to_string(), "has_indication");
        assert_eq!(
            MedicalEdgeType::HasContraindication.to_string(),
            "has_contraindication"
        );
        assert_eq!(
            MedicalEdgeType::HasOffLabelUse.to_string(),
            "has_off_label_use"
        );
        assert_eq!(MedicalEdgeType::Expresses.to_string(), "expresses");
        assert_eq!(MedicalEdgeType::Regulates.to_string(), "regulates");
        assert_eq!(
            MedicalEdgeType::ParticipatesIn.to_string(),
            "participates_in"
        );
        assert_eq!(MedicalEdgeType::Upregulates.to_string(), "upregulates");
        assert_eq!(MedicalEdgeType::Downregulates.to_string(), "downregulates");
        assert_eq!(MedicalEdgeType::BindsTo.to_string(), "binds_to");
        assert_eq!(MedicalEdgeType::Catalyzes.to_string(), "catalyzes");
        assert_eq!(MedicalEdgeType::Transports.to_string(), "transports");
        assert_eq!(MedicalEdgeType::Inhibits.to_string(), "inhibits");
        assert_eq!(MedicalEdgeType::Activates.to_string(), "activates");
        assert_eq!(MedicalEdgeType::Modulates.to_string(), "modulates");
        assert_eq!(MedicalEdgeType::SimilarTo.to_string(), "similar_to");
        assert_eq!(MedicalEdgeType::DerivedFrom.to_string(), "derived_from");
        assert_eq!(MedicalEdgeType::MemberOf.to_string(), "member_of");

        // Clinical workflow: Temporal
        assert_eq!(MedicalEdgeType::OccursBefore.to_string(), "occurs_before");
        assert_eq!(MedicalEdgeType::OccursAfter.to_string(), "occurs_after");
        assert_eq!(
            MedicalEdgeType::ConcurrentWith.to_string(),
            "concurrent_with"
        );
        assert_eq!(MedicalEdgeType::Follows.to_string(), "follows");

        // Severity / probability
        assert_eq!(MedicalEdgeType::Exacerbates.to_string(), "exacerbates");
        assert_eq!(MedicalEdgeType::Alleviates.to_string(), "alleviates");
        assert_eq!(MedicalEdgeType::PredisposesTo.to_string(), "predisposes_to");
        assert_eq!(
            MedicalEdgeType::ProtectsAgainst.to_string(),
            "protects_against"
        );

        // Diagnostic
        assert_eq!(MedicalEdgeType::Diagnoses.to_string(), "diagnoses");
        assert_eq!(MedicalEdgeType::Confirms.to_string(), "confirms");
        assert_eq!(MedicalEdgeType::RulesOut.to_string(), "rules_out");
        assert_eq!(MedicalEdgeType::Suggests.to_string(), "suggests");
        assert_eq!(MedicalEdgeType::Indicates.to_string(), "indicates");

        // Clinical course
        assert_eq!(MedicalEdgeType::ProgressesTo.to_string(), "progresses_to");
        assert_eq!(MedicalEdgeType::ResolvesTo.to_string(), "resolves_to");
        assert_eq!(MedicalEdgeType::RecursAs.to_string(), "recurs_as");
        assert_eq!(MedicalEdgeType::Complicates.to_string(), "complicates");

        // Treatment detail
        assert_eq!(
            MedicalEdgeType::AdministeredVia.to_string(),
            "administered_via"
        );
        assert_eq!(MedicalEdgeType::CombinedWith.to_string(), "combined_with");
        assert_eq!(
            MedicalEdgeType::AlternativesTo.to_string(),
            "alternatives_to"
        );
        assert_eq!(
            MedicalEdgeType::SynergizesWith.to_string(),
            "synergizes_with"
        );
        assert_eq!(MedicalEdgeType::Antagonizes.to_string(), "antagonizes");
    }

    #[test]
    fn test_medical_node_type_serde_roundtrip() {
        let variants = vec![
            MedicalNodeType::Concept,
            MedicalNodeType::Disease,
            MedicalNodeType::Drug,
            MedicalNodeType::Gene,
            MedicalNodeType::Variant,
            MedicalNodeType::Procedure,
            MedicalNodeType::Treatment,
            MedicalNodeType::Symptom,
            MedicalNodeType::Protein,
            MedicalNodeType::BiologicalProcess,
            MedicalNodeType::MolecularFunction,
            MedicalNodeType::CellularComponent,
            MedicalNodeType::Pathway,
            MedicalNodeType::Anatomy,
            MedicalNodeType::Phenotype,
            MedicalNodeType::Enzyme,
            MedicalNodeType::Transporter,
            MedicalNodeType::Carrier,
            MedicalNodeType::Target,
            MedicalNodeType::Metabolite,
            MedicalNodeType::Exposure,
            MedicalNodeType::Chemical,
            MedicalNodeType::SideEffect,
            MedicalNodeType::Tissue,
            MedicalNodeType::CellType,
            MedicalNodeType::Organism,
            MedicalNodeType::OntologyTerm,
        ];

        for variant in variants {
            let json = serde_json::to_string(&variant).unwrap();
            let deserialized: MedicalNodeType = serde_json::from_str(&json).unwrap();
            assert_eq!(variant, deserialized, "roundtrip failed for {:?}", variant);
        }
    }

    #[test]
    fn test_medical_edge_type_serde_roundtrip() {
        let variants = vec![
            MedicalEdgeType::IsA,
            MedicalEdgeType::Treats,
            MedicalEdgeType::Causes,
            MedicalEdgeType::Contraindicates,
            MedicalEdgeType::MetabolizedBy,
            MedicalEdgeType::HasPhenotype,
            MedicalEdgeType::HasVariant,
            MedicalEdgeType::PartOf,
            MedicalEdgeType::RelatedTo,
            MedicalEdgeType::AssociatedWith,
            MedicalEdgeType::LinkedTo,
            MedicalEdgeType::InteractsWith,
            MedicalEdgeType::HasGene,
            MedicalEdgeType::HasProtein,
            MedicalEdgeType::HasEnzyme,
            MedicalEdgeType::HasTransporter,
            MedicalEdgeType::HasCarrier,
            MedicalEdgeType::HasTarget,
            MedicalEdgeType::HasSideEffect,
            MedicalEdgeType::HasIndication,
            MedicalEdgeType::HasContraindication,
            MedicalEdgeType::HasOffLabelUse,
            MedicalEdgeType::HasEffect,
            MedicalEdgeType::HasExposure,
            MedicalEdgeType::HasSymptom,
            MedicalEdgeType::HasAnatomy,
            MedicalEdgeType::HasPathway,
            MedicalEdgeType::HasMolecularFunction,
            MedicalEdgeType::HasBiologicalProcess,
            MedicalEdgeType::HasCellularComponent,
            MedicalEdgeType::HasTissue,
            MedicalEdgeType::HasCellType,
            MedicalEdgeType::Expresses,
            MedicalEdgeType::Regulates,
            MedicalEdgeType::ParticipatesIn,
            MedicalEdgeType::Upregulates,
            MedicalEdgeType::Downregulates,
            MedicalEdgeType::BindsTo,
            MedicalEdgeType::Catalyzes,
            MedicalEdgeType::Transports,
            MedicalEdgeType::Inhibits,
            MedicalEdgeType::Activates,
            MedicalEdgeType::Modulates,
            MedicalEdgeType::SimilarTo,
            MedicalEdgeType::DerivedFrom,
            MedicalEdgeType::MemberOf,
            MedicalEdgeType::OccursBefore,
            MedicalEdgeType::OccursAfter,
            MedicalEdgeType::ConcurrentWith,
            MedicalEdgeType::Follows,
            MedicalEdgeType::Exacerbates,
            MedicalEdgeType::Alleviates,
            MedicalEdgeType::PredisposesTo,
            MedicalEdgeType::ProtectsAgainst,
            MedicalEdgeType::Diagnoses,
            MedicalEdgeType::Confirms,
            MedicalEdgeType::RulesOut,
            MedicalEdgeType::Suggests,
            MedicalEdgeType::Indicates,
            MedicalEdgeType::ProgressesTo,
            MedicalEdgeType::ResolvesTo,
            MedicalEdgeType::RecursAs,
            MedicalEdgeType::Complicates,
            MedicalEdgeType::AdministeredVia,
            MedicalEdgeType::CombinedWith,
            MedicalEdgeType::AlternativesTo,
            MedicalEdgeType::SynergizesWith,
            MedicalEdgeType::Antagonizes,
        ];

        for variant in variants {
            let json = serde_json::to_string(&variant).unwrap();
            let deserialized: MedicalEdgeType = serde_json::from_str(&json).unwrap();
            assert_eq!(variant, deserialized, "roundtrip failed for {:?}", variant);
        }
    }

    #[test]
    fn test_medical_node_type_serde_snake_case() {
        // Verify serde uses snake_case format
        let json = serde_json::to_string(&MedicalNodeType::BiologicalProcess).unwrap();
        assert_eq!(json, "\"biological_process\"");

        let json = serde_json::to_string(&MedicalNodeType::CellType).unwrap();
        assert_eq!(json, "\"cell_type\"");

        let json = serde_json::to_string(&MedicalNodeType::OntologyTerm).unwrap();
        assert_eq!(json, "\"ontology_term\"");

        // Verify deserialization from snake_case
        let node_type: MedicalNodeType = serde_json::from_str("\"biological_process\"").unwrap();
        assert_eq!(node_type, MedicalNodeType::BiologicalProcess);
    }

    #[test]
    fn test_medical_edge_type_serde_snake_case() {
        let json = serde_json::to_string(&MedicalEdgeType::MetabolizedBy).unwrap();
        assert_eq!(json, "\"metabolized_by\"");

        let json = serde_json::to_string(&MedicalEdgeType::HasSideEffect).unwrap();
        assert_eq!(json, "\"has_side_effect\"");

        let json = serde_json::to_string(&MedicalEdgeType::OccursBefore).unwrap();
        assert_eq!(json, "\"occurs_before\"");

        let edge_type: MedicalEdgeType = serde_json::from_str("\"metabolized_by\"").unwrap();
        assert_eq!(edge_type, MedicalEdgeType::MetabolizedBy);
    }

    #[test]
    fn test_medical_node_metadata() {
        let mut metadata = MedicalNodeMetadata::new();
        assert!(metadata.is_empty());
        assert_eq!(metadata.len(), 0);

        metadata.insert("source".to_string(), "PrimeKG".to_string());
        metadata.insert("confidence".to_string(), "0.95".to_string());

        assert!(!metadata.is_empty());
        assert_eq!(metadata.len(), 2);
        assert_eq!(metadata.get("source"), Some(&"PrimeKG".to_string()));
        assert_eq!(metadata.get("confidence"), Some(&"0.95".to_string()));
        assert_eq!(metadata.get("missing"), None);
    }

    #[test]
    fn test_medical_node_metadata_serde_roundtrip() {
        let mut metadata = MedicalNodeMetadata::new();
        metadata.insert("source".to_string(), "SNOMED".to_string());
        metadata.insert("version".to_string(), "2024-01".to_string());

        let json = serde_json::to_string(&metadata).unwrap();
        let deserialized: MedicalNodeMetadata = serde_json::from_str(&json).unwrap();

        assert_eq!(deserialized.len(), 2);
        assert_eq!(deserialized.get("source"), Some(&"SNOMED".to_string()));
        assert_eq!(deserialized.get("version"), Some(&"2024-01".to_string()));
    }

    #[test]
    fn test_medical_node_type_clone_copy() {
        let original = MedicalNodeType::Disease;
        let cloned = original.clone();
        let copied = original; // Copy
        assert_eq!(original, cloned);
        assert_eq!(original, copied);
    }

    #[test]
    fn test_medical_edge_type_clone_copy() {
        let original = MedicalEdgeType::Treats;
        let cloned = original.clone();
        let copied = original; // Copy
        assert_eq!(original, cloned);
        assert_eq!(original, copied);
    }

    #[test]
    fn test_medical_node_type_hash() {
        use std::collections::HashSet;
        let mut set = HashSet::new();
        set.insert(MedicalNodeType::Disease);
        set.insert(MedicalNodeType::Drug);
        set.insert(MedicalNodeType::Disease); // duplicate
        assert_eq!(set.len(), 2);
    }

    #[test]
    fn test_medical_edge_type_hash() {
        use std::collections::HashSet;
        let mut set = HashSet::new();
        set.insert(MedicalEdgeType::Treats);
        set.insert(MedicalEdgeType::Causes);
        set.insert(MedicalEdgeType::Treats); // duplicate
        assert_eq!(set.len(), 2);
    }
}