# All files / blue-button/lib/parser/c32/sections immunizations.js

95.06% Statements 77/81
40% Branches 2/5
100% Functions 2/2
95.06% Lines 77/81

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    821x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    12x
    12x

    12x

    12x
    12x
    12x

    12x
    12x
    1x
    1x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    11x
    1x
    1x
    1x
     "use strict";

    var shared = require("../shared");
    var component = require("@amida-tech/blue-button-xml").component;
    var cleanup = require("../cleanup");
    var bbm = require("@amida-tech/blue-button-meta");
    var _ = require("lodash");

    var augmentImmunizationStatus = function () {
      var tmpStatus = "";
      if (_.get(this, 'js.negation_ind') === "true") {
        tmpStatus = "refused";
      } else if (_.get(this, 'js.mood_code') === "INT") {
        tmpStatus = "pending";
      } else if (_.get(this, 'js.mood_code') === "EVN") {
        tmpStatus = "complete";
      } else {
        tmpStatus = "unknown";
      }
      this.js = tmpStatus;
    };

    var exportImmunizationsSection = function (version) {
      var sectionIDs = bbm.CCDA["sections" + version];
      var clinicalStatementsIDs = bbm.CCDA["statements" + version];

      var ImmunizationStatus = component.define("ImmunizationStatus")
        .fields([
          ["mood_code", "0..1", "./@moodCode"],
          ["negation_ind", "0..1", "./@negationInd"],
        ]).cleanupStep(augmentImmunizationStatus);

      var ImmunizationAdministration = component.define("ImmunizationAdministration")
        .fields([
          ["route", "0..1", "h:routeCode", shared.ConceptDescriptor],
          ["body_site", "0..1", "h:approachSiteCode", shared.ConceptDescriptor],
          ["dose", "0..1", "h:doseQuantity", shared.PhysicalQuantity],
          ["form", "0..1", "h:administrationUnitCode", shared.ConceptDescriptor]
        ]);

      var ImmunizationInstructions = component.define("MedicationInstructions")
        .fields([
          ["code", "0..1", "h:code", shared.ConceptDescriptor],
          ["free_text", "0..1", "h:text", shared.TextWithReference]
        ]);

      var immunizationActivityProduct = component.define('immunizationActivityProduct')
        .fields([
          ["product", "1..1", "h:manufacturedMaterial/h:code", shared.ConceptDescriptor],
          ["lot_number", "0..1", "h:manufacturedMaterial/h:lotNumberText"],
          ["manufacturer", "0..1", "h:manufacturerOrganization/h:name"],
        ]);

      var ImmunizationActivity = component.define("ImmunizationActivity")
        .templateRoot(["2.16.840.1.113883.3.88.11.83.13"])
        .fields([
          ["date_time", "1..1", "h:effectiveTime", shared.EffectiveTime],
          ["identifiers", "0..*", "h:id", shared.Identifier],
          ["status", "0..1", "./../h:substanceAdministration", ImmunizationStatus],
          ["sequence_number", "0..1", "h:entryRelationship[@typeCode='SUBJ']/h:observation/h:value"],
          ["product", "0..1", "h:consumable/h:manufacturedProduct", immunizationActivityProduct],
          ["administration", "0..1", "./../h:substanceAdministration", ImmunizationAdministration],
          ["performer", "0..1", "h:performer/h:assignedEntity", shared.assignedEntity],
          //Not in C32 Spec.
          //["instructions", "0..1", "h:entryRelationship[@typeCode='RSON']/h:act", ImmunizationInstructions],
          ["refusal_reason", "0..1", "h:entryRelationship[@typeCode='RSON']/h:act", shared.SimpleCode("2.16.840.1.113883.10.20.1.27")],
        ]);

      var immunizationsSection = component.define("immunizationsSection");
      immunizationsSection.templateRoot(["2.16.840.1.113883.3.88.11.83.117", "1.3.6.1.4.1.19376.1.5.3.1.3.23"]);
      immunizationsSection.fields([
        ["immunizations", "0..*", ImmunizationActivity.xpath(), ImmunizationActivity]
      ]);

      immunizationsSection.cleanupStep(cleanup.replaceWithField('immunizations'));

      return [immunizationsSection, ImmunizationActivity];
    };

    exports.immunizationsSection = exportImmunizationsSection;
    exports.immunizationsEntry = exportImmunizationsSection;