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

94.11% Statements 80/85
70% Branches 7/10
100% Functions 2/2
94.11% Lines 80/85

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
    82
    83
    84
    85
    861x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    20x
    20x
    8x
    18x

    12x
    12x
    12x

    20x
    20x
    1x
    1x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    20x
    20x

    20x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    33x
    1x
    1x
    1x
     "use strict";

    var shared = require("../shared");
    var component = require("@amida-tech/blue-button-xml").component.withNullFlavor();
    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/text()"],
          ["manufacturer", "0..1", "h:manufacturerOrganization/h:name/text()"],
        ]);

      var ImmunizationActivity = component.define("ImmunizationActivity")
        .templateRoot([clinicalStatementsIDs.ImmunizationActivity, clinicalStatementsIDs.MedicationActivity])
        .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:repeatNumber/@value"],
          ["product", "0..1", "h:consumable/h:manufacturedProduct", immunizationActivityProduct],
          ["administration", "0..1", "./../h:substanceAdministration", ImmunizationAdministration],
          ["performer", "0..1", "h:performer/h:assignedEntity", shared.assignedEntity],
          ["instructions", "0..1", "h:entryRelationship[@typeCode='SUBJ']/h:act", ImmunizationInstructions],
          ["refusal_reason", "0..1", "h:entryRelationship/h:observation/h:code/@code", shared.SimpleCode("2.16.840.1.113883.5.8")],
        ]).cleanupStep(function () { // Quick and dirty fix for when refusal_reason catches other observations in Vitera.
          if (this.js) { // Refusal reason should use the template id
            if (this.js.refusal_reason && (!_.get(this, "js.refusal_reason.js"))) {
              delete this.js.refusal_reason;
            }
          }
        });

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

      immunizationsSection.cleanupStep(cleanup.replaceWithField('immunizations'));
      return [immunizationsSection, ImmunizationActivity];
    };

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