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

100% Statements 117/117
100% Branches 3/3
100% Functions 1/1
100% Lines 117/117

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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    1181x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    3x
    3x
    3x
    3x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    10x
    10x
    10x
    10x
    10x
    10x
    10x
    10x
    10x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    30x
    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 exportProceduresSection = function (version) {
      var sectionIDs = bbm.CCDA["sections" + version];
      var clinicalStatementsIDs = bbm.CCDA["statements" + version];

      /*
      var organization = component.define('organization');
      organization.fields([
          ["name", "0:1", "h:name"],
          ["address", "0..1", "h:addr", shared.Address],
          ["identifiers", "0..*", "h:id", shared.Identifier],
          ["phone", "0..*", shared.phone.xpath(), shared.phone],
          ["email", "0..*", shared.email.xpath(), shared.email]
      ]);

      //replaced with shared.assignedEntity to normalize with performer in other sections
      var provider = component.define('provider');
      provider.fields([
          ["address", "1..1", "h:addr", shared.Address],
          ["identifiers", "0..*", "h:id", shared.Identifier],
          ["phone", "0..*", shared.phone.xpath(), shared.phone],
          ["email", "0..*", shared.email.xpath(), shared.email],
          ["organization", "0..1", "h:representedOrganization", organization]
      ]);
      */

      var ProcedureSpecimen = component.define('ProcedureSpecimen')
        .fields([
          ["identifiers", "0..*", "h:specimenRole/h:id", shared.Identifier],
          ["code", "0..1", "h:specimenRole/h:specimenPlayingEntity/h:code", shared.ConceptDescriptor]
        ]);

      // ..
      var observationEntry = component.define('procedureObservation');
      observationEntry.fields([
        ["procedure", "1..1", "h:code", shared.ConceptDescriptor],
        ["identifiers", "0..*", "h:id", shared.Identifier],
        ["status", "1..1", "h:statusCode", shared.simplifiedCodeOID('2.16.840.1.113883.11.20.9.22')],
        ["date_time", "0..1", "h:effectiveTime", shared.EffectiveTime],
        ["body_sites", "0..*", "h:targetSiteCode", shared.ConceptDescriptor],
        ["priority", "0..1", "h:priorityCode", shared.ConceptDescriptor],
        ["performers", "0..*", "h:performer/h:assignedEntity", shared.assignedEntity],
        ["locations", "0..*", "h:participant/h:participantRole", shared.serviceDeliveryLocation],
        ["procedure_type", "1..1", "h:templateId/@root"],
        ["value", "1..1", "h:value", shared.ConceptDescriptor],
      ]);
      observationEntry.cleanupStep(function () {
        if (this.js && _.has(this, "js.value") && _.isEmpty(this.js.value.js)) {
          delete this.js.value;
        }
      });

      var procedureEntry = component.define('procedureProcedure');
      procedureEntry.fields([
        ["procedure", "1..1", "h:code", shared.ConceptDescriptor],
        ["identifiers", "0..*", "h:id", shared.Identifier],
        ["status", "1..1", "h:statusCode", shared.simplifiedCodeOID('2.16.840.1.113883.11.20.9.22')],
        ["date_time", "0..1", "h:effectiveTime", shared.EffectiveTime],
        ["body_sites", "0..*", "h:targetSiteCode", shared.ConceptDescriptor],
        ["specimen", "0..1", "h:specimen", ProcedureSpecimen],
        // should be
        // ["specimen", "0..*", "h:specimen", ProcedureSpecimen],
        ["priority", "0..1", "h:priorityCode", shared.ConceptDescriptor],
        ["performers", "0..*", "h:performer/h:assignedEntity", shared.assignedEntity],
        ["locations", "0..*", "h:participant/h:participantRole", shared.serviceDeliveryLocation],
        ["procedure_type", "1..1", "h:templateId/@root"],
      ]);

      var actEntry = component.define('procedureAct');
      actEntry.fields([
        ["procedure", "1..1", "h:code", shared.ConceptDescriptor],
        ["identifiers", "0..*", "h:id", shared.Identifier],
        ["status", "1..1", "h:statusCode", shared.simplifiedCodeOID('2.16.840.1.113883.11.20.9.22')],
        ["date_time", "0..1", "h:effectiveTime", shared.EffectiveTime],
        ["priority", "0..1", "h:priorityCode", shared.ConceptDescriptor],
        ["performers", "0..*", "h:performer/h:assignedEntity", shared.assignedEntity],
        ["locations", "0..*", "h:participant/h:participantRole", shared.serviceDeliveryLocation],
        ["procedure_type", "1..1", "h:templateId/@root"],
      ]);

      var procedureUnion = component.define('procedureUnion');
      procedureUnion.templateRoot(['2.16.840.1.113883.10.20.22.4.12', '2.16.840.1.113883.10.20.22.4.13', '2.16.840.1.113883.10.20.22.4.14', clinicalStatementsIDs.ProcedureActivity]);
      procedureUnion.fields([
        ["actEntry", "0..1", ".//h:templateId[@root='2.16.840.1.113883.10.20.22.4.12']/..", actEntry],
        ["observationEntry", "0..1", ".//h:templateId[@root='2.16.840.1.113883.10.20.22.4.13']/..", observationEntry],
        ["procedureEntry", "0..1", ".//h:templateId[@root='2.16.840.1.113883.10.20.22.4.14']/..", procedureEntry],
      ]);
      procedureUnion.cleanupStep(cleanup.extractAllFields(["actEntry", "observationEntry", "procedureEntry"]));
      procedureUnion.cleanupStep(function () {
        var typeMap = {
          "2.16.840.1.113883.10.20.22.4.12": "act", // ccda
          "2.16.840.1.113883.10.20.22.4.13": "observation",
          "2.16.840.1.113883.10.20.22.4.14": "procedure",
          "2.16.840.1.113883.10.20.1.29": "procedure" // ccda-r1
        };
        var t = this.js['procedure_type'];
        this.js['procedure_type'] = typeMap[t];
      });

      var proceduresSection = component.define('proceduresSection');
      proceduresSection.templateRoot([sectionIDs.ProceduresSection, sectionIDs.ProceduresSectionEntriesOptional]);
      proceduresSection.fields([
        ["entry", "0..*", procedureUnion.xpath(), procedureUnion]
      ]);
      proceduresSection.cleanupStep(cleanup.replaceWithField('entry'));
      return [proceduresSection, procedureUnion];
    };

    exports.proceduresSection = exportProceduresSection;
    exports.proceduresEntry = exportProceduresSection;