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 `ResearchStudy` 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 process where a researcher or organization plans and then executes a series of steps intended to increase the field of healthcare-related knowledge. This includes studies of safety, efficacy, comparative effectiveness and other information about medications, devices, therapies and other interventional and investigative techniques. A ResearchStudy involves the gathering of information about human or animal subjects.
///
/// FHIR path: `ResearchStudy`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ResearchStudy {
    /// `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>,
    /// `identifier` (0..*): Business Identifier for study
    pub identifier: Vec<Identifier>,
    /// `title` (0..1): Name for this study
    pub title: Option<Primitive<String>>,
    /// `protocol` (0..*): Steps followed in executing study
    pub protocol: Vec<Reference>,
    /// `partOf` (0..*): Part of larger study
    pub part_of: Vec<Reference>,
    /// `status` (1..1): active | administratively-completed | approved | closed-to-accrual | closed-to-accrual-and-intervention | completed | disapproved | in-review | temporarily-closed-to-accrual | temporarily-closed-to-accrual-and-intervention | withdrawn
    pub status: Option<Primitive<String>>,
    /// `primaryPurposeType` (0..1): treatment | prevention | diagnostic | supportive-care | screening | health-services-research | basic-science | device-feasibility
    pub primary_purpose_type: Option<CodeableConcept>,
    /// `phase` (0..1): n-a | early-phase-1 | phase-1 | phase-1-phase-2 | phase-2 | phase-2-phase-3 | phase-3 | phase-4
    pub phase: Option<CodeableConcept>,
    /// `category` (0..*): Classifications for the study
    pub category: Vec<CodeableConcept>,
    /// `focus` (0..*): Drugs, devices, etc. under study
    pub focus: Vec<CodeableConcept>,
    /// `condition` (0..*): Condition being studied
    pub condition: Vec<CodeableConcept>,
    /// `contact` (0..*): Contact details for the study
    pub contact: Vec<ContactDetail>,
    /// `relatedArtifact` (0..*): References and dependencies
    pub related_artifact: Vec<RelatedArtifact>,
    /// `keyword` (0..*): Used to search for the study
    pub keyword: Vec<CodeableConcept>,
    /// `location` (0..*): Geographic region(s) for study
    pub location: Vec<CodeableConcept>,
    /// `description` (0..1): What this is study doing
    pub description: Option<Primitive<String>>,
    /// `enrollment` (0..*): Inclusion & exclusion criteria
    pub enrollment: Vec<Reference>,
    /// `period` (0..1): When the study began and ended
    pub period: Option<Period>,
    /// `sponsor` (0..1): Organization that initiates and is legally responsible for the study
    pub sponsor: Option<Reference>,
    /// `principalInvestigator` (0..1): Researcher who oversees multiple aspects of the study
    pub principal_investigator: Option<Reference>,
    /// `site` (0..*): Facility where study activities are conducted
    pub site: Vec<Reference>,
    /// `reasonStopped` (0..1): accrual-goal-met | closed-due-to-toxicity | closed-due-to-lack-of-study-progress | temporarily-closed-per-study-design
    pub reason_stopped: Option<CodeableConcept>,
    /// `note` (0..*): Comments made about the study
    pub note: Vec<Annotation>,
    /// `arm` (0..*): Defined path through the study for a subject
    pub arm: Vec<ResearchStudyArm>,
    /// `objective` (0..*): A goal for the study
    pub objective: Vec<ResearchStudyObjective>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "ResearchStudy");
        let r = ResearchStudy {
            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"),
            identifier: o.list(d, "identifier"),
            title: o.prim(d, "title", Kind::String),
            protocol: o.list(d, "protocol"),
            part_of: o.list(d, "partOf"),
            status: o.prim(d, "status", Kind::Code),
            primary_purpose_type: o.one(d, "primaryPurposeType"),
            phase: o.one(d, "phase"),
            category: o.list(d, "category"),
            focus: o.list(d, "focus"),
            condition: o.list(d, "condition"),
            contact: o.list(d, "contact"),
            related_artifact: o.list(d, "relatedArtifact"),
            keyword: o.list(d, "keyword"),
            location: o.list(d, "location"),
            description: o.prim(d, "description", Kind::Markdown),
            enrollment: o.list(d, "enrollment"),
            period: o.one(d, "period"),
            sponsor: o.one(d, "sponsor"),
            principal_investigator: o.one(d, "principalInvestigator"),
            site: o.list(d, "site"),
            reason_stopped: o.one(d, "reasonStopped"),
            note: o.list(d, "note"),
            arm: o.list(d, "arm"),
            objective: o.list(d, "objective"),
        };
        required(d, "status", &r.status);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("ResearchStudy".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.list("identifier", &self.identifier);
        w.prim("title", &self.title);
        w.list("protocol", &self.protocol);
        w.list("partOf", &self.part_of);
        w.prim("status", &self.status);
        w.one("primaryPurposeType", &self.primary_purpose_type);
        w.one("phase", &self.phase);
        w.list("category", &self.category);
        w.list("focus", &self.focus);
        w.list("condition", &self.condition);
        w.list("contact", &self.contact);
        w.list("relatedArtifact", &self.related_artifact);
        w.list("keyword", &self.keyword);
        w.list("location", &self.location);
        w.prim("description", &self.description);
        w.list("enrollment", &self.enrollment);
        w.one("period", &self.period);
        w.one("sponsor", &self.sponsor);
        w.one("principalInvestigator", &self.principal_investigator);
        w.list("site", &self.site);
        w.one("reasonStopped", &self.reason_stopped);
        w.list("note", &self.note);
        w.list("arm", &self.arm);
        w.list("objective", &self.objective);
        w.finish()
    }
}

/// Defined path through the study for a subject
///
/// FHIR path: `ResearchStudy.arm`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ResearchStudyArm {
    /// `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>,
    /// `name` (1..1): Label for study arm
    pub name: Option<Primitive<String>>,
    /// `type` (0..1): Categorization of study arm
    pub type_: Option<CodeableConcept>,
    /// `description` (0..1): Short explanation of study path
    pub description: Option<Primitive<String>>,
}

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

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

/// A goal for the study
///
/// FHIR path: `ResearchStudy.objective`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ResearchStudyObjective {
    /// `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>,
    /// `name` (0..1): Label for the objective
    pub name: Option<Primitive<String>>,
    /// `type` (0..1): primary | secondary | exploratory
    pub type_: Option<CodeableConcept>,
}

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

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