Skip to content

Commit

Permalink
use blue-button-xml for sensing
Browse files Browse the repository at this point in the history
  • Loading branch information
Afsin Ustundag committed Nov 12, 2014
1 parent 18e10a0 commit 9372a00
Showing 1 changed file with 7 additions and 52 deletions.
59 changes: 7 additions & 52 deletions lib/sense.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
"use strict";

var xml = require("blue-button-xml").xmlUtil;
var _ = require("underscore");

var DEFAULT_NS = {
"h": "urn:hl7-org:v3",
"xsi": "http://www.w3.org/2001/XMLSchema-instance"
};

//Sense document type based on XML object
var senseXml = function (doc) {
Expand All @@ -18,62 +12,23 @@ var senseXml = function (doc) {
return null;
}

var root = doc.root();

var children = root.find("h:templateId", DEFAULT_NS);

//Extension for CDA R2 headers.
var code_children = root.find("h:code", DEFAULT_NS);

var c32Result = _.find(children, function (child) {
if (child.attr("root").value() === "2.16.840.1.113883.3.88.11.32.1") {
return true;
} else {
return false;
}
});

if (c32Result !== undefined) {
var c32Result = xml.xpath(doc, 'h:templateId[@root=\"2.16.840.1.113883.3.88.11.32.1\"]');
if (c32Result && c32Result.length > 0) {
return {
type: "c32"
};
}

var CDAResult = _.find(children, function (child) {
if (child.attr("root").value() === "2.16.840.1.113883.10.20.1") {
return true;
} else {
return false;
}
});

var CDATemplateResult = _.find(code_children, function (child) {
if (child.attr("code").value() === "34133-9") {
if (child.attr("codeSystem").value() === "2.16.840.1.113883.6.1") {
return true;
} else {
return false;
}
} else {
return false;
}
});

if (CDAResult !== undefined && CDATemplateResult !== undefined) {
var cdaResult = xml.xpath(doc, 'h:templateId[@root=\"2.16.840.1.113883.10.20.1\"]');
var cdaTemplateResult = xml.xpath(doc, 'h:code[@code=\"34133-9\"][@codeSystem=\"2.16.840.1.113883.6.1\"]');
if ((cdaResult && cdaResult.length > 0) && (cdaTemplateResult && cdaTemplateResult.length > 0)) {
return {
type: "cda"
};
}

var CCDResult = _.find(children, function (child) {
if (child.attr("root").value() === "2.16.840.1.113883.10.20.22.1.2") {
return true;
} else {
return false;
}
});

if (CCDResult !== undefined) {
var ccdResult = xml.xpath(doc, 'h:templateId[@root=\"2.16.840.1.113883.10.20.22.1.2\"]');
if (ccdResult && ccdResult.length > 0) {
return {
type: "ccda"
};
Expand Down

0 comments on commit 9372a00

Please sign in to comment.