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 `SearchParameter` 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 search parameter that defines a named search item that can be used to search/filter on a resource.
///
/// FHIR path: `SearchParameter`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SearchParameter {
    /// `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` (1..1): Canonical identifier for this search parameter, represented as a URI (globally unique)
    pub url: Option<Primitive<String>>,
    /// `version` (0..1): Business version of the search parameter
    pub version: Option<Primitive<String>>,
    /// `name` (1..1): Name for this search parameter (computer friendly)
    pub name: Option<Primitive<String>>,
    /// `derivedFrom` (0..1): Original definition for the search parameter
    pub derived_from: 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` (1..1): Natural language description of the search parameter
    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 search parameter (if applicable)
    pub jurisdiction: Vec<CodeableConcept>,
    /// `purpose` (0..1): Why this search parameter is defined
    pub purpose: Option<Primitive<String>>,
    /// `code` (1..1): Code used in URL
    pub code: Option<Primitive<String>>,
    /// `base` (1..*): The resource type(s) this search parameter applies to
    pub base: Vec<Primitive<String>>,
    /// `type` (1..1): number | date | string | token | reference | composite | quantity | uri | special
    pub type_: Option<Primitive<String>>,
    /// `expression` (0..1): FHIRPath expression that extracts the values
    pub expression: Option<Primitive<String>>,
    /// `xpath` (0..1): XPath that extracts the values
    pub xpath: Option<Primitive<String>>,
    /// `xpathUsage` (0..1): normal | phonetic | nearby | distance | other
    pub xpath_usage: Option<Primitive<String>>,
    /// `target` (0..*): Types of resource (if a resource reference)
    pub target: Vec<Primitive<String>>,
    /// `multipleOr` (0..1): Allow multiple values per parameter (or)
    pub multiple_or: Option<Primitive<bool>>,
    /// `multipleAnd` (0..1): Allow multiple parameters (and)
    pub multiple_and: Option<Primitive<bool>>,
    /// `comparator` (0..*): eq | ne | gt | lt | ge | le | sa | eb | ap
    pub comparator: Vec<Primitive<String>>,
    /// `modifier` (0..*): missing | exact | contains | not | text | in | not-in | below | above | type | identifier | ofType
    pub modifier: Vec<Primitive<String>>,
    /// `chain` (0..*): Chained names supported
    pub chain: Vec<Primitive<String>>,
    /// `component` (0..*): For Composite resources to define the parts
    pub component: Vec<SearchParameterComponent>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "SearchParameter");
        let r = SearchParameter {
            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),
            derived_from: o.prim(d, "derivedFrom", Kind::Canonical),
            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),
            code: o.prim(d, "code", Kind::Code),
            base: o.prim_list(d, "base", Kind::Code),
            type_: o.prim(d, "type", Kind::Code),
            expression: o.prim(d, "expression", Kind::String),
            xpath: o.prim(d, "xpath", Kind::String),
            xpath_usage: o.prim(d, "xpathUsage", Kind::Code),
            target: o.prim_list(d, "target", Kind::Code),
            multiple_or: o.prim(d, "multipleOr", Kind::Boolean),
            multiple_and: o.prim(d, "multipleAnd", Kind::Boolean),
            comparator: o.prim_list(d, "comparator", Kind::Code),
            modifier: o.prim_list(d, "modifier", Kind::Code),
            chain: o.prim_list(d, "chain", Kind::String),
            component: o.list(d, "component"),
        };
        required(d, "url", &r.url);
        required(d, "name", &r.name);
        required(d, "status", &r.status);
        required(d, "description", &r.description);
        required(d, "code", &r.code);
        required_list(d, "base", &r.base, 1);
        required(d, "type", &r.type_);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("SearchParameter".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("derivedFrom", &self.derived_from);
        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("code", &self.code);
        w.prim_list("base", &self.base);
        w.prim("type", &self.type_);
        w.prim("expression", &self.expression);
        w.prim("xpath", &self.xpath);
        w.prim("xpathUsage", &self.xpath_usage);
        w.prim_list("target", &self.target);
        w.prim("multipleOr", &self.multiple_or);
        w.prim("multipleAnd", &self.multiple_and);
        w.prim_list("comparator", &self.comparator);
        w.prim_list("modifier", &self.modifier);
        w.prim_list("chain", &self.chain);
        w.list("component", &self.component);
        w.finish()
    }
}

/// For Composite resources to define the parts
///
/// FHIR path: `SearchParameter.component`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SearchParameterComponent {
    /// `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>,
    /// `definition` (1..1): Defines how the part works
    pub definition: Option<Primitive<String>>,
    /// `expression` (1..1): Subexpression relative to main expression
    pub expression: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = SearchParameterComponent {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            definition: o.prim(d, "definition", Kind::Canonical),
            expression: o.prim(d, "expression", Kind::String),
        };
        required(d, "definition", &r.definition);
        required(d, "expression", &r.expression);
        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("definition", &self.definition);
        w.prim("expression", &self.expression);
        w.finish()
    }
}