Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Commit

Permalink
Naming conventions and linting (#50)
Browse files Browse the repository at this point in the history
* standardize naming conventions - personal

* linting

* standardize naming conventions - expedited

* nameing conventions - name

* standardize naming conventions - conditions

* standardize naming conventions - medications

* remove unused macros

* standardize naming conventions - treatments

* standardize naming conventions - overall health

* standardize naming conventions - documents

* standardize naming conventions - employment

* standardize naming conventions - declaration

* automatic linting fixes

* standardize naming conventions - model/migration
  • Loading branch information
dsamojlenko authored Jan 2, 2020
1 parent 252b204 commit 6f85898
Show file tree
Hide file tree
Showing 47 changed files with 263 additions and 324 deletions.
12 changes: 6 additions & 6 deletions api/controllers/ConfirmationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ module.exports = {
},

store: function (req, res) {
const fs = require('fs')
const data = JSON.stringify(req.session.medicalReport)
const fs = require('fs');
const data = JSON.stringify(req.session.medicalReport);

const filename = Date.now() + '.json'
const filename = Date.now() + '.json';

fs.writeFileSync('sessions/' + filename, data)
req.session.medicalReport = {};
fs.writeFileSync('sessions/' + filename, data);
req.session.medicalReport = {};

res.redirect(sails.route('start'));
res.redirect(sails.route('start'));
}
};
6 changes: 3 additions & 3 deletions api/controllers/DeclarationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ module.exports = {

if (valid) {
// save the model
req.session.medicalReport.i_am_a = req.body.i_am_a;
req.session.medicalReport.other_specify = req.body.other_specify;
req.session.medicalReport.practitionerType = req.body.practitionerType;
req.session.medicalReport.otherSpecify = req.body.otherSpecify;
req.session.medicalReport.name = req.body.name;
req.session.medicalReport.date = req.body.date;
req.session.medicalReport.physician_address = req.body.physician_address;
req.session.medicalReport.physicianAddress = req.body.physicianAddress;

res.redirect(sails.route('confirmation'));
}
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/DocumentsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {

if (valid) {
// save the model
req.session.medicalReport.supporting_documents = req.body.supporting_documents;
req.session.medicalReport.supportingDocuments = req.body.supportingDocuments;
res.redirect(sails.route('employment'));
}
}
Expand Down
14 changes: 7 additions & 7 deletions api/controllers/EmploymentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ module.exports = {
data: data
});
},

store: function (req, res) {
let valid = req.validate(req, res, require('../schemas/employment.schema'));

if (valid) {
// save the model
req.session.medicalReport.stop_work = req.body.stop_work;
req.session.medicalReport.date_stopped_work = req.body.date_stopped_work;
req.session.medicalReport.return_to_work = req.body.return_to_work;
req.session.medicalReport.return_to_work_timeframe = req.body.return_to_work_timeframe;
req.session.medicalReport.type_of_work = req.body.type_of_work;
req.session.medicalReport.type_of_work_other = req.body.type_of_work_other;
req.session.medicalReport.stopWork = req.body.stopWork;
req.session.medicalReport.dateStoppedWork = req.body.dateStoppedWork;
req.session.medicalReport.returnToWork = req.body.returnToWork;
req.session.medicalReport.returnToWorkTimeframe = req.body.returnToWorkTimeframe;
req.session.medicalReport.typeOfWork = req.body.typeOfWork;
req.session.medicalReport.typeOfWorkOther = req.body.typeOfWorkOther;

res.redirect(sails.route('declaration'));
}
Expand Down
6 changes: 3 additions & 3 deletions api/controllers/ExpeditedController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ module.exports = {

if (valid) {
// save the model
req.session.medicalReport.condition_type = req.body.condition_type;
req.session.medicalReport.conditionType = req.body.conditionType;
req.session.medicalReport.diagnosis = req.body.diagnosis;
req.session.medicalReport.icd_code = req.body.icd_code;
req.session.medicalReport.onset_date = req.body.onset_date;
req.session.medicalReport.icdCode = req.body.icdCode;
req.session.medicalReport.onsetDate = req.body.onsetDate;

res.redirect(sails.route('conditions'));
}
Expand Down
3 changes: 1 addition & 2 deletions api/controllers/HealthController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ module.exports = {

if (valid) {
// save the model
req.session.medicalReport.overall_health = req.body.overall_health;
req.session.medicalReport.overallHealth = req.body.overallHealth;
res.redirect(sails.route('documents'));
}
}

};
2 changes: 1 addition & 1 deletion api/controllers/MedicationsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
index: function (req, res) {
if (!_.has(req.session.medicalReport, 'medications')) {
return res.redirect(sails.route('medications.add'));
}
}

res.view('pages/medications/index', {
data: req.session.medicalReport
Expand Down
2 changes: 1 addition & 1 deletion api/hooks/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ module.exports = sails => {
}
});
},
}
};
};
16 changes: 8 additions & 8 deletions api/models/MedicalReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ module.exports = {

sin: Sequelize.STRING,
title: Sequelize.STRING,
first_name: Sequelize.STRING,
middle_name: Sequelize.STRING,
last_name: Sequelize.STRING,
last_name_at_birth: Sequelize.STRING,
birth_date: Sequelize.DATEONLY,
firstName: Sequelize.STRING,
middleName: Sequelize.STRING,
lastName: Sequelize.STRING,
lastNameAtBirth: Sequelize.STRING,
birthDate: Sequelize.DATEONLY,
address: Sequelize.STRING,
telephone_number: Sequelize.STRING,
alt_telephone_number: Sequelize.STRING,
contact_period: Sequelize.ENUM('morning','afternoon','letters_only'),
telephoneNumber: Sequelize.STRING,
altTelephoneNumber: Sequelize.STRING,
contactPeriod: Sequelize.ENUM('morning','afternoon','letters_only'),
},
options: {
tableName: 'MedicalReports'
Expand Down
2 changes: 1 addition & 1 deletion api/policies/reportExists.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ module.exports = function (req, res, next) {
return res.redirect(sails.route('start'));
}
next();
}
};
16 changes: 8 additions & 8 deletions api/policies/route.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
/**
* This policy/middleware creates a route helper on the sails object and makes it available
* on res.locals for use in templates. The helper accepts a route name and returns a
* on res.locals for use in templates. The helper accepts a route name and returns a
* locale-specific path for the named route. The helper will accept an optional param
* to force the language of the path to be returned.
*/

module.exports = function (req, res, next) {
sails.route = (routeName, params = {}) => {
let lang = req.getLocale();

// use optional lang param if passed
if (_.has(params, 'lang')) {
lang = params.lang;
lang = params.lang;
}

// get i18n routes
const routes = sails.router.namedRoutes[routeName];

if (!routes) {
throw new Error('No named route : ' + routeName + '\n Maybe you missed the name property?');
throw new Error('No named route : ' + routeName + '\n Maybe you missed the name property?');
}

// get localized route
let route = routes[lang];

if (!route) {
throw new Error('No named route : ' + routeName + '\n in that language. Maybe you mistyped the lang property?');
throw new Error('No named route : ' + routeName + '\n in that language. Maybe you mistyped the lang property?');
}

// map any passed-in params to placeholders in the route path
if (!_.isEmpty(params)) {
Object.keys(params).forEach((key, index) => {
Object.keys(params).forEach((key, index) => {
route = route.replace(':' + key, params[key]);
});
});
}

return route;
};

res.locals.route = sails.route;

next();
Expand Down
28 changes: 14 additions & 14 deletions api/schemas/condition.schema.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
module.exports = {
name_of_condition: {
conditionName: {
presence: {
allowEmpty: false,
message: '^errors.name_of_condition.length'
}
},
symptoms_began: {
symptomsBegan: {
presence: {
allowEmpty: false,
message: '^errors.symptoms_began.length'
}
},
clinically_impair: {
clinicallyImpair: {
presence: {
allowEmpty: false,
message: '^errors.clinically_impair'
}
},
condition_outlook: {
conditionOutlook: {
presence: {
message: '^errors.condition_outlook_required'
}
},
condition_outlook_unknown: function (value, attributes) {
const condition_outlook = attributes.condition_outlook;
if (condition_outlook && condition_outlook === '4') {
conditionOutlookUnknown: function (value, attributes) {
const conditionOutlook = attributes.conditionOutlook;
if (conditionOutlook && conditionOutlook === '4') {
return {
presence: {
allowEmpty: false,
message: '^errors.condition_outlook_unknown'
}
}
};
}
},
condition_last: {
conditionLast: {
presence: {
message: '^errors.condition_last_required'
}
// also validate options
},
symptoms_occur: {
symptomsOccur: {
presence: {
message: '^errors.symptoms_occur_required'
}
},
symptoms_occur_unknown: function (value, attributes) {
const symptoms_occur = attributes.symptoms_occur;
if (symptoms_occur && symptoms_occur === '3') {
symptomsOccurUnknown: function (value, attributes) {
const symptomsOccur = attributes.symptomsOccur;
if (symptomsOccur && symptomsOccur === '3') {
return {
presence: {
allowEmpty: false,
message: '^errors.symptoms_occur_unknown_required'
}
}
};
}
}
};
4 changes: 2 additions & 2 deletions api/schemas/consent.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
message: '^Signature is Required if you Consent',
allowEmpty: false
}
}
};
}
},
}
};
40 changes: 20 additions & 20 deletions api/schemas/declaration.schema.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module.exports = {
i_am_a: {
practitionerType: {
presence: {
message: '^I am a is required',
allowEmpty: false,
},
},
other_specify: function (value, attributes) {
const i_am_a = attributes.i_am_a;
if (i_am_a === 'other') {
otherSpecify: function (value, attributes) {
const practitionerType = attributes.practitionerType;
if (practitionerType === 'other') {
return {
presence: {
message: '^Other is required if Other is selected',
allowEmpty: false
}
}
};
}
},
name: {
Expand All @@ -24,26 +24,26 @@ module.exports = {
},
date: function (value) {
if (value) {
return {
validateDateFormat: {
message: '^Date is not formatted correctly'
},
validateDateExists: {
message: '^Date is not a valid date'
}
}
}
return {
presence: {
allowEmpty: false,
message: '^Date is required'
validateDateFormat: {
message: '^Date is not formatted correctly'
},
}
validateDateExists: {
message: '^Date is not a valid date'
}
};
}
return {
presence: {
allowEmpty: false,
message: '^Date is required'
},
};
},
physician_address: {
physicianAddress: {
presence: {
message: '^Address is required',
allowEmpty: false,
},
}
}
};
4 changes: 2 additions & 2 deletions api/schemas/documents.schema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
supporting_documents: function (value, attributes) {
const attachLater = attributes.attach_later;
supportingDocuments: function (value, attributes) {
const attachLater = attributes.attachLater;
if (!attachLater) {
return {
presence: {
Expand Down
Loading

0 comments on commit 6f85898

Please sign in to comment.