fhir_rs/datatype/
mod.rs

1mod primitive;
2mod complex;
3mod base;
4mod macros;
5mod extension;
6mod anytype;
7
8pub use primitive::*;
9pub use complex::*;
10pub use base::*;
11pub use extension::*;
12pub use anytype::*;
13
14use std::fmt::{Debug, Display};
15use std::str::FromStr;
16
17/// 所有数据类型的基类
18pub trait Base : Debug {
19    fn type_name(&self) -> &str;
20}
21
22/// 所有数据元素的基类型,继承自Base
23pub trait Element: Base {
24    fn id(&self) -> Option<&String>;
25    fn set_id<T: Into<String>>(self, id: T) -> Self;
26    fn extensions(&self) -> Option<&Vec<Extension>>;
27    fn set_extensions(self, ext: Vec<Extension>) -> Self;
28    fn add_extension(self, ext: Extension) -> Self;
29}
30
31/// 用于简单类型和复合类型的基类
32pub trait DataType : Element {}
33
34
35pub trait Backbone {
36    fn modifier_extensions(&self) -> Option<&Vec<Extension>>;
37    fn set_modifier_extensions(self, ext: Vec<Extension>) -> Self;
38    fn add_modifier_extension(self, ext: Extension) -> Self;
39    fn modifier_extension<U: Into<Url>>(&self, url: U) -> Option<&Extension>;
40}
41/// 有一些特殊类需要从Backbone类型继承
42/// Timing, Dosage, ElementDefinition
43pub trait BackboneType : DataType + Backbone {}
44
45pub trait BackboneElement : Element + Backbone {}
46
47/// FHIR简单类型的特性
48/// FHIR简单类型是RUST简单数据类型的包装器
49///
50pub trait Primitive: DataType + Display + FromStr {
51    type T;
52    fn new<A: Into<Self::T>>(v: A) -> Self;
53    fn has_value(&self) -> bool;
54    fn value(&self) -> &Option<Self::T>;
55    fn set_value(self, v: Self::T) -> Self;
56    fn combine(&mut self, other: Self);
57}
58
59pub trait Resource {
60    fn id(&self) -> &Option<Id>;
61    fn set_id<T: Into<Id>>(self, id: T) -> Self;
62    fn meta(&self) -> &Option<Meta>;
63    fn set_meta(self, meta: Meta) -> Self;
64}
65
66pub trait DomainResource: Resource {
67    fn extension(&self) -> &Option<Vec<Extension>>;
68    fn set_extension(self, ext: Vec<Extension>) -> Self;
69    fn add_extension(self, ext: Extension) -> Self;
70    fn modifier_extension(&self) -> &Option<Vec<Extension>>;
71    fn set_modifier_extension(self, ext: Vec<Extension>) -> Self;
72    fn add_modifier_extension(self, ext: Extension) -> Self;
73}
74