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 `DiagnosticReport` 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 findings and interpretation of diagnostic tests performed on patients, groups of patients, devices, and locations, and/or specimens derived from these. The report includes clinical context such as requesting and provider information, and some mix of atomic results, images, textual and coded interpretations, and formatted representation of diagnostic reports.
///
/// FHIR path: `DiagnosticReport`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DiagnosticReport {
    /// `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 report
    pub identifier: Vec<Identifier>,
    /// `basedOn` (0..*): What was requested
    pub based_on: Vec<Reference>,
    /// `status` (1..1): registered | partial | preliminary | final +
    pub status: Option<Primitive<String>>,
    /// `category` (0..*): Service category
    pub category: Vec<CodeableConcept>,
    /// `code` (1..1): Name/Code for this diagnostic report
    pub code: Option<CodeableConcept>,
    /// `subject` (0..1): The subject of the report - usually, but not always, the patient
    pub subject: Option<Reference>,
    /// `encounter` (0..1): Health care event when test ordered
    pub encounter: Option<Reference>,
    /// `effective[x]` (0..1): Clinically relevant time/time-period for report
    pub effective: Option<DiagnosticReportEffective>,
    /// `issued` (0..1): DateTime this version was made
    pub issued: Option<Primitive<String>>,
    /// `performer` (0..*): Responsible Diagnostic Service
    pub performer: Vec<Reference>,
    /// `resultsInterpreter` (0..*): Primary result interpreter
    pub results_interpreter: Vec<Reference>,
    /// `specimen` (0..*): Specimens this report is based on
    pub specimen: Vec<Reference>,
    /// `result` (0..*): Observations
    pub result: Vec<Reference>,
    /// `imagingStudy` (0..*): Reference to full details of imaging associated with the diagnostic report
    pub imaging_study: Vec<Reference>,
    /// `media` (0..*): Key images associated with this report
    pub media: Vec<DiagnosticReportMedia>,
    /// `conclusion` (0..1): Clinical conclusion (interpretation) of test results
    pub conclusion: Option<Primitive<String>>,
    /// `conclusionCode` (0..*): Codes for the clinical conclusion of test results
    pub conclusion_code: Vec<CodeableConcept>,
    /// `presentedForm` (0..*): Entire report as issued
    pub presented_form: Vec<Attachment>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "DiagnosticReport");
        let r = DiagnosticReport {
            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"),
            based_on: o.list(d, "basedOn"),
            status: o.prim(d, "status", Kind::Code),
            category: o.list(d, "category"),
            code: o.one(d, "code"),
            subject: o.one(d, "subject"),
            encounter: o.one(d, "encounter"),
            effective: o.choice(d, "effective"),
            issued: o.prim(d, "issued", Kind::Instant),
            performer: o.list(d, "performer"),
            results_interpreter: o.list(d, "resultsInterpreter"),
            specimen: o.list(d, "specimen"),
            result: o.list(d, "result"),
            imaging_study: o.list(d, "imagingStudy"),
            media: o.list(d, "media"),
            conclusion: o.prim(d, "conclusion", Kind::String),
            conclusion_code: o.list(d, "conclusionCode"),
            presented_form: o.list(d, "presentedForm"),
        };
        required(d, "status", &r.status);
        required(d, "code", &r.code);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("DiagnosticReport".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.list("basedOn", &self.based_on);
        w.prim("status", &self.status);
        w.list("category", &self.category);
        w.one("code", &self.code);
        w.one("subject", &self.subject);
        w.one("encounter", &self.encounter);
        w.choice("effective", &self.effective);
        w.prim("issued", &self.issued);
        w.list("performer", &self.performer);
        w.list("resultsInterpreter", &self.results_interpreter);
        w.list("specimen", &self.specimen);
        w.list("result", &self.result);
        w.list("imagingStudy", &self.imaging_study);
        w.list("media", &self.media);
        w.prim("conclusion", &self.conclusion);
        w.list("conclusionCode", &self.conclusion_code);
        w.list("presentedForm", &self.presented_form);
        w.finish()
    }
}

/// Key images associated with this report
///
/// FHIR path: `DiagnosticReport.media`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DiagnosticReportMedia {
    /// `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>,
    /// `comment` (0..1): Comment about the image (e.g. explanation)
    pub comment: Option<Primitive<String>>,
    /// `link` (1..1): Reference to the image source
    pub link: Option<Reference>,
}

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

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

/// The types `DiagnosticReport.effective[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum DiagnosticReportEffective {
    /// `dateTime`
    DateTime(Primitive<String>),
    /// `Period`
    Period(Period),
}

#[cfg(feature = "clinical")]
impl Choice for DiagnosticReportEffective {
    const TYPES: &'static [&'static str] = &["dateTime", "Period"];

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

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