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 `ResearchDefinition` 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 ResearchDefinition resource describes the conditional state (population and any exposures being compared within the population) and outcome (if specified) that the knowledge (evidence, assertion, recommendation) is about.
///
/// FHIR path: `ResearchDefinition`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ResearchDefinition {
    /// `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 research definition, represented as a URI (globally unique)
    pub url: Option<Primitive<String>>,
    /// `identifier` (0..*): Additional identifier for the research definition
    pub identifier: Vec<Identifier>,
    /// `version` (0..1): Business version of the research definition
    pub version: Option<Primitive<String>>,
    /// `name` (0..1): Name for this research definition (computer friendly)
    pub name: Option<Primitive<String>>,
    /// `title` (0..1): Name for this research definition (human friendly)
    pub title: Option<Primitive<String>>,
    /// `shortTitle` (0..1): Title for use in informal contexts
    pub short_title: Option<Primitive<String>>,
    /// `subtitle` (0..1): Subordinate title of the ResearchDefinition
    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>>,
    /// `subject[x]` (0..1): E.g. Patient, Practitioner, RelatedPerson, Organization, Location, Device
    pub subject: Option<ResearchDefinitionSubject>,
    /// `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 research definition
    pub description: Option<Primitive<String>>,
    /// `comment` (0..*): Used for footnotes or explanatory notes
    pub comment: Vec<Primitive<String>>,
    /// `useContext` (0..*): The context that the content is intended to support
    pub use_context: Vec<UsageContext>,
    /// `jurisdiction` (0..*): Intended jurisdiction for research definition (if applicable)
    pub jurisdiction: Vec<CodeableConcept>,
    /// `purpose` (0..1): Why this research definition is defined
    pub purpose: Option<Primitive<String>>,
    /// `usage` (0..1): Describes the clinical usage of the ResearchDefinition
    pub usage: Option<Primitive<String>>,
    /// `copyright` (0..1): Use and/or publishing restrictions
    pub copyright: Option<Primitive<String>>,
    /// `approvalDate` (0..1): When the research definition was approved by publisher
    pub approval_date: Option<Primitive<String>>,
    /// `lastReviewDate` (0..1): When the research definition was last reviewed
    pub last_review_date: Option<Primitive<String>>,
    /// `effectivePeriod` (0..1): When the research definition is expected to be used
    pub effective_period: Option<Period>,
    /// `topic` (0..*): The category of the ResearchDefinition, such as 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>,
    /// `library` (0..*): Logic used by the ResearchDefinition
    pub library: Vec<Primitive<String>>,
    /// `population` (1..1): What population?
    pub population: Option<Reference>,
    /// `exposure` (0..1): What exposure?
    pub exposure: Option<Reference>,
    /// `exposureAlternative` (0..1): What alternative exposure state?
    pub exposure_alternative: Option<Reference>,
    /// `outcome` (0..1): What outcome?
    pub outcome: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "ResearchDefinition");
        let r = ResearchDefinition {
            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),
            short_title: o.prim(d, "shortTitle", Kind::String),
            subtitle: o.prim(d, "subtitle", Kind::String),
            status: o.prim(d, "status", Kind::Code),
            experimental: o.prim(d, "experimental", Kind::Boolean),
            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),
            comment: o.prim_list(d, "comment", Kind::String),
            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"),
            library: o.prim_list(d, "library", Kind::Canonical),
            population: o.one(d, "population"),
            exposure: o.one(d, "exposure"),
            exposure_alternative: o.one(d, "exposureAlternative"),
            outcome: o.one(d, "outcome"),
        };
        required(d, "status", &r.status);
        required(d, "population", &r.population);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("ResearchDefinition".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("shortTitle", &self.short_title);
        w.prim("subtitle", &self.subtitle);
        w.prim("status", &self.status);
        w.prim("experimental", &self.experimental);
        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.prim_list("comment", &self.comment);
        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.prim_list("library", &self.library);
        w.one("population", &self.population);
        w.one("exposure", &self.exposure);
        w.one("exposureAlternative", &self.exposure_alternative);
        w.one("outcome", &self.outcome);
        w.finish()
    }
}

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

#[cfg(feature = "specialized")]
impl Choice for ResearchDefinitionSubject {
    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),
        }
    }
}