[SUGGESTION] Wrappers/helpers for data creation/editing of FHIR resources
Closed this issue ยท 4 comments
FrozenInc commented
Right now it can be pretty difficult to create FHIR resources directly with Rust code.
Rust example:
let mut patient = Patient::builder().build();
let family_name = HumanName::builder().family(String::from("Family")).build();
let given_name = HumanName::builder().given(Vec::from([Some(String::from("Given"))])).build();
patient.name = vec![Some(family_name), Some(given_name)];
While for C# FHIR SDK it's like:
var patient = new Patient();
patient.Name = new List<HumanName>
{
new HumanName
{
Family = "Family",
Given = new List<string>
{
"Given"
}
}
};
My suggestion would be to either have a helper/wrapper for all fields, or if possible to do it like C# where you basically write it as JSON (I don't know if it's possible).
Suggestion 1
Have helpers for all fields
let mut patient = Patient::builder().build();
patient.set_family_name(String::from("Family");
patient.set_given_name(Vec::from([Some(String::from("Given"))]));
Suggestion 2
If possible have it similar to C#.
NOTE! Not valid code, just a suggestion as I really like this kind of syntax.
let mut patient = Patient::builder().build();
patient.name = {
family = String::from("Family"),
given = vec![Some(String::from("Given))]
};
FlixCoder commented
You do know that you can do
Patient::builder()
.name(vec![HumanName::builder().build()])
.build()
right?
FlixCoder commented
You could probably also do
Patient {
name: vec![...],
..Patient::builder().build()
}
I cannot test, as I am on the move
FlixCoder commented
Btw, you probably want to combine family and given name into one human name?
HumanName::builder()
.family("Meier".to_owned())
.given(vec![Some("Peter".to_owned())])
.build()
FrozenInc commented
Great! You can disregard my suggestion in that case :)