diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index c2d9b8abf..000000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..179159f40 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +max_line_length = 120 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{diff,md,mdx}] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index d6b0d3d53..a33312bb4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,78 +1,80 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -!/src/**/Coverage - -# nyc test coverage -.nyc_output -.test_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz -!hl7.fhir.r4.core-4.0.1.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env - -# next.js build output -.next - -# test temp data -.temp* - -# app runtime data -service-templates -tmp/ - -# autogen files -src/lib/outputProcessor/autogen/*.interp -src/lib/outputProcessor/autogen/*.tokens - -.idea -*.DS_Store \ No newline at end of file +.DS_Store + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +!/src/**/Coverage + +# nyc test coverage +.nyc_output +.test_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz +!hl7.fhir.r4.core-4.0.1.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next + +# test temp data +.temp* + +# app runtime data +service-templates +tmp/ + +# autogen files +src/lib/outputProcessor/autogen/*.interp +src/lib/outputProcessor/autogen/*.tokens + +.idea +*.DS_Store diff --git a/.node-version b/.node-version index a5f7da7f0..f46d5e394 100644 --- a/.node-version +++ b/.node-version @@ -1 +1 @@ -14.19.3 +14.21.3 diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..e8980d15c --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "printWidth": 120, + "tabWidth": 4 +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..d7a242768 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Attach", + "port": 9229, + "request": "attach", + "skipFiles": [ + "/**" + ], + "type": "node" + } + ] +} diff --git a/README.md b/README.md index 50193d57b..5ff00db55 100644 --- a/README.md +++ b/README.md @@ -109,3 +109,10 @@ provided by the bot. You will only need to do this once across all repos using o This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + +## M2 Macs + +```shell +arch -x86_64 zsh +nodenv install 14.21.3 +``` diff --git a/src/convert-xml-to-fhir-resource.js b/src/convert-xml-to-fhir-resource.js index b8b2ee529..f5cb69ea0 100644 --- a/src/convert-xml-to-fhir-resource.js +++ b/src/convert-xml-to-fhir-resource.js @@ -4,10 +4,14 @@ const WorkerPool = require("./lib/workers/workerPool"); function createAndUploadFhirResource() { let filePath, newPath; const generateChirpTestFile = process.argv.slice(2)[0] == '--chirp-test-file'; + const filePathArg = process.argv.slice(2).find(value => /^--filePath=/.test(value)); if (generateChirpTestFile) { filePath = "src/sample-data/cda/Chirp_CCD.cda"; newPath = "test/e2e-test/regression-test/data/cda/ccd.hbs/ccd.hbs-Chirp_CCD.cda.json"; + } else if(filePathArg) { + filePath = filePathArg.split("=")[1].trim(); + newPath = filePath.replace(".xml", "--FHIR-RESOURCE.json"); } else { if ((process.env.npm_config_filepath || '') === '') { console.log("Must specify file path"); diff --git a/src/lib/handlebars-converter/handlebars-helpers.js b/src/lib/handlebars-converter/handlebars-helpers.js index f8f85da8d..fc9cd939c 100644 --- a/src/lib/handlebars-converter/handlebars-helpers.js +++ b/src/lib/handlebars-converter/handlebars-helpers.js @@ -643,35 +643,56 @@ module.exports.external = [ } } }, - { name: 'getBirthSexInfo', description: "Returns first instance of birthSex id e.g. getBirthSexInfo msg '2.16.840.1.113883.10.20.22.2.14'", + // FIXME: (anti-pattern) the arrow pattern here has been slightly improved but is still really bad + // FIXME: (code smell) long method - the function is way too long, but the structure of this file is terrible + // there isn't an obvious way to extract a method without introducing a new pattern and that's not the goal here func: function getBirthSexInfo(msg, templateId) { try { - var birthSexValue ; + var birthSexValue; let structuredBody = msg.ClinicalDocument.component.structuredBody; - if(structuredBody && structuredBody.component) { - for(var i=0; i< structuredBody.component.length; i++) { - let sectionObj = structuredBody.component[i].section; - if(sectionObj && sectionObj.templateId && JSON.stringify(sectionObj.templateId).includes('2.16.840.1.113883.10.20.22.2.17')){ - let entryObjs = sectionObj.entry; - for(var j=0; j < entryObjs.length; j++) { - let entryObj = entryObjs[j]; - if(entryObj){ - let observation = entryObj.observation; - if(observation && observation.templateId && JSON.stringify(observation.templateId).includes(templateId)){ - birthSexValue = observation.value.code; - break; - } - } + + // return undefined when there is no structured body component + if (!structuredBody || !structuredBody.component) return birthSexValue; + + sectionLoop: for (var i = 0; i < structuredBody.component.length; i++) { + let sectionObj = structuredBody.component[i].section; + if (!sectionObj || !sectionObj.templateId) continue; + if (!JSON.stringify(sectionObj.templateId).includes("2.16.840.1.113883.10.20.22.2.17")) continue; + + if (Array.isArray(sectionObj.entry)) { + let entries = sectionObj.entry; + for (var j = 0; j < entries.length; j++) { + let entry = entries[j]; + if (!entry) continue; + + let observation = entry.observation; + if ( + observation && + observation.templateId && + JSON.stringify(observation.templateId).includes(templateId) + ) { + birthSexValue = observation.value.code; + break sectionLoop; } } + } else { + let entry = sectionObj.entry; + if ( + entry && + entry.observation && + entry.observation.templateId && + JSON.stringify(entry.observation.templateId).includes(templateId) + ) { + birthSexValue = entry.observation.value.code; + break sectionLoop; + } } } return birthSexValue; - } - catch (err) { + } catch (err) { throw `helper "getBirthSexInfo" : ${err}`; } } diff --git a/src/templates/cda/Resources/Patient.hbs b/src/templates/cda/Resources/Patient.hbs index be3f70959..03f7d3df7 100644 --- a/src/templates/cda/Resources/Patient.hbs +++ b/src/templates/cda/Resources/Patient.hbs @@ -50,14 +50,14 @@ [ { "system":"urn:ietf:bcp:47", - "code":"{{this.languageCode.code}}", + "code":"{{this.languageCode.code}}", "display":{{>ValueSet/Language.hbs code=this.languageCode.code}}, }, ], - }, + }, "preferred":{{this.preferenceInd.value}}, }, - {{/each}} + {{/each}} ], }, "request":{