text: /* BlueButton.js -- 0.0.19 */
  
  !function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define(b):a.BlueButton=b()}(this,function(){var a=function(){var a=function(a){if(!a||"string"!=typeof a)return null;var b=a.substr(0,4),c=parseInt(a.substr(4,2),10)-1,d=a.substr(6,2);return new Date(b,c,d)},b=function(a){var c;for(var d in a)c=a[d],null===c&&delete a[d],c instanceof Object&&(c=b(c));return a};return{parseDate:a,trim:b}}(),b=function(){var a=function(a){function b(a){return{el:a,template:c,tag:d,elsByTag:e,attr:f,val:g,isEmpty:i}}if(a.length){for(var h=[],j=0;j<a.length;j++)h.push(b(a[j]));return h}return b(a)},b=function(a,b,c,d){a=a.getElementsByTagName(b);for(var e=0;e<a.length;e++)if(c=m?c.toLowerCase():c,a[e].getAttribute(c)===d)return a[e]},c=function(c){var d=b(this.el,"templateId","root",c);return d?a(d.parentNode):h()},d=function(b){var c=this.el.getElementsByTagName(b)[0];return c?a(c):h()},e=function(b){return a(this.el.getElementsByTagName(b))},f=function(a){return this.el?(a=m?a.toLowerCase():a,this.el.getAttribute(a)):null},g=function(){if(!this.el)return null;try{return this.el.childNodes[0].nodeValue}catch(a){return null}},h=function(){var b=n.createElement("empty");return a(b)},i=function(){return"empty"==this.el.tagName.toLowerCase()?!0:!1},j=function(b){if(!b||"string"!=typeof b)return console.log("BB Error: XML data is not a string"),null;var c;if(m)c=l.jsdom(b,l.level(1,"core"));else if(window.DOMParser)parser=new DOMParser,c=parser.parseFromString(b,"text/xml");else try{c=new ActiveXObject("Microsoft.XMLDOM"),c.async="false",c.loadXML(b)}catch(d){console.log("BB ActiveX Exception: Could not parse XML")}return c&&c.documentElement&&!c.getElementsByTagName("parsererror").length?a(c):(console.log("BB Error: Could not parse XML"),null)},k=this,l=void 0,m=!1,n=k.document;return"undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports&&(m=!0,l=require("jsdom"),n=new(l.level(1,"core").Document)),{parseXML:j}}(),c=function(){var a=function(a){var b={F:"female",M:"male",UN:"undifferentiated"};return b[a]||null},b=function(a){var b={N:"annulled",C:"common law",D:"divorced",P:"domestic partner",I:"interlocutory",E:"legally separated",G:"living together",M:"married",O:"other",R:"registered domestic partner",A:"separated",S:"single",U:"unknown",B:"unmarried",T:"unreported",W:"widowed"};return b[a]||null};return{gender:a,maritalStatus:b}}(),d=function(){return{}}();d.Allergies=function(){var b=a.parseDate,c=function(a){var c,d,e,f=[];c=a.template("2.16.840.1.113883.3.88.11.83.102"),d=c.elsByTag("entry");for(var g=0;g<d.length;g++){e=d[g],c=e.tag("effectiveTime");var h=b(c.tag("low").attr("value")),i=b(c.tag("high").attr("value"));c=e.template("2.16.840.1.113883.3.88.11.83.6").tag("code");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem"),m=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.3.88.11.83.6").tag("value");var n=c.attr("displayName"),o=c.attr("code"),p=c.attr("codeSystem"),q=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.10.20.1.54").tag("value");var r=c.attr("displayName"),s=c.attr("code"),t=c.attr("codeSystem");c=e.template("2.16.840.1.113883.10.20.1.55").tag("value");var u=c.attr("displayName");c=e.tag("participant").tag("code");var v=c.attr("displayName"),w=c.attr("code"),x=c.attr("codeSystem"),y=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.10.20.1.39").tag("value");var z=c.attr("displayName");f.push({date_range:{start:h,end:i},name:j,code:k,code_system:l,code_system_name:m,status:z,severity:u,reaction:{name:r,code:s,code_system:t},reaction_type:{name:n,code:o,code_system:p,code_system_name:q},allergen:{name:v,code:w,code_system:x,code_system_name:y}})}return f};return{parse:c}}(),d.Demographics=function(){var b=a.parseDate,d=function(a){var d,e,f,g={};d=a.template("2.16.840.1.113883.3.88.11.32.1"),f=d.tag("patientRole"),d=f.tag("patient").tag("name");var h=d.tag("prefix").val();e=d.elsByTag("given");for(var i=[],j=0;j<e.length;j++)i.push(e[j].val());var k=d.tag("family").val();d=f.tag("patient");var l=b(d.tag("birthTime").attr("value")),m=c.gender(d.tag("administrativeGenderCode").attr("code")),n=c.maritalStatus(d.tag("maritalStatusCode").attr("code"));d=f.tag("addr"),e=d.elsByTag("streetAddressLine");for(var o=[],j=0;j<e.length;j++)o.push(e[j].val());var p=d.tag("city").val(),q=d.tag("state").val(),r=d.tag("postalCode").val(),s=d.tag("country").val();d=f.tag("telecom");var t=d.attr("value"),u=null,v=null,w=null,x=f.tag("languageCommunication").tag("languageCode").attr("code"),y=f.tag("raceCode").attr("displayName"),z=f.tag("ethnicGroupCode").attr("displayName"),A=f.tag("religiousAffiliationCode").attr("displayName");d=f.tag("birthplace");var B=d.tag("state").val(),C=d.tag("postalCode").val(),D=d.tag("country").val();d=f.tag("guardian");var E=d.tag("code").attr("displayName"),F=d.tag("telecom").attr("value");d=d.tag("guardianPerson"),e=d.elsByTag("given");for(var G=[],j=0;j<e.length;j++)G.push(e[j].val());var H=d.tag("family").val();d=f.tag("guardian").tag("addr"),e=d.elsByTag("streetAddressLine");for(var I=[],j=0;j<e.length;j++)I.push(e[j].val());var J=d.tag("city").val(),K=d.tag("state").val(),L=d.tag("postalCode").val(),M=d.tag("country").val();d=f.tag("providerOrganization");var N=d.tag("name").val(),O=d.tag("telecom").attr("value");e=d.elsByTag("streetAddressLine");for(var P=[],j=0;j<e.length;j++)P.push(e[j].val());var Q=d.tag("city").val(),R=d.tag("state").val(),S=d.tag("postalCode").val(),T=d.tag("country").val();return g={name:{prefix:h,given:i,family:k},dob:l,gender:m,marital_status:n,address:{street:o,city:p,state:q,zip:r,country:s},phone:{home:t,work:u,mobile:v},email:w,language:x,race:y,ethnicity:z,religion:A,birthplace:{state:B,zip:C,country:D},guardian:{name:{given:G,family:H},relationship:E,address:{street:I,city:J,state:K,zip:L,country:M},phone:{home:F}},provider:{organization:N,phone:O,address:{street:P,city:Q,state:R,zip:S,country:T}}}};return{parse:d}}(),d.Encounters=function(){var b=a.parseDate,c=function(a){var c,d,e,f,g=[];c=a.template("2.16.840.1.113883.3.88.11.83.127"),e=c.elsByTag("entry");for(var h=0;h<e.length;h++){f=e[h];var i=b(f.tag("effectiveTime").attr("value"));if(!i)var i=b(f.tag("effectiveTime").tag("low").attr("value"));c=f.tag("code");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem"),m=c.attr("codeSystemName"),n=c.attr("codeSystemVersion");c=f.tag("value");var o=c.attr("displayName"),p=c.attr("code"),q=c.attr("codeSystem");c=f.tag("translation");var r=c.attr("displayName"),s=c.attr("code"),t=c.attr("codeSystem"),u=c.attr("codeSystemName");c=f.tag("performer");var v=c.tag("name").val(),w=c.attr("code"),x=c.attr("codeSystem"),y=c.attr("codeSystemName");c=f.tag("participant");var z=c.tag("name").val();d=c.elsByTag("streetAddressLine"),street=[];for(var A=0;A<d.length;A++)street.push(d[A].val());var B=c.tag("city").val(),C=c.tag("state").val(),D=c.tag("postalCode").val(),E=c.tag("country").val();g.push({date:i,name:j,code:k,code_system:l,code_system_name:m,code_system_version:n,finding:{name:o,code:p,code_system:q},translation:{name:r,code:s,code_system:t,code_system_name:u},performer:{name:v,code:w,code_system:x,code_system_name:y},location:{organization:z,street:street,city:B,state:C,zip:D,country:E}})}return g};return{parse:c}}(),d.Immunizations=function(){var b=a.parseDate,c=function(a){var c,d,e,f=[];c=a.template("2.16.840.1.113883.3.88.11.83.117"),d=c.elsByTag("entry");for(var g=0;g<d.length;g++){e=d[g],c=e.tag("effectiveTime");var h=b(c.attr("value"));c=e.template("2.16.840.1.113883.10.20.1.53").tag("code");var i=c.attr("displayName"),j=c.attr("code"),k=c.attr("codeSystem"),l=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.10.20.1.53").tag("translation");var m=c.attr("displayName"),n=c.attr("code"),o=c.attr("codeSystem"),p=c.attr("codeSystemName");c=e.tag("routeCode");var q=c.attr("displayName"),r=c.attr("code"),s=c.attr("codeSystem"),t=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.10.20.1.49");var u=c.tag("text").val();c=c.tag("code");var v=c.attr("displayName"),w=c.attr("code"),x=c.attr("codeSystem");f.push({date:h,product:{name:i,code:j,code_system:k,code_system_name:l,translation:{name:m,code:n,code_system:o,code_system_name:p}},route:{name:q,code:r,code_system:s,code_system_name:t},instructions:u,education_type:{name:v,code:w,code_system:x}})}return f};return{parse:c}}(),d.Labs=function(){var b=a.parseDate,c=function(a){var c,d,e,f,g,h,i=[];d=a.template("2.16.840.1.113883.3.88.11.83.122"),e=d.elsByTag("entry");for(var j=0;j<e.length;j++){f=e[j],d=f.tag("effectiveTime");var k=b(f.tag("effectiveTime").attr("value"));if(!k)var k=b(f.tag("effectiveTime").tag("low").attr("value"));d=f.tag("code");var l=d.attr("displayName"),m=d.attr("code"),n=d.attr("codeSystem"),o=d.attr("codeSystemName");g=f.elsByTag("component"),c=[];for(var p=0;p<g.length;p++)if(h=g[p],h.template("2.16.840.1.113883.10.20.1.31").val()){var q=b(h.tag("effectiveTime").attr("value"));d=h.tag("code");var r=d.attr("displayName"),s=d.attr("code"),t=d.attr("codeSystem"),u=d.attr("codeSystemName");d=h.tag("value");var v=parseFloat(d.attr("value")),w=d.attr("unit");d=h.tag("referenceRange");var x=d.tag("observationRange").tag("text").val();reference_range_low_unit=d.tag("observationRange").tag("low").attr("unit"),reference_range_low_value=d.tag("observationRange").tag("low").attr("value"),reference_range_high_unit=d.tag("observationRange").tag("high").attr("unit"),reference_range_high_value=d.tag("observationRange").tag("high").attr("value"),c.push({date:q,name:r,value:v,unit:w,code:s,code_system:t,code_system_name:u,reference_range:{text:x,low_unit:reference_range_low_unit,low_value:reference_range_low_value,high_unit:reference_range_high_unit,high_value:reference_range_high_value}})}i.push({name:l,code:m,code_system:n,code_system_name:o,date:k,results:c})}return i};return{parse:c}}(),d.Medications=function(){var b=a.parseDate,c=function(a){var c,d,e,f=[];c=a.template("2.16.840.1.113883.3.88.11.83.112"),d=c.elsByTag("entry");for(var g=0;g<d.length;g++){e=d[g],c=e.tag("effectiveTime");var h=b(c.tag("low").attr("value")),i=b(c.tag("high").attr("value"));c=e.tag("manufacturedProduct").tag("code");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem");c=e.tag("manufacturedProduct").tag("translation");var m=c.attr("displayName"),n=c.attr("code"),o=c.attr("codeSystem"),p=c.attr("codeSystemName");c=e.tag("doseQuantity");var q=c.attr("value"),r=c.attr("unit");c=e.tag("rateQuantity");var s=c.attr("value"),t=c.attr("unit");c=e.tag("precondition").tag("value");var u=c.attr("displayName"),v=c.attr("code"),w=c.attr("codeSystem"),c=e.template("2.16.840.1.113883.10.20.1.28").tag("value"),x=c.attr("displayName"),y=c.attr("code"),z=c.attr("codeSystem");c=e.tag("routeCode");var A=c.attr("displayName"),B=c.attr("code"),C=c.attr("codeSystem"),D=c.attr("codeSystemName");c=e.tag("participant").tag("code");var E=c.attr("displayName"),F=c.attr("code"),G=c.attr("codeSystem"),H=c.attr("codeSystemName");c=e.tag("administrationUnitCode");var I=c.attr("displayName"),J=c.attr("code"),K=c.attr("codeSystem"),L=c.attr("codeSystemName");c=e.tag("performer");var M=c.tag("name").val(),N=null;f.push({date_range:{start:h,end:i},product:{name:j,code:k,code_system:l,translation:{name:m,code:n,code_system:o,code_system_name:p}},dose_quantity:{value:q,unit:r},rate_quantity:{value:s,unit:t},precondition:{name:u,code:v,code_system:w},reason:{name:x,code:y,code_system:z},route:{name:A,code:B,code_system:C,code_system_name:D},vehicle:{name:E,code:F,code_system:G,code_system_name:H},administration:{name:I,code:J,code_system:K,code_system_name:L},prescriber:{organization:M,person:N}})}return f};return{parse:c}}(),d.Problems=function(){var b=a.parseDate,c=function(a){var c,d,e,f=[];c=a.template("2.16.840.1.113883.3.88.11.83.103"),d=c.elsByTag("entry");for(var g=0;g<d.length;g++){e=d[g],c=e.tag("effectiveTime");var h=b(c.tag("low").attr("value")),i=b(c.tag("high").attr("value"));c=e.template("2.16.840.1.113883.10.20.1.28").tag("value");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem");c=e.template("2.16.840.1.113883.10.20.1.50");var m=c.tag("value").attr("displayName");c=e.template("2.16.840.1.113883.10.20.1.38");var n=parseFloat(c.tag("value").attr("value"));f.push({date_range:{start:h,end:i},name:j,status:m,age:n,code:k,code_system:l})}return f};return{parse:c}}(),d.Procedures=function(){var b=a.parseDate,c=function(a){var c,d,e,f,g=[];c=a.template("2.16.840.1.113883.3.88.11.83.108"),e=c.elsByTag("entry");for(var h=0;h<e.length;h++){f=e[h],c=f.tag("effectiveTime");var i=b(c.attr("value"));c=f.tag("code");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem"),m=null,n=null,o=null;c=f.tag("performer").tag("addr");var p=c.tag("name").val(),q=c.tag("telecom").attr("value");d=c.elsByTag("streetAddressLine"),street=[];for(var r=0;r<d.length;r++)street.push(d[r].val());var s=c.tag("city").val(),t=c.tag("state").val(),u=c.tag("postalCode").val(),v=c.tag("country").val();c=f.tag("participant").tag("code");var w=c.attr("displayName"),x=c.attr("code"),y=c.attr("codeSystem");g.push({date:i,name:j,code:k,code_system:l,specimen:{name:m,code:n,code_system:o},performer:{organization:p,street:street,city:s,state:t,zip:u,country:v,phone:q},device:{name:w,code:x,code_system:y}})}return g};return{parse:c}}(),d.Vitals=function(){var b=a.parseDate,c=function(a){var c,d,e,f,g,h,i=[];d=a.template("2.16.840.1.113883.3.88.11.83.119"),e=d.elsByTag("entry");for(var j=0;j<e.length;j++){f=e[j],d=f.tag("effectiveTime");var k=b(d.attr("value"));g=f.elsByTag("component"),c=[];for(var l=0;l<g.length;l++){h=g[l],d=h.tag("code");var m=d.attr("displayName"),n=d.attr("code"),d=h.tag("value"),o=parseFloat(d.attr("value")),p=d.attr("unit");c.push({name:m,code:n,value:o,unit:p})}i.push({date:k,results:c})}return i};return{parse:c}}();var e=function(){return{}}();e.Allergies=function(){var b=a.parseDate,c=function(a){var c,d,e,f=[];c=a.template("2.16.840.1.113883.10.20.22.2.6.1"),d=c.elsByTag("entry");for(var g=0;g<d.length;g++){e=d[g],c=e.tag("effectiveTime");var h=b(c.tag("low").attr("value")),i=b(c.tag("high").attr("value"));c=e.template("2.16.840.1.113883.10.20.22.4.7").tag("code");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem"),m=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.10.20.22.4.7").tag("value");var n=c.attr("displayName"),o=c.attr("code"),p=c.attr("codeSystem"),q=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.10.20.22.4.9").tag("value");var r=c.attr("displayName"),s=c.attr("code"),t=c.attr("codeSystem");c=e.template("2.16.840.1.113883.10.20.22.4.8").tag("value");var u=c.attr("displayName");c=e.tag("participant").tag("code");var v=c.attr("displayName"),w=c.attr("code"),x=c.attr("codeSystem"),y=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.10.20.22.4.28").tag("value");var z=c.attr("displayName");f.push({date_range:{start:h,end:i},name:j,code:k,code_system:l,code_system_name:m,status:z,severity:u,reaction:{name:r,code:s,code_system:t},reaction_type:{name:n,code:o,code_system:p,code_system_name:q},allergen:{name:v,code:w,code_system:x,code_system_name:y}})}return f};return{parse:c}}(),e.Demographics=function(){var b=a.parseDate,d=function(a){var d,e,f,g={};d=a.template("2.16.840.1.113883.10.20.22.1.1"),f=d.tag("patientRole"),d=f.tag("patient").tag("name");var h=d.tag("prefix").val();e=d.elsByTag("given");for(var i=[],j=0;j<e.length;j++)i.push(e[j].val());var k=d.tag("family").val();d=f.tag("patient");var l=b(d.tag("birthTime").attr("value")),m=c.gender(d.tag("administrativeGenderCode").attr("code")),n=c.maritalStatus(d.tag("maritalStatusCode").attr("code"));d=f.tag("addr"),e=d.elsByTag("streetAddressLine");for(var o=[],j=0;j<e.length;j++)o.push(e[j].val());var p=d.tag("city").val(),q=d.tag("state").val(),r=d.tag("postalCode").val(),s=d.tag("country").val();d=f.tag("telecom");var t=d.attr("value"),u=null,v=null,w=null,x=f.tag("languageCommunication").tag("languageCode").attr("code"),y=f.tag("raceCode").attr("displayName"),z=f.tag("ethnicGroupCode").attr("displayName"),A=f.tag("religiousAffiliationCode").attr("displayName");d=f.tag("birthplace");var B=d.tag("state").val(),C=d.tag("postalCode").val(),D=d.tag("country").val();d=f.tag("guardian");var E=d.tag("code").attr("displayName"),F=d.tag("telecom").attr("value");d=d.tag("guardianPerson"),e=d.elsByTag("given");for(var G=[],j=0;j<e.length;j++)G.push(e[j].val());var H=d.tag("family").val();d=f.tag("guardian").tag("addr"),e=d.elsByTag("streetAddressLine");for(var I=[],j=0;j<e.length;j++)I.push(e[j].val());var J=d.tag("city").val(),K=d.tag("state").val(),L=d.tag("postalCode").val(),M=d.tag("country").val();d=f.tag("providerOrganization");var N=d.tag("name").val(),O=d.tag("telecom").attr("value");e=d.elsByTag("streetAddressLine");for(var P=[],j=0;j<e.length;j++)P.push(e[j].val());var Q=d.tag("city").val(),R=d.tag("state").val(),S=d.tag("postalCode").val(),T=d.tag("country").val();return g={name:{prefix:h,given:i,family:k},dob:l,gender:m,marital_status:n,address:{street:o,city:p,state:q,zip:r,country:s},phone:{home:t,work:u,mobile:v},email:w,language:x,race:y,ethnicity:z,religion:A,birthplace:{state:B,zip:C,country:D},guardian:{name:{given:G,family:H},relationship:E,address:{street:I,city:J,state:K,zip:L,country:M},phone:{home:F}},provider:{organization:N,phone:O,address:{street:P,city:Q,state:R,zip:S,country:T}}}};return{parse:d}}(),e.Encounters=function(){var b=a.parseDate,c=function(a){var c,d,e,f,g=[];c=a.template("2.16.840.1.113883.10.20.22.2.22"),c.isEmpty()&&(c=a.template("2.16.840.1.113883.10.20.22.2.22.1")),e=c.elsByTag("entry");for(var h=0;h<e.length;h++){f=e[h];var i=b(f.tag("effectiveTime").attr("value"));c=f.tag("code");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem"),m=c.attr("codeSystemName"),n=c.attr("codeSystemVersion");c=f.tag("value");var o=c.attr("displayName"),p=c.attr("code"),q=c.attr("codeSystem");c=f.tag("translation");var r=c.attr("displayName"),s=c.attr("code"),t=c.attr("codeSystem"),u=c.attr("codeSystemName");c=f.tag("performer").tag("code");var v=c.attr("displayName"),w=c.attr("code"),x=c.attr("codeSystem"),y=c.attr("codeSystemName");c=f.tag("participant");var z=c.tag("code").attr("displayName");d=c.elsByTag("streetAddressLine"),street=[];for(var A=0;A<d.length;A++)street.push(d[A].val());var B=c.tag("city").val(),C=c.tag("state").val(),D=c.tag("postalCode").val(),E=c.tag("country").val();g.push({date:i,name:j,code:k,code_system:l,code_system_name:m,code_system_version:n,finding:{name:o,code:p,code_system:q},translation:{name:r,code:s,code_system:t,code_system_name:u},performer:{name:v,code:w,code_system:x,code_system_name:y},location:{organization:z,street:street,city:B,state:C,zip:D,country:E}})}return g};return{parse:c}}(),e.Immunizations=function(){var b=a.parseDate,c=function(a){var c,d,e,f=[];c=a.template("2.16.840.1.113883.10.20.22.2.2.1"),c.isEmpty()&&(c=a.template("2.16.840.1.113883.10.20.22.2.2")),d=c.elsByTag("entry");for(var g=0;g<d.length;g++){e=d[g],c=e.tag("effectiveTime");var h=b(c.attr("value"));c=e.template("2.16.840.1.113883.10.20.22.4.54").tag("code");var i=c.attr("displayName"),j=c.attr("code"),k=c.attr("codeSystem"),l=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.10.20.22.4.54").tag("translation");var m=c.attr("displayName"),n=c.attr("code"),o=c.attr("codeSystem"),p=c.attr("codeSystemName");c=e.tag("routeCode");var q=c.attr("displayName"),r=c.attr("code"),s=c.attr("codeSystem"),t=c.attr("codeSystemName");c=e.template("2.16.840.1.113883.10.20.22.4.20");var u=c.tag("text").val();c=c.tag("code");var v=c.attr("displayName"),w=c.attr("code"),x=c.attr("codeSystem");f.push({date:h,product:{name:i,code:j,code_system:k,code_system_name:l,translation:{name:m,code:n,code_system:o,code_system_name:p}},route:{name:q,code:r,code_system:s,code_system_name:t},instructions:u,education_type:{name:v,code:w,code_system:x}})}return f};return{parse:c}}(),e.Labs=function(){var b=a.parseDate,c=function(a){var c,d,e,f,g,h,i=[];d=a.template("2.16.840.1.113883.10.20.22.2.3.1"),e=d.elsByTag("entry");for(var j=0;j<e.length;j++){f=e[j],d=f.tag("code");var k=d.attr("displayName"),l=d.attr("code"),g=f.elsByTag("component");c=[];for(var m=0;m<g.length;m++){h=g[m];var n=b(h.tag("effectiveTime").attr("value"));d=h.tag("code");var o=d.attr("displayName"),p=d.attr("code"),d=h.tag("value"),q=parseFloat(d.attr("value")),r=d.attr("unit");c.push({date:n,name:o,value:q,unit:r,code:p})}i.push({name:k,code:l,results:c})}return i};return{parse:c}}(),e.Medications=function(){var b=a.parseDate,c=function(a){var c,d,e,f=[];c=a.template("2.16.840.1.113883.10.20.22.2.1.1"),d=c.elsByTag("entry");for(var g=0;g<d.length;g++){e=d[g],c=e.tag("effectiveTime");var h=b(c.tag("low").attr("value")),i=b(c.tag("high").attr("value"));c=e.tag("manufacturedProduct").tag("code");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem");c=e.tag("manufacturedProduct").tag("translation");var m=c.attr("displayName"),n=c.attr("code"),o=c.attr("codeSystem"),p=c.attr("codeSystemName");c=e.tag("doseQuantity");var q=c.attr("value"),r=c.attr("unit");c=e.tag("rateQuantity");var s=c.attr("value"),t=c.attr("unit");c=e.tag("precondition").tag("value");var u=c.attr("displayName"),v=c.attr("code"),w=c.attr("codeSystem"),c=e.template("2.16.840.1.113883.10.20.22.4.19").tag("value"),x=c.attr("displayName"),y=c.attr("code"),z=c.attr("codeSystem");c=e.tag("routeCode");var A=c.attr("displayName"),B=c.attr("code"),C=c.attr("codeSystem"),D=c.attr("codeSystemName");c=e.tag("participant").tag("code");var E=c.attr("displayName"),F=c.attr("code"),G=c.attr("codeSystem"),H=c.attr("codeSystemName");c=e.tag("administrationUnitCode");var I=c.attr("displayName"),J=c.attr("code"),K=c.attr("codeSystem"),L=c.attr("codeSystemName");c=e.tag("performer");var M=c.tag("name").val(),N=null;f.push({date_range:{start:h,end:i},product:{name:j,code:k,code_system:l,translation:{name:m,code:n,code_system:o,code_system_name:p}},dose_quantity:{value:q,unit:r},rate_quantity:{value:s,unit:t},precondition:{name:u,code:v,code_system:w},reason:{name:x,code:y,code_system:z},route:{name:A,code:B,code_system:C,code_system_name:D},vehicle:{name:E,code:F,code_system:G,code_system_name:H},administration:{name:I,code:J,code_system:K,code_system_name:L},prescriber:{organization:M,person:N}})}return f};return{parse:c}}(),e.Problems=function(){var b=a.parseDate,c=function(a){var c,d,e,f=[];c=a.template("2.16.840.1.113883.10.20.22.2.5.1"),c.isEmpty()&&(c=a.template("2.16.840.1.113883.10.20.22.2.5")),d=c.elsByTag("entry");for(var g=0;g<d.length;g++){e=d[g],c=e.tag("effectiveTime");var h=b(c.tag("low").attr("value")),i=b(c.tag("high").attr("value"));c=e.template("2.16.840.1.113883.10.20.22.4.4").tag("value");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem");c=e.template("2.16.840.1.113883.10.20.22.4.6");var m=c.tag("value").attr("displayName");c=e.template("2.16.840.1.113883.10.20.22.4.31");var n=parseFloat(c.tag("value").attr("value"));f.push({date_range:{start:h,end:i},name:j,status:m,age:n,code:k,code_system:l})}return f};return{parse:c}}(),e.Procedures=function(){var b=a.parseDate,c=function(a){var c,d,e,f,g=[];c=a.template("2.16.840.1.113883.10.20.22.2.7.1"),c.isEmpty()&&(c=a.template("2.16.840.1.113883.10.20.22.2.7")),e=c.elsByTag("entry");for(var h=0;h<e.length;h++){f=e[h],c=f.tag("effectiveTime");var i=b(c.attr("value"));c=f.tag("code");var j=c.attr("displayName"),k=c.attr("code"),l=c.attr("codeSystem"),m=null,n=null,o=null;c=f.tag("performer").tag("addr");var p=c.tag("name").val(),q=c.tag("telecom").attr("value");d=c.elsByTag("streetAddressLine"),street=[];for(var r=0;r<d.length;r++)street.push(d[r].val());var s=c.tag("city").val(),t=c.tag("state").val(),u=c.tag("postalCode").val(),v=c.tag("country").val();c=f.tag("participant").tag("code");var w=c.attr("displayName"),x=c.attr("code"),y=c.attr("codeSystem");g.push({date:i,name:j,code:k,code_system:l,specimen:{name:m,code:n,code_system:o},performer:{organization:p,street:street,city:s,state:t,zip:u,country:v,phone:q},device:{name:w,code:x,code_system:y}})}return g};return{parse:c}}(),e.Vitals=function(){var b=a.parseDate,c=function(a){var c,d,e,f,g,h,i=[];d=a.template("2.16.840.1.113883.10.20.22.2.4.1"),e=d.elsByTag("entry");for(var j=0;j<e.length;j++){f=e[j],d=f.tag("effectiveTime");var k=b(d.attr("value"));g=f.elsByTag("component"),c=[];for(var l=0;l<g.length;l++){h=g[l],d=h.tag("code");var m=d.attr("displayName"),n=d.attr("code"),d=h.tag("value"),o=parseFloat(d.attr("value")),p=d.attr("unit");c.push({name:m,code:n,value:o,unit:p})}i.push({date:k,results:c})}return i};return{parse:c}}();var f=function(c){var f=null,g="",h={},i=function(a){for(var b=0;b<a.length;b++)a[b].json=function(){return JSON.stringify(this,null,2)}},j=function(){return h.document},k=function(){return h.allergies},l=function(){return h.demographics},m=function(){return h.encounters},n=function(){return h.immunizations},o=function(){return h.labs},p=function(){return h.medications},q=function(){return h.problems},r=function(){return h.procedures},s=function(b){return b?a.filters(h.vitals):h.vitals};switch(c=c.replace(/^\s+|\s+$/g,""),"<?xml"==c.substr(0,5)?(f=b.parseXML(c),f.template("2.16.840.1.113883.3.88.11.32.1").isEmpty()?f.template("2.16.840.1.113883.10.20.22.1.2").isEmpty()||(g="ccda"):g="c32"):g="json",h.document={type:g},g){case"c32":h.allergies=d.Allergies.parse(f),h.demographics=d.Demographics.parse(f),h.encounters=d.Encounters.parse(f),h.immunizations=d.Immunizations.parse(f),h.labs=d.Labs.parse(f),h.medications=d.Medications.parse(f),h.problems=d.Problems.parse(f),h.procedures=d.Procedures.parse(f),h.vitals=d.Vitals.parse(f);break;case"ccda":h.allergies=e.Allergies.parse(f),h.demographics=e.Demographics.parse(f),h.encounters=e.Encounters.parse(f),h.immunizations=e.Immunizations.parse(f),h.labs=e.Labs.parse(f),h.medications=e.Medications.parse(f),h.problems=e.Problems.parse(f),h.procedures=e.Procedures.parse(f),h.vitals=e.Vitals.parse(f);break;case"json":try{JSON.parse(c)}catch(t){console.log("BB Exception: Could not parse JSON")}console.log("BB Error: Blue Button JSON not yet implemented.")}return i([h,h.document,h.allergies,h.demographics,h.encounters,h.immunizations,h.labs,h.medications,h.problems,h.procedures,h.vitals]),{xmlDOM:f,data:h,document:j,allergies:k,demographics:l,encounters:m,immunizations:n,labs:o,medications:p,problems:q,procedures:r,vitals:s}};return f});