From fb4c6659f6f9df4684edf88cef400d6dbc2b3a87 Mon Sep 17 00:00:00 2001 From: Joe Jean Date: Fri, 7 Jul 2023 16:10:53 +0400 Subject: [PATCH] Revert "MIG-171 - Fixed ECBuilderMap and script" --- .../__tests__/MIG-148/MIG-148.test.js | 45 ++------------ .../__tests__/MIG-154/MIG-154.test.js | 5 -- .../__tests__/MIG-63/MIG-63.test.js | 42 +++++++++----- .../__tests__/TOOLS-42/TOOLS-42.test.js | 2 +- .../lib/StudyManifestTools.js | 5 +- .../mdctl-axon-tools/lib/mappings/index.js | 39 ++----------- .../lib/mappings/maps/EcBuilderDataMap.js | 58 +++++++++++-------- .../lib/mappings/maps/index.js | 4 +- 8 files changed, 78 insertions(+), 122 deletions(-) diff --git a/packages/mdctl-axon-tools/__tests__/MIG-148/MIG-148.test.js b/packages/mdctl-axon-tools/__tests__/MIG-148/MIG-148.test.js index 52fa9937..11d2dc29 100644 --- a/packages/mdctl-axon-tools/__tests__/MIG-148/MIG-148.test.js +++ b/packages/mdctl-axon-tools/__tests__/MIG-148/MIG-148.test.js @@ -199,7 +199,7 @@ describe('MIG-148 - Test StudyManifestTools ', () => { paths: () => ({ limit: () => ({ toArray: () => existingStudy - }), + }) }) }) }, @@ -212,26 +212,23 @@ describe('MIG-148 - Test StudyManifestTools ', () => { }, ec__document_templates: { find: () => ({ - limit: () => ({ - paths: () => ({ - toArray: () => ([ecDocTemplate]) - }) + paths: () => ({ + toArray: () => ([ecDocTemplate]) }) }) } } }, installAfterScript = ` - import _ from 'lodash' const { run } = require('expressions') - const mappings = [{"path":"ec__document_template.8c16e1ad-f3b4-41c8-a6fb-a68d1d28f188.ec__builder_data","mapTo":{"$let":{"vars":{"originalTemplate":{"$dbNext":{"object":"ec__document_template","operation":"cursor","where":{"ec__key":"8c16e1ad-f3b4-41c8-a6fb-a68d1d28f188"},"expand":["ec__knowledge_checks"],"passive":true}}},"in":{"$object":{"ck-widgets-data":{"$concatArrays":[{"$map":{"input":"$$originalTemplate.ec__requested_signatures","as":"entry","in":{"$object":{"ec__key":"$$entry.ec__key","_id":"$$entry._id"}}}},{"$map":{"input":"$$originalTemplate.ec__knowledge_checks.data","as":"entry","in":{"$object":{"ec__key":"$$entry.ec__key","_id":"$$entry._id"}}}},{"$map":{"input":"$$originalTemplate.ec__requested_data","as":"entry","in":{"$object":{"ec__key":"$$entry.ec__key","_id":"$$entry._id"}}}}]}}}}}}] + const mappings = [{"path":"ec__document_template.8c16e1ad-f3b4-41c8-a6fb-a68d1d28f188.ec__builder_data","mapTo":{"$let":{"vars":{"originalTemplate":{"$dbNext":{"object":"ec__document_template","operation":"cursor","where":{"ec__key":"8c16e1ad-f3b4-41c8-a6fb-a68d1d28f188"},"expand":["ec__knowledge_checks"],"passive":true}}},"in":{"$object":{"ck-widgets-data":{"$concatArrays":[{"$map":{"input":"$$originalTemplate.ec__requested_signatures","as":"entry","in":{"$object":{"data":"$$entry","id":"$$entry.ec__key","type":{"$literal":"signature"}}}}},{"$map":{"input":"$$originalTemplate.ec__knowledge_checks.data","as":"entry","in":{"$object":{"data":"$$entry","id":"$$entry.ec__key","type":{"$literal":"knowledgeCheck"}}}}},{"$map":{"input":"$$originalTemplate.ec__requested_data","as":"entry","in":{"$object":{"data":"$$entry","id":"$$entry.ec__key","type":{"$cond":["$$entry.ec__allow_multiple",{"$literal":"checkboxGroup"},{"$cond":[{"$eq":["$$entry.ec__allow_multiple",false]},{"$literal":"radioGroup"},{"$literal":"input"}]}]}}}}}]}}}}}}] mappings.forEach(({ path, mapTo }) => { const [entity, entityKey, property, ...rest] = path.split('.'), - isDocPropUpdate = !!rest.length - let value = run(mapTo) + isDocPropUpdate = !!rest.length, + value = run(mapTo) const prop = entity.startsWith('ec__') ? 'ec__key' : 'c_key' @@ -262,36 +259,6 @@ describe('MIG-148 - Test StudyManifestTools ', () => { } - if (entity === 'ec__document_template' && prop === 'ec__key' && property === 'ec__builder_data') { - - const idMapping = _.keyBy(value['ck-widgets-data'], 'ec__key') - const { - _id: template_id, - ec__builder_data: { "ck-widgets-data": originalBuilderData }, - ec__status, creator, owner, updater - } = org.objects.ec__document_templates.find({ ec__key: entityKey }) - .paths('ec__builder_data', 'ec__status', 'creator', 'owner', 'updater') - .next() - - //We can update only draft templates - if (ec__status !== 'draft') { - return - } - - //Map ids between builder_data and corresponding entities - let new_builder_data = originalBuilderData.map((obd) => { - const updatedId = _.get(idMapping, obd.id + '._id') - _.set(obd, 'data._id', updatedId) - _.get(obd, 'data.ec__document_template._id', false) && _.set(obd, 'data.ec__document_template._id', template_id) - _.get(obd, 'data.ec__document_template.path', false) && _.set(obd, 'data.ec__document_template.path', '/ec__document_templates/' + template_id) - _.get(obd, 'data.creator', false) && _.set(obd, 'data.creator', creator) - _.get(obd, 'data.owner', false) && _.set(obd, 'data.owner', owner) - _.get(obd, 'data.updater', false) && _.set(obd, 'data.updater', updater) - return obd - }) - value = { "ck-widgets-data": new_builder_data } - } - //normal prop update return org.objects[entity] .updateOne({ [prop]: entityKey }, { $set: { [property]: value }}) diff --git a/packages/mdctl-axon-tools/__tests__/MIG-154/MIG-154.test.js b/packages/mdctl-axon-tools/__tests__/MIG-154/MIG-154.test.js index 6a487d96..ced98710 100644 --- a/packages/mdctl-axon-tools/__tests__/MIG-154/MIG-154.test.js +++ b/packages/mdctl-axon-tools/__tests__/MIG-154/MIG-154.test.js @@ -1,10 +1,5 @@ - describe('MIG-154 - Check new methods', () => { - afterEach(() => { - jest.clearAllMocks() - }) - beforeEach(() => { /* Resets the module registry - the cache of all required modules diff --git a/packages/mdctl-axon-tools/__tests__/MIG-63/MIG-63.test.js b/packages/mdctl-axon-tools/__tests__/MIG-63/MIG-63.test.js index 65254231..fd20c230 100644 --- a/packages/mdctl-axon-tools/__tests__/MIG-63/MIG-63.test.js +++ b/packages/mdctl-axon-tools/__tests__/MIG-63/MIG-63.test.js @@ -483,10 +483,8 @@ const MenuConfigMap = require('../../lib/mappings/maps/MenuConfigMap'), }, ec__document_templates: { find: () => ({ - limit: () => ({ - paths: () => ({ - toArray: () => ([ecDocTemplate]) - }) + paths: () => ({ + toArray: () => ([ecDocTemplate]) }) }) } @@ -495,10 +493,6 @@ const MenuConfigMap = require('../../lib/mappings/maps/MenuConfigMap'), describe('Export Mappings', () => { - afterEach(() => { - jest.clearAllMocks() - }) - it('menuConfigMapping', async() => { const menuConfigMapping = new MenuConfigMap(org), mappings = await menuConfigMapping.getMappings() @@ -676,8 +670,11 @@ describe('MIG-126: econsentDocumentTemplateAdjustments', () => { as: 'entry', in: { $object: { - _id: '$$entry._id', - ec__key: '$$entry.ec__key' + data: '$$entry', + id: '$$entry.ec__key', + type: { + $literal: 'signature' + } } } } @@ -687,8 +684,11 @@ describe('MIG-126: econsentDocumentTemplateAdjustments', () => { as: 'entry', in: { $object: { - _id: '$$entry._id', - ec__key: '$$entry.ec__key' + data: '$$entry', + id: '$$entry.ec__key', + type: { + $literal: 'knowledgeCheck' + } } } } @@ -698,8 +698,22 @@ describe('MIG-126: econsentDocumentTemplateAdjustments', () => { as: 'entry', in: { $object: { - _id: '$$entry._id', - ec__key: '$$entry.ec__key' + data: '$$entry', + id: '$$entry.ec__key', + type: { + $cond: [ + '$$entry.ec__allow_multiple', { + $literal: 'checkboxGroup' + }, { + $cond: [{ + $eq: ['$$entry.ec__allow_multiple', false] + }, { + $literal: 'radioGroup' + }, { + $literal: 'input' + }] + }] + } } } } diff --git a/packages/mdctl-axon-tools/__tests__/TOOLS-42/TOOLS-42.test.js b/packages/mdctl-axon-tools/__tests__/TOOLS-42/TOOLS-42.test.js index ff654b30..eb51513f 100644 --- a/packages/mdctl-axon-tools/__tests__/TOOLS-42/TOOLS-42.test.js +++ b/packages/mdctl-axon-tools/__tests__/TOOLS-42/TOOLS-42.test.js @@ -218,7 +218,7 @@ describe('StudyManifestTools', () => { [ 'consent', { - object: 'package', name: 'Consent export', version: '0.0.1', description: 'An export of consent template or multiple consent templates', pipes: { ingest: 'ingestTransform.js' } + object: 'package', name: 'Consent export', version: '0.0.1', description: 'An export of task or multiple consent templates', pipes: { ingest: 'ingestTransform.js' } } ], ])('should writePackage for: %s', (packageType, expected) => { diff --git a/packages/mdctl-axon-tools/lib/StudyManifestTools.js b/packages/mdctl-axon-tools/lib/StudyManifestTools.js index f881d1ba..86ccd64d 100644 --- a/packages/mdctl-axon-tools/lib/StudyManifestTools.js +++ b/packages/mdctl-axon-tools/lib/StudyManifestTools.js @@ -298,7 +298,7 @@ class StudyManifestTools { async buildConsentManifestAndDependencies(consentIds) { const { org, orgReferenceProps } = await this.getOrgAndReferences(), - mappingScript = await getEcMappingScript(org, consentIds), + mappingScript = await getEcMappingScript(org), allEntities = await this.getConsentManifestEntities(org, consentIds, orgReferenceProps), { manifest, removedEntities } = this.validateAndCreateManifest(allEntities, orgReferenceProps, ['ec__document_templates']) @@ -927,5 +927,4 @@ class StudyManifestTools { } -module.exports = StudyManifestTools - +module.exports = StudyManifestTools \ No newline at end of file diff --git a/packages/mdctl-axon-tools/lib/mappings/index.js b/packages/mdctl-axon-tools/lib/mappings/index.js index 67a42684..472747d3 100644 --- a/packages/mdctl-axon-tools/lib/mappings/index.js +++ b/packages/mdctl-axon-tools/lib/mappings/index.js @@ -2,7 +2,6 @@ const { getMappings, getEcMappings } = require('./maps') function getScript(mappings) { return ` - import _ from 'lodash' const { run } = require('expressions') const mappings = ${JSON.stringify(mappings)} @@ -10,8 +9,8 @@ function getScript(mappings) { mappings.forEach(({ path, mapTo }) => { const [entity, entityKey, property, ...rest] = path.split('.'), - isDocPropUpdate = !!rest.length - let value = run(mapTo) + isDocPropUpdate = !!rest.length, + value = run(mapTo) const prop = entity.startsWith('ec__') ? 'ec__key' : 'c_key' @@ -42,36 +41,6 @@ function getScript(mappings) { } - if (entity === 'ec__document_template' && prop === 'ec__key' && property === 'ec__builder_data') { - - const idMapping = _.keyBy(value['ck-widgets-data'], 'ec__key') - const { - _id: template_id, - ec__builder_data: { "ck-widgets-data": originalBuilderData }, - ec__status, creator, owner, updater - } = org.objects.ec__document_templates.find({ ec__key: entityKey }) - .paths('ec__builder_data', 'ec__status', 'creator', 'owner', 'updater') - .next() - - //We can update only draft templates - if (ec__status !== 'draft') { - return - } - - //Map ids between builder_data and corresponding entities - let new_builder_data = originalBuilderData.map((obd) => { - const updatedId = _.get(idMapping, obd.id + '._id') - _.set(obd, 'data._id', updatedId) - _.get(obd, 'data.ec__document_template._id', false) && _.set(obd, 'data.ec__document_template._id', template_id) - _.get(obd, 'data.ec__document_template.path', false) && _.set(obd, 'data.ec__document_template.path', '/ec__document_templates/' + template_id) - _.get(obd, 'data.creator', false) && _.set(obd, 'data.creator', creator) - _.get(obd, 'data.owner', false) && _.set(obd, 'data.owner', owner) - _.get(obd, 'data.updater', false) && _.set(obd, 'data.updater', updater) - return obd - }) - value = { "ck-widgets-data": new_builder_data } - } - //normal prop update return org.objects[entity] .updateOne({ [prop]: entityKey }, { $set: { [property]: value }}) @@ -90,9 +59,9 @@ module.exports = { return getScript(mappings) }, - async getEcMappingScript(org, consentIds = []) { + async getEcMappingScript(org) { - const mappings = await getEcMappings(org, consentIds) + const mappings = await getEcMappings(org) if (mappings.length === 0) return '' diff --git a/packages/mdctl-axon-tools/lib/mappings/maps/EcBuilderDataMap.js b/packages/mdctl-axon-tools/lib/mappings/maps/EcBuilderDataMap.js index f661635c..35acc0a2 100644 --- a/packages/mdctl-axon-tools/lib/mappings/maps/EcBuilderDataMap.js +++ b/packages/mdctl-axon-tools/lib/mappings/maps/EcBuilderDataMap.js @@ -5,22 +5,14 @@ module.exports = class EcBuilderDataMap { this.org = org } - async getEcBuilderDataMaps(consentIds = []) { + async getEcBuilderDataMaps() { + const mapping = [] - let ecTemplates - if (consentIds && consentIds.length) { - ecTemplates = await this.org.objects.ec__document_templates - .find({ _id: { $in: consentIds } }) - .limit(false) - .paths('ec__key', 'ec__builder_data', 'ec__requested_data', 'ec__requested_signatures', 'ec__knowledge_checks') - .toArray() - } else { - ecTemplates = await this.org.objects.ec__document_templates - .find() - .limit(false) - .paths('ec__key', 'ec__builder_data', 'ec__requested_data', 'ec__requested_signatures', 'ec__knowledge_checks') - .toArray() - } + + let ecTemplates = await this.org.objects.ec__document_templates + .find({ ec__status: 'draft' }) + .paths('ec__key', 'ec__builder_data', 'ec__requested_data', 'ec__requested_signatures', 'ec__knowledge_checks') + .toArray() ecTemplates = ecTemplates .filter(template => template.ec__builder_data @@ -62,8 +54,11 @@ module.exports = class EcBuilderDataMap { as: 'entry', in: { $object: { - ec__key: '$$entry.ec__key', - _id: '$$entry._id' + data: '$$entry', + id: '$$entry.ec__key', + type: { + $literal: 'signature' + } } } } @@ -73,8 +68,11 @@ module.exports = class EcBuilderDataMap { as: 'entry', in: { $object: { - ec__key: '$$entry.ec__key', - _id: '$$entry._id' + data: '$$entry', + id: '$$entry.ec__key', + type: { + $literal: 'knowledgeCheck' + } } } } @@ -84,8 +82,22 @@ module.exports = class EcBuilderDataMap { as: 'entry', in: { $object: { - ec__key: '$$entry.ec__key', - _id: '$$entry._id' + data: '$$entry', + id: '$$entry.ec__key', + type: { + $cond: [ + '$$entry.ec__allow_multiple', { + $literal: 'checkboxGroup' + }, { + $cond: [{ + $eq: ['$$entry.ec__allow_multiple', false] + }, { + $literal: 'radioGroup' + }, { + $literal: 'input' + }] + }] + } } } } @@ -100,9 +112,9 @@ module.exports = class EcBuilderDataMap { return mapping } - async getMappings(consentIds = []) { + async getMappings() { return [ - ...await this.getEcBuilderDataMaps(consentIds) + ...await this.getEcBuilderDataMaps() ] } diff --git a/packages/mdctl-axon-tools/lib/mappings/maps/index.js b/packages/mdctl-axon-tools/lib/mappings/maps/index.js index 91bbb288..68101d06 100644 --- a/packages/mdctl-axon-tools/lib/mappings/maps/index.js +++ b/packages/mdctl-axon-tools/lib/mappings/maps/index.js @@ -15,11 +15,11 @@ module.exports = { ] }, - async getEcMappings(org, consentIds = []) { + async getEcMappings(org) { const ecBuilderDataMap = new EcBuilderDataMap(org) return [ - ...await ecBuilderDataMap.getMappings(consentIds) + ...await ecBuilderDataMap.getMappings() ] } }