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 `Library` 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::*;

/// The Library resource is a general-purpose container for knowledge asset definitions. It can be used to describe and expose existing knowledge assets such as logic libraries and information model descriptions, as well as to describe a collection of knowledge assets.
///
/// FHIR path: `Library`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Library {
    /// `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 library, represented as a URI (globally unique)
    pub url: Option<Primitive<String>>,
    /// `identifier` (0..*): Additional identifier for the library
    pub identifier: Vec<Identifier>,
    /// `version` (0..1): Business version of the library
    pub version: Option<Primitive<String>>,
    /// `name` (0..1): Name for this library (computer friendly)
    pub name: Option<Primitive<String>>,
    /// `title` (0..1): Name for this library (human friendly)
    pub title: Option<Primitive<String>>,
    /// `subtitle` (0..1): Subordinate title of the library
    pub subtitle: 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>>,
    /// `type` (1..1): logic-library | model-definition | asset-collection | module-definition
    pub type_: Option<CodeableConcept>,
    /// `subject[x]` (0..1): Type of individual the library content is focused on
    pub subject: Option<LibrarySubject>,
    /// `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 library
    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 library (if applicable)
    pub jurisdiction: Vec<CodeableConcept>,
    /// `purpose` (0..1): Why this library is defined
    pub purpose: Option<Primitive<String>>,
    /// `usage` (0..1): Describes the clinical usage of the library
    pub usage: Option<Primitive<String>>,
    /// `copyright` (0..1): Use and/or publishing restrictions
    pub copyright: Option<Primitive<String>>,
    /// `approvalDate` (0..1): When the library was approved by publisher
    pub approval_date: Option<Primitive<String>>,
    /// `lastReviewDate` (0..1): When the library was last reviewed
    pub last_review_date: Option<Primitive<String>>,
    /// `effectivePeriod` (0..1): When the library is expected to be used
    pub effective_period: Option<Period>,
    /// `topic` (0..*): E.g. Education, Treatment, Assessment, etc.
    pub topic: Vec<CodeableConcept>,
    /// `author` (0..*): Who authored the content
    pub author: Vec<ContactDetail>,
    /// `editor` (0..*): Who edited the content
    pub editor: Vec<ContactDetail>,
    /// `reviewer` (0..*): Who reviewed the content
    pub reviewer: Vec<ContactDetail>,
    /// `endorser` (0..*): Who endorsed the content
    pub endorser: Vec<ContactDetail>,
    /// `relatedArtifact` (0..*): Additional documentation, citations, etc.
    pub related_artifact: Vec<RelatedArtifact>,
    /// `parameter` (0..*): Parameters defined by the library
    pub parameter: Vec<ParameterDefinition>,
    /// `dataRequirement` (0..*): What data is referenced by this library
    pub data_requirement: Vec<DataRequirement>,
    /// `content` (0..*): Contents of the library, either embedded or referenced
    pub content: Vec<Attachment>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Library");
        let r = Library {
            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),
            identifier: o.list(d, "identifier"),
            version: o.prim(d, "version", Kind::String),
            name: o.prim(d, "name", Kind::String),
            title: o.prim(d, "title", Kind::String),
            subtitle: o.prim(d, "subtitle", Kind::String),
            status: o.prim(d, "status", Kind::Code),
            experimental: o.prim(d, "experimental", Kind::Boolean),
            type_: o.one(d, "type"),
            subject: o.choice(d, "subject"),
            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),
            usage: o.prim(d, "usage", Kind::String),
            copyright: o.prim(d, "copyright", Kind::Markdown),
            approval_date: o.prim(d, "approvalDate", Kind::Date),
            last_review_date: o.prim(d, "lastReviewDate", Kind::Date),
            effective_period: o.one(d, "effectivePeriod"),
            topic: o.list(d, "topic"),
            author: o.list(d, "author"),
            editor: o.list(d, "editor"),
            reviewer: o.list(d, "reviewer"),
            endorser: o.list(d, "endorser"),
            related_artifact: o.list(d, "relatedArtifact"),
            parameter: o.list(d, "parameter"),
            data_requirement: o.list(d, "dataRequirement"),
            content: o.list(d, "content"),
        };
        required(d, "status", &r.status);
        required(d, "type", &r.type_);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Library".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.list("identifier", &self.identifier);
        w.prim("version", &self.version);
        w.prim("name", &self.name);
        w.prim("title", &self.title);
        w.prim("subtitle", &self.subtitle);
        w.prim("status", &self.status);
        w.prim("experimental", &self.experimental);
        w.one("type", &self.type_);
        w.choice("subject", &self.subject);
        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("usage", &self.usage);
        w.prim("copyright", &self.copyright);
        w.prim("approvalDate", &self.approval_date);
        w.prim("lastReviewDate", &self.last_review_date);
        w.one("effectivePeriod", &self.effective_period);
        w.list("topic", &self.topic);
        w.list("author", &self.author);
        w.list("editor", &self.editor);
        w.list("reviewer", &self.reviewer);
        w.list("endorser", &self.endorser);
        w.list("relatedArtifact", &self.related_artifact);
        w.list("parameter", &self.parameter);
        w.list("dataRequirement", &self.data_requirement);
        w.list("content", &self.content);
        w.finish()
    }
}

/// The types `Library.subject[x]` allows.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq)]
pub enum LibrarySubject {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

#[cfg(feature = "base")]
impl Choice for LibrarySubject {
    const TYPES: &'static [&'static str] = &["CodeableConcept", "Reference"];

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "CodeableConcept" => o.one(d, key).map(Self::CodeableConcept),
            "Reference" => o.one(d, key).map(Self::Reference),
            _ => None,
        }
    }

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::CodeableConcept(v) => w.value(&choice_key(base, "CodeableConcept"), v),
            Self::Reference(v) => w.value(&choice_key(base, "Reference"), v),
        }
    }
}