-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement creation of References
- Loading branch information
Flix
committed
Sep 6, 2023
1 parent
03745cc
commit aaa5203
Showing
6 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
//! Revision 4B types of FHIR. | ||
pub mod codes; | ||
pub mod reference; | ||
pub mod resources; | ||
pub mod types; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! Extended [`Reference`] functionality. | ||
use super::{ | ||
resources::{BaseResource, NamedResource}, | ||
types::{Reference, ReferenceInner}, | ||
}; | ||
|
||
/// Create relative [`Reference`] to the given resource. | ||
pub fn create_to<R>(resource: R) -> Option<Reference> | ||
where | ||
R: NamedResource + BaseResource, | ||
{ | ||
Some( | ||
ReferenceInner { | ||
id: None, | ||
extension: Vec::new(), | ||
reference: Some(format!("{}/{}", R::TYPE, resource.id().as_ref()?)), | ||
reference_ext: None, | ||
r#type: Some(R::TYPE.to_string()), | ||
type_ext: None, | ||
identifier: None, | ||
identifier_ext: None, | ||
display: None, | ||
display_ext: None, | ||
} | ||
.into(), | ||
) | ||
} | ||
|
||
/// Create local [`Reference`] to the given resource. Make sure the resource is | ||
/// going to be in the `contained` field of the referencing resource. | ||
pub fn create_local_to<R>(resource: R) -> Option<Reference> | ||
where | ||
R: NamedResource + BaseResource, | ||
{ | ||
Some( | ||
ReferenceInner { | ||
id: None, | ||
extension: Vec::new(), | ||
reference: Some(format!("#{}", resource.id().as_ref()?)), | ||
reference_ext: None, | ||
r#type: Some(R::TYPE.to_string()), | ||
type_ext: None, | ||
identifier: None, | ||
identifier_ext: None, | ||
display: None, | ||
display_ext: None, | ||
} | ||
.into(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
//! Revision 5 types of FHIR. | ||
pub mod codes; | ||
pub mod reference; | ||
pub mod resources; | ||
pub mod types; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! Extended [`Reference`] functionality. | ||
use super::{ | ||
resources::{BaseResource, NamedResource}, | ||
types::{Reference, ReferenceInner}, | ||
}; | ||
|
||
/// Create relative [`Reference`] to the given resource. | ||
pub fn create_to<R>(resource: R) -> Option<Reference> | ||
where | ||
R: NamedResource + BaseResource, | ||
{ | ||
Some( | ||
ReferenceInner { | ||
id: None, | ||
extension: Vec::new(), | ||
reference: Some(format!("{}/{}", R::TYPE, resource.id().as_ref()?)), | ||
reference_ext: None, | ||
r#type: Some(R::TYPE.to_string()), | ||
type_ext: None, | ||
identifier: None, | ||
identifier_ext: None, | ||
display: None, | ||
display_ext: None, | ||
} | ||
.into(), | ||
) | ||
} | ||
|
||
/// Create local [`Reference`] to the given resource. Make sure the resource is | ||
/// going to be in the `contained` field of the referencing resource. | ||
pub fn create_local_to<R>(resource: R) -> Option<Reference> | ||
where | ||
R: NamedResource + BaseResource, | ||
{ | ||
Some( | ||
ReferenceInner { | ||
id: None, | ||
extension: Vec::new(), | ||
reference: Some(format!("#{}", resource.id().as_ref()?)), | ||
reference_ext: None, | ||
r#type: Some(R::TYPE.to_string()), | ||
type_ext: None, | ||
identifier: None, | ||
identifier_ext: None, | ||
display: None, | ||
display_ext: None, | ||
} | ||
.into(), | ||
) | ||
} |