fhirkit 0.1.0

FHIR R4 for Rust: typed models for every resource and datatype generated from the official specification, lossless JSON with path-precise validation, typed search queries, FHIRPath
Documentation
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `GraphDefinition` resource.

#![allow(
    unused_imports,
    clippy::large_enum_variant,
    clippy::too_many_lines,
    clippy::doc_markdown
)]

use crate::decode::{
    choice_key, required, required_list, resource_type, Choice, Decoder, FhirJson, Obj, ObjWriter,
};
use crate::json::Json;
use crate::primitive::{Decimal, Kind, Primitive};
use crate::r4::*;

/// A formal computable definition of a graph of resources - that is, a coherent set of resources that form a graph by following references. The Graph Definition resource defines a set and makes rules about the set.
///
/// FHIR path: `GraphDefinition`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct GraphDefinition {
    /// `id` (0..1): Logical id of this artifact
    pub id: Option<String>,
    /// `meta` (0..1): Metadata about the resource
    pub meta: Option<Meta>,
    /// `implicitRules` (0..1): A set of rules under which this content was created
    pub implicit_rules: Option<Primitive<String>>,
    /// `language` (0..1): Language of the resource content
    pub language: Option<Primitive<String>>,
    /// `text` (0..1): Text summary of the resource, for human interpretation
    pub text: Option<Narrative>,
    /// `contained` (0..*): Contained, inline Resources
    pub contained: Vec<Resource>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored
    pub modifier_extension: Vec<Extension>,
    /// `url` (0..1): Canonical identifier for this graph definition, represented as a URI (globally unique)
    pub url: Option<Primitive<String>>,
    /// `version` (0..1): Business version of the graph definition
    pub version: Option<Primitive<String>>,
    /// `name` (1..1): Name for this graph definition (computer friendly)
    pub name: Option<Primitive<String>>,
    /// `status` (1..1): draft | active | retired | unknown
    pub status: Option<Primitive<String>>,
    /// `experimental` (0..1): For testing purposes, not real usage
    pub experimental: Option<Primitive<bool>>,
    /// `date` (0..1): Date last changed
    pub date: Option<Primitive<String>>,
    /// `publisher` (0..1): Name of the publisher (organization or individual)
    pub publisher: Option<Primitive<String>>,
    /// `contact` (0..*): Contact details for the publisher
    pub contact: Vec<ContactDetail>,
    /// `description` (0..1): Natural language description of the graph definition
    pub description: Option<Primitive<String>>,
    /// `useContext` (0..*): The context that the content is intended to support
    pub use_context: Vec<UsageContext>,
    /// `jurisdiction` (0..*): Intended jurisdiction for graph definition (if applicable)
    pub jurisdiction: Vec<CodeableConcept>,
    /// `purpose` (0..1): Why this graph definition is defined
    pub purpose: Option<Primitive<String>>,
    /// `start` (1..1): Type of resource at which the graph starts
    pub start: Option<Primitive<String>>,
    /// `profile` (0..1): Profile on base resource
    pub profile: Option<Primitive<String>>,
    /// `link` (0..*): Links this graph makes rules about
    pub link: Vec<GraphDefinitionLink>,
}

#[cfg(feature = "foundation")]
impl FhirJson for GraphDefinition {
    const TYPE_NAME: &'static str = "GraphDefinition";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "GraphDefinition");
        let r = GraphDefinition {
            id: o.string(d, "id"),
            meta: o.one(d, "meta"),
            implicit_rules: o.prim(d, "implicitRules", Kind::Uri),
            language: o.prim(d, "language", Kind::Code),
            text: o.one(d, "text"),
            contained: o.list(d, "contained"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            url: o.prim(d, "url", Kind::Uri),
            version: o.prim(d, "version", Kind::String),
            name: o.prim(d, "name", Kind::String),
            status: o.prim(d, "status", Kind::Code),
            experimental: o.prim(d, "experimental", Kind::Boolean),
            date: o.prim(d, "date", Kind::DateTime),
            publisher: o.prim(d, "publisher", Kind::String),
            contact: o.list(d, "contact"),
            description: o.prim(d, "description", Kind::Markdown),
            use_context: o.list(d, "useContext"),
            jurisdiction: o.list(d, "jurisdiction"),
            purpose: o.prim(d, "purpose", Kind::Markdown),
            start: o.prim(d, "start", Kind::Code),
            profile: o.prim(d, "profile", Kind::Canonical),
            link: o.list(d, "link"),
        };
        required(d, "name", &r.name);
        required(d, "status", &r.status);
        required(d, "start", &r.start);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("GraphDefinition".into()));
        w.string("id", &self.id);
        w.one("meta", &self.meta);
        w.prim("implicitRules", &self.implicit_rules);
        w.prim("language", &self.language);
        w.one("text", &self.text);
        w.list("contained", &self.contained);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("url", &self.url);
        w.prim("version", &self.version);
        w.prim("name", &self.name);
        w.prim("status", &self.status);
        w.prim("experimental", &self.experimental);
        w.prim("date", &self.date);
        w.prim("publisher", &self.publisher);
        w.list("contact", &self.contact);
        w.prim("description", &self.description);
        w.list("useContext", &self.use_context);
        w.list("jurisdiction", &self.jurisdiction);
        w.prim("purpose", &self.purpose);
        w.prim("start", &self.start);
        w.prim("profile", &self.profile);
        w.list("link", &self.link);
        w.finish()
    }
}

/// Links this graph makes rules about
///
/// FHIR path: `GraphDefinition.link`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct GraphDefinitionLink {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `path` (0..1): Path in the resource that contains the link
    pub path: Option<Primitive<String>>,
    /// `sliceName` (0..1): Which slice (if profiled)
    pub slice_name: Option<Primitive<String>>,
    /// `min` (0..1): Minimum occurrences for this link
    pub min: Option<Primitive<i32>>,
    /// `max` (0..1): Maximum occurrences for this link
    pub max: Option<Primitive<String>>,
    /// `description` (0..1): Why this link is specified
    pub description: Option<Primitive<String>>,
    /// `target` (0..*): Potential target for the link
    pub target: Vec<GraphDefinitionLinkTarget>,
}

#[cfg(feature = "foundation")]
impl FhirJson for GraphDefinitionLink {
    const TYPE_NAME: &'static str = "GraphDefinitionLink";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = GraphDefinitionLink {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            path: o.prim(d, "path", Kind::String),
            slice_name: o.prim(d, "sliceName", Kind::String),
            min: o.prim(d, "min", Kind::Integer),
            max: o.prim(d, "max", Kind::String),
            description: o.prim(d, "description", Kind::String),
            target: o.list(d, "target"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("path", &self.path);
        w.prim("sliceName", &self.slice_name);
        w.prim("min", &self.min);
        w.prim("max", &self.max);
        w.prim("description", &self.description);
        w.list("target", &self.target);
        w.finish()
    }
}

/// Potential target for the link
///
/// FHIR path: `GraphDefinition.link.target`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct GraphDefinitionLinkTarget {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (1..1): Type of resource this link refers to
    pub type_: Option<Primitive<String>>,
    /// `params` (0..1): Criteria for reverse lookup
    pub params: Option<Primitive<String>>,
    /// `profile` (0..1): Profile for the target resource
    pub profile: Option<Primitive<String>>,
    /// `compartment` (0..*): Compartment Consistency Rules
    pub compartment: Vec<GraphDefinitionLinkTargetCompartment>,
    /// `link` (0..*): Additional links from target resource
    pub link: Vec<GraphDefinitionLink>,
}

#[cfg(feature = "foundation")]
impl FhirJson for GraphDefinitionLinkTarget {
    const TYPE_NAME: &'static str = "GraphDefinitionLinkTarget";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = GraphDefinitionLinkTarget {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.prim(d, "type", Kind::Code),
            params: o.prim(d, "params", Kind::String),
            profile: o.prim(d, "profile", Kind::Canonical),
            compartment: o.list(d, "compartment"),
            link: o.list(d, "link"),
        };
        required(d, "type", &r.type_);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("type", &self.type_);
        w.prim("params", &self.params);
        w.prim("profile", &self.profile);
        w.list("compartment", &self.compartment);
        w.list("link", &self.link);
        w.finish()
    }
}

/// Compartment Consistency Rules
///
/// FHIR path: `GraphDefinition.link.target.compartment`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct GraphDefinitionLinkTargetCompartment {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `use` (1..1): condition | requirement
    pub use_: Option<Primitive<String>>,
    /// `code` (1..1): Patient | Encounter | RelatedPerson | Practitioner | Device
    pub code: Option<Primitive<String>>,
    /// `rule` (1..1): identical | matching | different | custom
    pub rule: Option<Primitive<String>>,
    /// `expression` (0..1): Custom rule, as a FHIRPath expression
    pub expression: Option<Primitive<String>>,
    /// `description` (0..1): Documentation for FHIRPath expression
    pub description: Option<Primitive<String>>,
}

#[cfg(feature = "foundation")]
impl FhirJson for GraphDefinitionLinkTargetCompartment {
    const TYPE_NAME: &'static str = "GraphDefinitionLinkTargetCompartment";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = GraphDefinitionLinkTargetCompartment {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            use_: o.prim(d, "use", Kind::Code),
            code: o.prim(d, "code", Kind::Code),
            rule: o.prim(d, "rule", Kind::Code),
            expression: o.prim(d, "expression", Kind::String),
            description: o.prim(d, "description", Kind::String),
        };
        required(d, "use", &r.use_);
        required(d, "code", &r.code);
        required(d, "rule", &r.rule);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("use", &self.use_);
        w.prim("code", &self.code);
        w.prim("rule", &self.rule);
        w.prim("expression", &self.expression);
        w.prim("description", &self.description);
        w.finish()
    }
}