From 20f5530cbc1e461090ba4d800c463ec47cddf791 Mon Sep 17 00:00:00 2001 From: zeevosec Date: Tue, 29 Sep 2020 10:58:58 -0400 Subject: [PATCH] chore(prettier): run prettier --- .../src/server/metadata/capability.1_0_2.js | 28 ++++---- .../src/server/metadata/capability.3_0_1.js | 28 ++++---- .../src/server/metadata/capability.4_0_0.js | 28 ++++---- .../src/server/metadata/metadata.config.js | 6 +- .../server/metadata/metadata.controller.js | 6 +- .../src/server/metadata/metadata.service.js | 22 +++---- .../src/server/metadata/metadata.test.js | 65 +++++++++---------- .../src/server/router.test.js | 30 ++++----- 8 files changed, 101 insertions(+), 112 deletions(-) diff --git a/packages/node-fhir-server-core/src/server/metadata/capability.1_0_2.js b/packages/node-fhir-server-core/src/server/metadata/capability.1_0_2.js index c4e0efaaa..68e194d59 100644 --- a/packages/node-fhir-server-core/src/server/metadata/capability.1_0_2.js +++ b/packages/node-fhir-server-core/src/server/metadata/capability.1_0_2.js @@ -8,27 +8,25 @@ let getConformanceResource = () => { return resolveSchema('1_0_2', 'conformance'); }; -module.exports.makeStatement = function(resources) { +module.exports.makeStatement = function (resources) { let Conformance = getConformanceResource(); return new Conformance({ status: 'active', - date: moment() - .tz('America/New_York') - .format(), + date: moment().tz('America/New_York').format(), publisher: 'Not provided', kind: 'instance', software: { name: 'FHIR Server', - version: '1.4.0' + version: '1.4.0', }, implementation: { - description: 'FHIR Test Server (DSTU2)' + description: 'FHIR Test Server (DSTU2)', }, fhirVersion: '1.0.2', acceptUnknown: 'extensions', format: ['application/json+fhir'], - rest: [resources] + rest: [resources], }); }; @@ -36,23 +34,23 @@ module.exports.makeStatement = function(resources) { * @name exports * @summary Capability statement shell */ -module.exports.securityStatement = securityUrls => ({ +module.exports.securityStatement = (securityUrls) => ({ cors: true, service: [ { coding: [ { system: 'http://hl7.org/fhir/restful-security-service', - code: 'SMART-on-FHIR' - } + code: 'SMART-on-FHIR', + }, ], - text: 'Custom OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)' - } + text: 'Custom OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)', + }, ], extension: [ { url: 'http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris', - extension: securityUrls - } - ] + extension: securityUrls, + }, + ], }); diff --git a/packages/node-fhir-server-core/src/server/metadata/capability.3_0_1.js b/packages/node-fhir-server-core/src/server/metadata/capability.3_0_1.js index 2d397b1c4..409808d52 100644 --- a/packages/node-fhir-server-core/src/server/metadata/capability.3_0_1.js +++ b/packages/node-fhir-server-core/src/server/metadata/capability.3_0_1.js @@ -8,27 +8,25 @@ let getCapabilityStatementResource = () => { return resolveSchema('3_0_1', 'capabilitystatement'); }; -module.exports.makeStatement = function(resources) { +module.exports.makeStatement = function (resources) { let CapabilityStatement = getCapabilityStatementResource(); return new CapabilityStatement({ status: 'active', - date: moment() - .tz('America/New_York') - .format(), + date: moment().tz('America/New_York').format(), publisher: 'Not provided', kind: 'instance', software: { name: 'FHIR Server', - version: '1.4.0' + version: '1.4.0', }, implementation: { - description: 'FHIR Test Server (STU3)' + description: 'FHIR Test Server (STU3)', }, fhirVersion: '3.0.1', acceptUnknown: 'extensions', format: ['application/fhir+json'], - rest: [resources] + rest: [resources], }); }; @@ -36,23 +34,23 @@ module.exports.makeStatement = function(resources) { * @name exports * @summary Capability statement shell */ -module.exports.securityStatement = securityUrls => ({ +module.exports.securityStatement = (securityUrls) => ({ cors: true, service: [ { coding: [ { system: 'http://hl7.org/fhir/restful-security-service', - code: 'SMART-on-FHIR' - } + code: 'SMART-on-FHIR', + }, ], - text: 'OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)' - } + text: 'OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)', + }, ], extension: [ { url: 'http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris', - extension: securityUrls - } - ] + extension: securityUrls, + }, + ], }); diff --git a/packages/node-fhir-server-core/src/server/metadata/capability.4_0_0.js b/packages/node-fhir-server-core/src/server/metadata/capability.4_0_0.js index 1c2738b41..0a2977c5e 100644 --- a/packages/node-fhir-server-core/src/server/metadata/capability.4_0_0.js +++ b/packages/node-fhir-server-core/src/server/metadata/capability.4_0_0.js @@ -8,27 +8,25 @@ let getCapabilityStatementResource = () => { return resolveSchema('4_0_0', 'capabilitystatement'); }; -module.exports.makeStatement = function(resources) { +module.exports.makeStatement = function (resources) { let CapabilityStatement = getCapabilityStatementResource(); return new CapabilityStatement({ status: 'active', - date: moment() - .tz('America/New_York') - .format(), + date: moment().tz('America/New_York').format(), publisher: 'Not provided', kind: 'instance', software: { name: 'FHIR Server', - version: '1.4.0' + version: '1.4.0', }, implementation: { - description: 'FHIR Test Server (R4)' + description: 'FHIR Test Server (R4)', }, fhirVersion: '4.0.0', acceptUnknown: 'extensions', format: ['application/fhir+json'], - rest: [resources] + rest: [resources], }); }; @@ -36,23 +34,23 @@ module.exports.makeStatement = function(resources) { * @name exports * @summary Capability statement shell */ -module.exports.securityStatement = securityUrls => ({ +module.exports.securityStatement = (securityUrls) => ({ cors: true, service: [ { coding: [ { system: 'http://hl7.org/fhir/restful-security-service', - code: 'SMART-on-FHIR' - } + code: 'SMART-on-FHIR', + }, ], - text: 'Custom OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)' - } + text: 'Custom OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)', + }, ], extension: [ { url: 'http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris', - extension: securityUrls - } - ] + extension: securityUrls, + }, + ], }); diff --git a/packages/node-fhir-server-core/src/server/metadata/metadata.config.js b/packages/node-fhir-server-core/src/server/metadata/metadata.config.js index 3f929f8aa..f923c35db 100644 --- a/packages/node-fhir-server-core/src/server/metadata/metadata.config.js +++ b/packages/node-fhir-server-core/src/server/metadata/metadata.config.js @@ -4,10 +4,10 @@ const { routeArgs: routeArgs } = require('../route.config.js'); let route = { path: '/:base_version/metadata', corsOptions: { - methods: ['GET'] + methods: ['GET'], }, args: [routeArgs.BASE], - controller: controller.getCapabilityStatement + controller: controller.getCapabilityStatement, }; /** @@ -15,5 +15,5 @@ let route = { * @summary Metadata config */ module.exports = { - route + route, }; diff --git a/packages/node-fhir-server-core/src/server/metadata/metadata.controller.js b/packages/node-fhir-server-core/src/server/metadata/metadata.controller.js index 0dc7d38cc..67fe98c41 100644 --- a/packages/node-fhir-server-core/src/server/metadata/metadata.controller.js +++ b/packages/node-fhir-server-core/src/server/metadata/metadata.controller.js @@ -15,9 +15,9 @@ module.exports.getCapabilityStatement = ({ profiles, security, statementGenerato fhirVersion: fhirVersion || VERSIONS['4_0_0'], profiles, security, - statementGenerator + statementGenerator, }) - .then(statement => res.status(200).json(statement)) - .catch(err => next(err)); + .then((statement) => res.status(200).json(statement)) + .catch((err) => next(err)); }; }; diff --git a/packages/node-fhir-server-core/src/server/metadata/metadata.service.js b/packages/node-fhir-server-core/src/server/metadata/metadata.service.js index e62bb9b62..fb5eb711d 100644 --- a/packages/node-fhir-server-core/src/server/metadata/metadata.service.js +++ b/packages/node-fhir-server-core/src/server/metadata/metadata.service.js @@ -9,7 +9,7 @@ let logger = container.get('default'); /** * Load the correct statement generators for the right version */ -let getStatementGenerators = base_version => { +let getStatementGenerators = (base_version) => { if (base_version) { return require(`./capability.${base_version}`); } else { @@ -29,7 +29,7 @@ let generateCapabilityStatement = ({ fhirVersion, profiles, security, - statementGenerator = getStatementGenerators + statementGenerator = getStatementGenerators, }) => new Promise((resolve, reject) => { logger.info('Metadata.generateCapabilityStatement'); @@ -37,16 +37,16 @@ let generateCapabilityStatement = ({ // create profile list let keys = Object.keys(profiles); let active_profiles = keys - .map(profile_name => { + .map((profile_name) => { return { key: profile_name, makeResource: conformanceTemplate.resource, versions: profiles[profile_name] && profiles[profile_name].versions, service: profiles[profile_name] && profiles[profile_name].serviceModule, - metadata: profiles[profile_name] && profiles[profile_name].metadata + metadata: profiles[profile_name] && profiles[profile_name].metadata, }; }) - .filter(profile => profile.versions.indexOf(fhirVersion) !== -1); + .filter((profile) => profile.versions.indexOf(fhirVersion) !== -1); // TODO: REMOVE: Logger deprecatedLogger let deprecatedLogger = deprecate( @@ -65,7 +65,7 @@ let generateCapabilityStatement = ({ // Let's start building our confromance/capability statement const serverStatement = { - mode: 'server' + mode: 'server', }; // Add security information if available @@ -77,14 +77,14 @@ let generateCapabilityStatement = ({ let operations = keys.reduce((ops, profile_name) => { const opsInProfile = profiles[profile_name].operation; if (opsInProfile && opsInProfile.length) { - opsInProfile.forEach(opInProfile => { + opsInProfile.forEach((opInProfile) => { const op = { name: opInProfile.name, definition: { reference: opInProfile.reference ? opInProfile.reference - : `/OperationOutcome/${opInProfile.name}` - } + : `/OperationOutcome/${opInProfile.name}`, + }, }; ops.push(op); }); @@ -99,7 +99,7 @@ let generateCapabilityStatement = ({ // Make the resource and give it the version so it can only include valid search params let customMakeResource = null; - serverStatement.resource = active_profiles.map(profile => { + serverStatement.resource = active_profiles.map((profile) => { if (profile.metadata) { customMakeResource = require(profile.metadata).makeResource; } else { @@ -122,5 +122,5 @@ let generateCapabilityStatement = ({ * @summary Metadata service */ module.exports = { - generateCapabilityStatement + generateCapabilityStatement, }; diff --git a/packages/node-fhir-server-core/src/server/metadata/metadata.test.js b/packages/node-fhir-server-core/src/server/metadata/metadata.test.js index a423883c8..bb76c849c 100644 --- a/packages/node-fhir-server-core/src/server/metadata/metadata.test.js +++ b/packages/node-fhir-server-core/src/server/metadata/metadata.test.js @@ -10,84 +10,79 @@ let server; // Helper function to replace express params with mock values let fillRoute = (route, key) => - route - .replace(':base_version', VERSIONS['3_0_1']) - .replace(':id', 1) - .replace(':resource', key); + route.replace(':base_version', VERSIONS['3_0_1']).replace(':id', 1).replace(':resource', key); //Helper function build a custom security statement -const customSecurityStatement = securityUrls => ({ +const customSecurityStatement = (securityUrls) => ({ cors: true, service: [ { coding: [ { system: 'http://hl7.org/fhir/restful-security-service', - code: 'SMART-on-FHIR' - } + code: 'SMART-on-FHIR', + }, ], - text: 'Custom OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)' - } + text: 'Custom OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)', + }, ], extension: [ { url: 'http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris', - extension: securityUrls - } - ] + extension: securityUrls, + }, + ], }); // Helper function to build a custom capability statement -const customCapabilityStatement = function(resources) { +const customCapabilityStatement = function (resources) { let CapabilityStatement = resolveSchema('3_0_1', 'CapabilityStatement'); return new CapabilityStatement({ status: 'active', - date: moment() - .tz('America/New_York') - .format(), + date: moment().tz('America/New_York').format(), publisher: 'Not provided', kind: 'instance', software: { name: 'FHIR Server', - version: '0.0.1' + version: '0.0.1', }, implementation: { - description: 'FHIR Custom Server (STU3)' + description: 'FHIR Custom Server (STU3)', }, fhirVersion: '3.0.1', acceptUnknown: 'extensions', format: ['application/fhir+json'], - rest: [resources] + rest: [resources], }); }; //A custom statementGenerator getter -let customGetStatementGenerators = args => { +let customGetStatementGenerators = (args) => { return { makeStatement: customCapabilityStatement, - securityStatement: customSecurityStatement + securityStatement: customSecurityStatement, }; }; //A function to make a custom resource conformance statement -let customMakeResource = args => { +let customMakeResource = (args) => { let Resource = resolveSchema(args.base_version, args.key); // Return our conformance statement return { type: Resource.resourceType, profile: { - reference: `http://example.org/fhir/${args.key}.html` + reference: `http://example.org/fhir/${args.key}.html`, }, conditionalDelete: 'not-supported', searchParam: [ { name: '_id', type: 'token', - documentation: 'The ID of the resource' - } - ] + documentation: 'The ID of the resource', + }, + ], }; }; @@ -111,12 +106,12 @@ describe('Conformance Tests', () => { config.security = [ { url: 'authorize', - valueUri: 'https://afternoon-springs-39948.herokuapp.com/authorize' + valueUri: 'https://afternoon-springs-39948.herokuapp.com/authorize', }, { url: 'token', - valueUri: 'https://afternoon-springs-39948.herokuapp.com/token' - } + valueUri: 'https://afternoon-springs-39948.herokuapp.com/token', + }, ]; server = new Server(config).setProfileRoutes().setErrorRoutes(); @@ -138,12 +133,12 @@ describe('Conformance Tests', () => { config.security = [ { url: 'authorize', - valueUri: 'https://afternoon-springs-39948.herokuapp.com/authorize' + valueUri: 'https://afternoon-springs-39948.herokuapp.com/authorize', }, { url: 'token', - valueUri: 'https://afternoon-springs-39948.herokuapp.com/token' - } + valueUri: 'https://afternoon-springs-39948.herokuapp.com/token', + }, ]; config.statementGenerator = customGetStatementGenerators; server = new Server(config).setProfileRoutes().setErrorRoutes(); @@ -186,7 +181,7 @@ describe('Conformance Tests', () => { expect(response.body.resourceType).toBe('CapabilityStatement'); //Check that the reference for each resource is the default for (let key of keys) { - let resource = response.body.rest[0].resource.find(rsc => rsc.type === key); + let resource = response.body.rest[0].resource.find((rsc) => rsc.type === key); expect(resource.profile.reference).toBe(`http://hl7.org/fhir/${key}.html`); } }, 60000); @@ -210,7 +205,7 @@ describe('Conformance Tests', () => { expect(response.body.resourceType).toBe('CapabilityStatement'); //Check the reference for each resource is the customised one for (let key of keys) { - let account_resource = response.body.rest[0].resource.find(rsc => { + let account_resource = response.body.rest[0].resource.find((rsc) => { return rsc.type === key; }); expect(account_resource.profile.reference).toBe(`http://example.org/fhir/${key}.html`); @@ -237,7 +232,7 @@ describe('Conformance Tests', () => { expect(response.body.resourceType).toBe('CapabilityStatement'); //Check the reference for each resource is the customised one for (let key of keys) { - let account_resource = response.body.rest[0].resource.find(rsc => rsc.type === 'Foobar'); + let account_resource = response.body.rest[0].resource.find((rsc) => rsc.type === 'Foobar'); expect(account_resource.profile.reference).toBe( `https://fhir.hl7.org.uk/STU3/StructureDefinition/CareConnect-Patient-1` ); diff --git a/packages/node-fhir-server-core/src/server/router.test.js b/packages/node-fhir-server-core/src/server/router.test.js index 79cc3a723..b473526dc 100644 --- a/packages/node-fhir-server-core/src/server/router.test.js +++ b/packages/node-fhir-server-core/src/server/router.test.js @@ -10,15 +10,15 @@ let app, config; let mockServiceModule = { search: () => Promise.resolve(), - aggregateResults: () => Promise.resolve() + aggregateResults: () => Promise.resolve(), }; let mockOperationConfig = [ { name: 'aggregate-results', route: '/$aggregate-results', - method: 'POST' - } + method: 'POST', + }, ]; describe('Router Tests', () => { @@ -26,16 +26,16 @@ describe('Router Tests', () => { app = { get: jest.fn(), post: jest.fn(), - options: jest.fn() + options: jest.fn(), }; config = { server: {}, profiles: { patient: { service: path.resolve('./src/server/profiles/service.mock.js'), - versions: ['4_0_0'] - } - } + versions: ['4_0_0'], + }, + }, }; }); @@ -43,7 +43,7 @@ describe('Router Tests', () => { // Add another version via a different route config.profiles.observation = { service: path.resolve('./src/server/profiles/service.mock.js'), - versions: ['4_0_0'] + versions: ['4_0_0'], }; // Run the router with some defaults router.setRoutes({ app, config }); @@ -62,7 +62,7 @@ describe('Router Tests', () => { config.profiles.observation = { service: path.resolve('./src/server/profiles/service.mock.js'), versions: ['4_0_0'], - baseUrls: ['/'] + baseUrls: ['/'], }; // Run the router with some defaults router.setRoutes({ app, config }); @@ -119,8 +119,8 @@ describe('Router Tests', () => { config.profiles.patient.operation = [ { name: 'foo-bar', - route: '/$foo-bar' - } + route: '/$foo-bar', + }, ]; expect(() => { router.setRoutes({ app, config }); @@ -130,8 +130,8 @@ describe('Router Tests', () => { { name: 'foo-bar', route: '/$foo-bar', - method: 'POST' - } + method: 'POST', + }, ]; expect(() => { router.setRoutes({ app, config }); @@ -170,8 +170,8 @@ describe('Router Tests', () => { config.auth = { strategy: { name: 'test', - useSession: true - } + useSession: true, + }, }; config.profiles.patient.serviceModule = mockServiceModule; config.profiles.patient.operation = mockOperationConfig;