Skip to content

Commit

Permalink
chore(eslint): ESLint setup (openemr#6708)
Browse files Browse the repository at this point in the history
* chore(eslint): ESLint setup

* fix(portal): fix lint error in signer_api

* fix(library): disable no-constant-condition error in textformat

* fix(library): disable no-cond-assign error in validate_extend

* fix(library): disable no-inner-declarations error in utility

* fix(library): fix lint error in html

* fix(library): fix lint errors in clickmap

* fix(library): fix lint errors in ajax_functions_writer

* fix(library): fix lint errors in dialog

* fix(interface): fix lint errors in product_registration_service

* fix(interface): disable no-unused-labels in autosuggest

* fix(interface): fix lint errors in sendTo

* fix(interface): fix lint errors in oe-module-comlink-telehealth

* fix(interface): fix lint errors in tabs

* fix(interface): fix lint errors in fee_sheet_core

* fix(gulp): fix lint errors in gulpfile

* fix(ccdaservice): fix lint errors

* chore(eslint): pin package versions

* chore(interface): rebuild telehealth.min.js

* feat(ci): add step for ESLint
  • Loading branch information
raskolnikov-rodion committed Aug 9, 2023
1 parent e05dd26 commit 7de6b61
Show file tree
Hide file tree
Showing 34 changed files with 2,042 additions and 136 deletions.
21 changes: 21 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
node_modules
interface/forms/eye_mag/js
interface/forms/questionnaire_assessments/lforms
interface/main/calendar/modules/PostCalendar/pnincludes/*.js
interface/modules/custom_modules/oe-module-comlink-telehealth/public/assets/js/dist
interface/modules/custom_modules/oe-module-comlink-telehealth/public/assets/js/src/cvb.min.js
interface/modules/zend_modules/public/js/lib/**/*.js
interface/super/rules/www/js/cdr-multiselect
interface/super/rules/www/js/jQuery.autocomplete.js
interface/super/rules/www/js/jQuery.fn.sortElements.js
library/ESign/js/jquery.esign.js
library/js/vendors/validate/validate_modified.js
library/js/xl/**/*.js
library/js/u2f-api.js
library/js/SearchHighlight.js
library/js/DocumentTreeMenu.js
library/js/CategoryTreeMenu.js
portal/sign/assets/signature_pad.umd.js
portal/patient/scripts
public/assets
swagger
24 changes: 24 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"jquery": true
},
"extends": ["eslint:recommended"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"no-undef": "warn",
"no-unused-vars": "warn",
"no-redeclare": "warn",
"no-useless-escape": "warn",
"no-mixed-spaces-and-tabs": "warn"
}
}
27 changes: 27 additions & 0 deletions .github/workflows/styling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,30 @@ jobs:
if $failTest; then
exit 1
fi
js_linting:
runs-on: ubuntu-22.04
name: JS
steps:
- uses: actions/checkout@v3

- name: Install npm package
uses: actions/setup-node@v3
with:
node-version: '18'

- name: npm install
run: |
failTest=false
npm install || failTest=true
if $failTest; then
exit 1
fi
- name: Check JS Linting
run: |
failTest=false
npm run lint:js || failTest=true
if $failTest; then
exit 1
fi
11 changes: 8 additions & 3 deletions ccdaservice/oe-blue-button-generate/lib/condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@ exports.isNullFlavorSection = function (key) {
exports.keyExists = function (key) {
let bu = key;
return function (input) {
return input.hasOwnProperty(key);
return Object.prototype.hasOwnProperty.call(input, key);
};
};

exports.keyDoesntExist = function (key) {
return function (input) {
return !input.hasOwnProperty(key);
return !Object.prototype.hasOwnProperty.call(input, key);
};
};

exports.eitherKeyExists = function (key0, key1, key2, key3) {
return function (input) {
return input.hasOwnProperty(key0) || input.hasOwnProperty(key1) || input.hasOwnProperty(key2) || input.hasOwnProperty(key3);
return (
Object.prototype.hasOwnProperty.call(input, key0) ||
Object.prototype.hasOwnProperty.call(input, key1) ||
Object.prototype.hasOwnProperty.call(input, key2) ||
Object.prototype.hasOwnProperty.call(input, key3)
);
};
};

Expand Down
31 changes: 18 additions & 13 deletions ccdaservice/oe-blue-button-generate/lib/headerLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,23 @@ var providers = exports.providers = {
dataKey: "data.demographics"
};

var participants = exports.participant = [{
key: "participant"
, attributes: {
typeCode: leafLevel.inputProperty("typeCode")
}
, content: [
[fieldLevel.effectiveTime, required, key("time")],
// associatedEntity
, fieldLevel.associatedEntity
]
, dataKey: "meta.ccda_header.participants"
}];
var participants = (exports.participant = [
{
key: "participant",
attributes: {
typeCode: leafLevel.inputProperty("typeCode"),
},
// TODO: check if this middle element can be removed
/* eslint-disable-next-line no-sparse-arrays */
content: [
[fieldLevel.effectiveTime, required, key("time")],
,
// associatedEntity
fieldLevel.associatedEntity,
],
dataKey: "meta.ccda_header.participants",
},
]);

var attributed_provider = exports.attributed_provider = {
key: "providerOrganization",
Expand Down Expand Up @@ -599,4 +604,4 @@ var headerComponentOf = exports.headerComponentOf = {
]
},
dataKey: "meta.ccda_header.component_of"
};
};
2 changes: 1 addition & 1 deletion ccdaservice/oe-blue-button-generate/lib/leafLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.docDateProperty = function (key) {

exports.boolInputProperty = function (key) {
return function (input) {
if (input && input.hasOwnProperty(key)) {
if (input && Object.prototype.hasOwnProperty.call(input, key)) {
return input[key].toString();
} else {
return null;
Expand Down
2 changes: 2 additions & 0 deletions ccdaservice/oe-blue-button-meta/lib/oids.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ module.exports = OIDs = {
name: "CPT",
uri: "http:https://purl.bioontology.org/ontology/CPT/"
},
// TODO: check why this property is duplicated
/* eslint-disable-next-line no-dupe-keys */
"2.16.840.1.113883.6.12": {
name: "CPT4",
uri: "http:https://purl.bioontology.org/ontology/CPT/"
Expand Down
4 changes: 2 additions & 2 deletions ccdaservice/oe-blue-button-util/lib/jsonpath/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var processOptions = function (opts) {
return {
resultType: (opts && opts.resultType && opts.resultType.toLowerCase()) || 'value',
flatten: (opts && opts.flatten) || false,
wrap: (opts && opts.hasOwnProperty('wrap')) ? opts.wrap : null,
wrap: (opts && Object.prototype.hasOwnProperty.call(opts, 'wrap')) ? opts.wrap : null,
sandbox: (opts && opts.sandbox) || {},
functions: (opts && opts.functions) || {}
};
Expand Down Expand Up @@ -237,7 +237,7 @@ var Tracer = {
},
traceProperty: function (property, accumulator) {
var obj = accumulator.currentObject();
if (obj && obj.hasOwnProperty(property)) {
if (obj && Object.prototype.hasOwnProperty.call(obj, property)) {
accumulator.add(obj[property], property);
this.traceNext(accumulator);
}
Expand Down
4 changes: 2 additions & 2 deletions ccdaservice/oe-blue-button-util/lib/predicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var hasProperty = exports.hasProperty = function (deepProperty) {
if (typeof input !== 'object') {
return false;
}
if (!input.hasOwnProperty(piece)) {
if (!Object.prototype.hasOwnProperty.call(input, piece)) {
return false;
}
input = input[piece];
Expand All @@ -30,7 +30,7 @@ var hasProperty = exports.hasProperty = function (deepProperty) {
} else {
return function (input) {
if (exists(input) && (typeof input === 'object')) {
return input.hasOwnProperty(deepProperty);
return Object.prototype.hasOwnProperty.call(input, deepProperty);
} else {
return false;
}
Expand Down
52 changes: 30 additions & 22 deletions ccdaservice/serveccda.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function populateTimezones(node, tzOffset, depthCheck) {
return node;
}

if (node.hasOwnProperty('precision') && node.precision == 'tz' && !node.hasOwnProperty('timezoneOffset')) {
if (Object.prototype.hasOwnProperty.call(node, 'precision') && node.precision == 'tz' && !Object.prototype.hasOwnProperty.call(node, 'timezoneOffset')) {
node.timezoneOffset = tzOffset;
} else {
for (const [key, value] of Object.entries(node)) {
Expand Down Expand Up @@ -129,10 +129,7 @@ function fDate(str, lim8 = false) {

let str1 = strDate + ' ' + strTime + '-' + strZone[1];
return str1;
} else {
return str;
}

return str;
}

Expand Down Expand Up @@ -174,13 +171,13 @@ function cleanCode(code) {
function isOne(who) {
try {
if (who !== null && typeof who === 'object') {
return (who.hasOwnProperty('npi')
|| who.hasOwnProperty('code')
|| who.hasOwnProperty('extension')
|| who.hasOwnProperty('id')
|| who.hasOwnProperty('date')
|| who.hasOwnProperty('use')
|| who.hasOwnProperty('type')
return (Object.prototype.hasOwnProperty.call(who, 'npi')
|| Object.prototype.hasOwnProperty.call(who, 'code')
|| Object.prototype.hasOwnProperty.call(who, 'extension')
|| Object.prototype.hasOwnProperty.call(who, 'id')
|| Object.prototype.hasOwnProperty.call(who, 'date')
|| Object.prototype.hasOwnProperty.call(who, 'use')
|| Object.prototype.hasOwnProperty.call(who, 'type')
) ? 1 : Object.keys(who).length;
}
} catch (e) {
Expand Down Expand Up @@ -1587,7 +1584,7 @@ function getPlanOfCare(pd) {

for (let key in all.encounter_list.encounter) {
// skip loop if the property is from prototype
if (!all.encounter_list.encounter.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(all.encounter_list.encounter, key)) {
continue;
}
encounter = all.encounter_list.encounter[key];
Expand Down Expand Up @@ -3276,9 +3273,7 @@ function generateCcda(pd) {
switch (pd.clinical_notes[currentNote].clinical_notes_type) {
case 'evaluation_note':
continue;
break;
case 'progress_note':

break;
case 'history_physical':
pd.clinical_notes[currentNote].code_text = "History and Physical";
Expand Down Expand Up @@ -3442,22 +3437,28 @@ function processConnection(connection) {
if (xml_complete.match(/^<CCDA/g) && xml_complete.match(/<\/CCDA>$/g)) {
let doc = "";
let xslUrl = "";
/* eslint-disable-next-line no-control-regex */
xml_complete = xml_complete.replace(/(\u000b\u001c)/gm, "").trim();
xml_complete = xml_complete.replace(/\t\s+/g, ' ').trim();
xml_complete = xml_complete.replace(/\t\s+/g, " ").trim();
// convert xml data set for document to json array
to_json(xml_complete, function (error, data) {
if (error) {
console.log('toJson error: ' + error + 'Len: ' + xml_complete.length);
return 'ERROR: Failed json build';
console.log(
"toJson error: " + error + "Len: " + xml_complete.length
);
return "ERROR: Failed json build";
}
let unstructured = "";
let isUnstruturedData = !!data.CCDA.patient_files;
// extract unstructured documents file component templates. One per file.
if (isUnstruturedData) {
unstructuredTemplate = xml_complete.substring(xml_complete.lastIndexOf('<patient_files>') + 15, xml_complete.lastIndexOf('</patient_files>'));
unstructuredTemplate = xml_complete.substring(
xml_complete.lastIndexOf("<patient_files>") + 15,
xml_complete.lastIndexOf("</patient_files>")
);
}
// create doc_type document i.e. CCD Referral etc.
if (data.CCDA.doc_type !== 'unstructured') {
if (data.CCDA.doc_type !== "unstructured") {
doc = generateCcda(data.CCDA);
if (data.CCDA.xslUrl) {
xslUrl = data.CCDA.xslUrl || "";
Expand All @@ -3473,22 +3474,29 @@ function processConnection(connection) {
doc += unstructured;
}
// auto build an Unstructured document of supplied embedded files.
if (data.CCDA.doc_type !== 'unstructured' && isUnstruturedData) {
if (
data.CCDA.doc_type !== "unstructured" &&
isUnstruturedData
) {
unstructured = generateUnstructured(data.CCDA);
unstructured = headReplace(unstructured, xslUrl);
// combine the two documents to send back all at once.
doc += unstructured;
}
});
// send results back to eagerly awaiting CCM for disposal.
doc = doc.toString().replace(/(\u000b\u001c|\r)/gm, "").trim();
doc = doc
.toString()
/* eslint-disable-next-line no-control-regex */
.replace(/(\u000b\u001c|\r)/gm, "")
.trim();
let chunk = "";
let numChunks = Math.ceil(doc.length / 1024);
for (let i = 0, o = 0; i < numChunks; ++i, o += 1024) {
chunk = doc.substring(o, o + 1024);
conn.write(chunk);
}
conn.write(String.fromCharCode(28) + "\r\r" + '');
conn.write(String.fromCharCode(28) + "\r\r" + "");
conn.end();
}
}
Expand Down
Loading

0 comments on commit 7de6b61

Please sign in to comment.