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 `Binary` 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 resource that represents the data of a single raw artifact as digital content accessible in its native format. A Binary resource can contain any content, whether text, image, pdf, zip archive, etc.
///
/// FHIR path: `Binary`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Binary {
    /// `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>>,
    /// `contentType` (1..1): MimeType of the binary content
    pub content_type: Option<Primitive<String>>,
    /// `securityContext` (0..1): Identifies another resource to use as proxy when enforcing access control
    pub security_context: Option<Reference>,
    /// `data` (0..1): The actual content
    pub data: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Binary");
        let r = Binary {
            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),
            content_type: o.prim(d, "contentType", Kind::Code),
            security_context: o.one(d, "securityContext"),
            data: o.prim(d, "data", Kind::Base64Binary),
        };
        required(d, "contentType", &r.content_type);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Binary".into()));
        w.string("id", &self.id);
        w.one("meta", &self.meta);
        w.prim("implicitRules", &self.implicit_rules);
        w.prim("language", &self.language);
        w.prim("contentType", &self.content_type);
        w.one("securityContext", &self.security_context);
        w.prim("data", &self.data);
        w.finish()
    }
}