Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/parsing/parseable_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl ParsableNode<Disease> for Disease {
if let Value::Object(map) = &node.inner
&& node
.pointer()
.segments()
.iter_segments()
.into_iter()
.any(|seg| seg.to_lowercase() == "diseases")
&& map.contains_key("term")
Expand All @@ -102,7 +102,7 @@ impl ParsableNode<Diagnosis> for Diagnosis {
if let Value::Object(map) = &node.inner
&& node
.pointer()
.segments()
.iter_segments()
.into_iter()
.any(|seg| seg.to_lowercase() == "interpretations")
&& map.contains_key("disease")
Expand Down
88 changes: 45 additions & 43 deletions src/patches/patch_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ impl PatchEngine {
patches.sort_by(|p1, p2| match (p1, p2) {
(PatchInstruction::Add { .. }, PatchInstruction::Remove { .. }) => Ordering::Less,
(PatchInstruction::Remove { .. }, PatchInstruction::Add { .. }) => Ordering::Greater,
(PatchInstruction::Add { at: at1, .. }, PatchInstruction::Add { at: at2, .. }) => {
at1.segments().count().cmp(&at2.segments().count())
}
(PatchInstruction::Remove { at: at1 }, PatchInstruction::Remove { at: at2 }) => {
at1.segments().count().cmp(&at2.segments().count())
}
(PatchInstruction::Add { at: at1, .. }, PatchInstruction::Add { at: at2, .. }) => at1
.iter_segments()
.count()
.cmp(&at2.iter_segments().count()),
(PatchInstruction::Remove { at: at1 }, PatchInstruction::Remove { at: at2 }) => at1
.iter_segments()
.count()
.cmp(&at2.iter_segments().count()),
_ => Ordering::Equal,
});
}
Expand Down Expand Up @@ -168,7 +170,7 @@ mod tests {
let phenostr = sample_phenopacket();
let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Add {
at: Pointer::new("/metaData"),
at: Pointer::from("/metaData"),
value: json!({"created": "2024-01-01"}),
},
vec![],
Expand All @@ -187,7 +189,7 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Add {
at: Pointer::new("/subject/timeAtLastEncounter"),
at: Pointer::from("/subject/timeAtLastEncounter"),
value: json!({"age": "P30Y"}),
},
vec![],
Expand All @@ -206,7 +208,7 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Remove {
at: Pointer::new("/subject/dateOfBirth"),
at: Pointer::from("/subject/dateOfBirth"),
},
vec![],
));
Expand All @@ -223,7 +225,7 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Remove {
at: Pointer::new("/diseases/0/onset"),
at: Pointer::from("/diseases/0/onset"),
},
vec![],
));
Expand All @@ -241,8 +243,8 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Move {
from: Pointer::new("/subject/dateOfBirth"),
to: Pointer::new("/subject/birthDate"),
from: Pointer::from("/subject/dateOfBirth"),
to: Pointer::from("/subject/birthDate"),
},
vec![],
));
Expand All @@ -260,8 +262,8 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Move {
from: Pointer::new("/diseases/0/onset"),
to: Pointer::new("/ageOfOnset"),
from: Pointer::from("/diseases/0/onset"),
to: Pointer::from("/ageOfOnset"),
},
vec![],
));
Expand All @@ -279,8 +281,8 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Duplicate {
from: Pointer::new("/subject/id"),
to: Pointer::new("/subject/patientId"),
from: Pointer::from("/subject/id"),
to: Pointer::from("/subject/patientId"),
},
vec![],
));
Expand All @@ -298,8 +300,8 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Duplicate {
from: Pointer::new("/diseases/0/term"),
to: Pointer::new("/diagnosisTerm"),
from: Pointer::from("/diseases/0/term"),
to: Pointer::from("/diagnosisTerm"),
},
vec![],
));
Expand All @@ -318,11 +320,11 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Add {
at: Pointer::new("/subject/karyotypicSex"),
at: Pointer::from("/subject/karyotypicSex"),
value: Value::String("XY".to_string()),
},
vec![PatchInstruction::Add {
at: Pointer::new("/subject/taxonomy"),
at: Pointer::from("/subject/taxonomy"),
value: json!({"id": "NCBITaxon:9606", "label": "Homo sapiens"}),
}],
));
Expand All @@ -340,16 +342,16 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Add {
at: Pointer::new("/metaData"),
at: Pointer::from("/metaData"),
value: json!({"created": "2024-01-01"}),
},
vec![
PatchInstruction::Remove {
at: Pointer::new("/subject/dateOfBirth"),
at: Pointer::from("/subject/dateOfBirth"),
},
PatchInstruction::Move {
from: Pointer::new("/subject/sex"),
to: Pointer::new("/subject/gender"),
from: Pointer::from("/subject/sex"),
to: Pointer::from("/subject/gender"),
},
],
));
Expand All @@ -369,10 +371,10 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Remove {
at: Pointer::new("/subject/sex"),
at: Pointer::from("/subject/sex"),
},
vec![PatchInstruction::Add {
at: Pointer::new("/subject/gender"),
at: Pointer::from("/subject/gender"),
value: Value::String("MALE".to_string()),
}],
));
Expand All @@ -390,11 +392,11 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Move {
from: Pointer::new("/diseases/0"),
to: Pointer::new("/primaryDiagnosis"),
from: Pointer::from("/diseases/0"),
to: Pointer::from("/primaryDiagnosis"),
},
vec![PatchInstruction::Add {
at: Pointer::new("/primaryDiagnosis/confirmed"),
at: Pointer::from("/primaryDiagnosis/confirmed"),
value: Value::Bool(true),
}],
));
Expand Down Expand Up @@ -423,7 +425,7 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Add {
at: Pointer::new("/schemaVersion"),
at: Pointer::from("/schemaVersion"),
value: Value::Number(Number::from_f64(2.0f64).unwrap()),
},
vec![],
Expand All @@ -441,11 +443,11 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Duplicate {
from: Pointer::new("/subject"),
to: Pointer::new("/backup"),
from: Pointer::from("/subject"),
to: Pointer::from("/backup"),
},
vec![PatchInstruction::Remove {
at: Pointer::new("/subject/dateOfBirth"),
at: Pointer::from("/subject/dateOfBirth"),
}],
));

Expand All @@ -464,7 +466,7 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Add {
at: Pointer::new("/phenotypicFeatures/0/severity"),
at: Pointer::from("/phenotypicFeatures/0/severity"),
value: json!({"label": "severe"}),
},
vec![],
Expand All @@ -485,7 +487,7 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Add {
at: Pointer::new("/diseases/0/onset/iso8601"),
at: Pointer::from("/diseases/0/onset/iso8601"),
value: json!({"iso8601duration": "P10Y"}),
},
vec![],
Expand All @@ -506,7 +508,7 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Add {
at: Pointer::new("/notes"),
at: Pointer::from("/notes"),
value: Value::String(
"Patient has \"complex\" symptoms; requires care.".to_string(),
),
Expand All @@ -526,12 +528,12 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Move {
from: Pointer::new("/subject/sex"),
to: Pointer::new("/subject/biologicalSex"),
from: Pointer::from("/subject/sex"),
to: Pointer::from("/subject/biologicalSex"),
},
vec![PatchInstruction::Move {
from: Pointer::new("/subject/id"),
to: Pointer::new("/patientIdentifier"),
from: Pointer::from("/subject/id"),
to: Pointer::from("/patientIdentifier"),
}],
));

Expand All @@ -550,10 +552,10 @@ mod tests {

let patch = Patch::new(NonEmptyVec::with_rest(
PatchInstruction::Remove {
at: Pointer::new("/subject/sex"),
at: Pointer::from("/subject/sex"),
},
vec![PatchInstruction::Add {
at: Pointer::new("/subject/sex"),
at: Pointer::from("/subject/sex"),
value: Value::String("FEMALE".to_string()),
}],
));
Expand All @@ -569,7 +571,7 @@ mod tests {
let minimal = json!({"id": "test"});

let patch = Patch::new(NonEmptyVec::with_single_entry(PatchInstruction::Add {
at: Pointer::new("/subject"),
at: Pointer::from("/subject"),
value: json!({"id": "patient.1"}),
}));

Expand Down
6 changes: 3 additions & 3 deletions src/rules/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod test_curies_have_resources {
label: "Seizure".into(),
},
Default::default(),
Pointer::new("/phenotypicFeatures/0/type"),
Pointer::from("/phenotypicFeatures/0/type"),
)];
let resources = [];
let data = (List(&ocs), List(&resources));
Expand Down Expand Up @@ -109,12 +109,12 @@ impl ReportFromContext for CuriesHaveResourcesReport {

impl CompileReport for CuriesHaveResourcesReport {
fn compile_report(&self, full_node: &dyn Node, lint_violation: &LintViolation) -> ReportSpecs {
let resources_ptr = Pointer::new("/metaData/resources");
let resources_ptr = Pointer::from("/metaData/resources");
let span = if let Some(resources_range) = full_node.span_at(&resources_ptr).cloned() {
resources_range
} else {
// `metaData` lacks the `resources` field itself.
let metadata_ptr = Pointer::new("/metaData");
let metadata_ptr = Pointer::from("/metaData");
full_node.span_at(&metadata_ptr)
.cloned()
.expect("We assume `metaData` is always in the `Node` because we validate the basic phenopacket invariants before running this rule")
Expand Down
2 changes: 1 addition & 1 deletion src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pub mod node;
pub mod node_repository;
pub mod pointer;
pub mod traits;
pub(crate) mod utils;
mod utils;
Loading
Loading