Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc/mig/1.2.0 #391

Merged
merged 3 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/mdctl-axon-tools/__tests__/MIG-11/MIG-11.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ describe('ingestTransform', () => {
const docErr = { code: 'kInvalidArgument', errCode: 'cortex.invalidArgument.updateDisabled', reason: 'An eConsent template in this import exists in the target and is not in draft', message: 'Document Key 2222, Document title "title"' }
it.each([
// test, resource, memo, expected
['Draft consents should be imported ', { object: 'ec__document_template', ec__status: 'draft', ec__key: '1111' }, {}, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '1111' }],
['Published docs not existing in target should be imported', { object: 'ec__document_template', ec__status: 'published', ec__key: '3333', ec__title: 'title' }, {}, { object: 'ec__document_template', ec__status: 'published', ec__sites: [], ec__key: '3333', ec__title: 'title' }],
['Published docs existing should throw an error', { object: 'ec__document_template', ec__status: 'draft', ec__key: '2222', ec__title: 'title' }, {}, docErr],
['Draft consents should be imported ', { object: 'ec__document_template', ec__status: 'draft', ec__key: '1111' }, { manifest: {} }, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '1111' }],
['Published docs not existing in target should be imported', { object: 'ec__document_template', ec__status: 'published', ec__key: '3333', ec__title: 'title' }, { manifest: {} }, { object: 'ec__document_template', ec__status: 'published', ec__sites: [], ec__key: '3333', ec__title: 'title' }],
['Published docs existing should throw an error', { object: 'ec__document_template', ec__status: 'draft', ec__key: '2222', ec__title: 'title' }, { manifest: {} }, docErr],
])('%s', (test, resource, memo, expected) => {

let transformedResource
Expand Down
105 changes: 105 additions & 0 deletions packages/mdctl-axon-tools/__tests__/MIG-127/MIG-127.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const Transform = require('../../packageScripts/ingestTransform.js')
let transform, consts

jest.mock('runtime.transform', () => ({ Transform: class { } }), { virtual: true })
jest.mock('config', () => { }, { virtual: true })

describe('econsentDocumentTemplateAdjustments', () => {

beforeAll(() => {
transform = new Transform()
global.consts = { accessLevels: { read: 'read' } }
global.org = {
objects: {
ec__document_template: {
readOne: () => ({
skipAcl: () => ({
grant: () => ({
throwNotFound: () => ({
paths: () => ({
execute: () => { }
})
})
})
})
})
}
}
}
})

it('should not delete sites from ec__sites present in the manifest', () => {
const resource = { object: 'ec__document_template', ec__status: 'draft', ec__sites: ['c_site.abc'] },
memo = { availableApps: { eConsentConfig: '1.0' }, manifest: { c_site: { includes: ['abc'] } } }

global.org.objects.c_sites = {
find: () => ({
skipAcl: () => ({
grant: () => ({
hasNext: () => false
})
})
})
}

transform.each(resource, memo)

expect(resource.ec__sites)
.toStrictEqual(['c_site.abc'])
})

it('should not delete sites from ec__sites present in the org', () => {
const resource = { object: 'ec__document_template', ec__status: 'draft', ec__sites: ['c_site.abc'] },
memo = { availableApps: { eConsentConfig: '1.0' }, manifest: {} }

global.org.objects.c_sites = {
find: () => ({
skipAcl: () => ({
grant: () => ({
hasNext: () => true
})
})
})
}

transform.each(resource, memo)

expect(resource.ec__sites)
.toStrictEqual(['c_site.abc'])
})

it('should delete sites from ec__sites not present in the manifest or the org', () => {
// manifest includes site abc, org includes site def, so should remove site ghi
const resource = { object: 'ec__document_template', ec__status: 'draft', ec__sites: ['c_site.abc', 'c_site.def', 'c_site.ghi'] },
memo = { availableApps: { eConsentConfig: '1.0' }, manifest: { c_site: { includes: ['abc'] } } }

global.org.objects.c_sites = {
find: ({ c_key }) => {
if (c_key === 'def') {
return {
skipAcl: () => ({
grant: () => ({
hasNext: () => true
})
})
}
}
else {
return {
skipAcl: () => ({
grant: () => ({
hasNext: () => false
})
})
}
}
}
}

transform.each(resource, memo)

expect(resource.ec__sites)
.toStrictEqual(['c_site.abc', 'c_site.def'])
})

})
4 changes: 2 additions & 2 deletions packages/mdctl-axon-tools/__tests__/MIG-66/MIG-66.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ describe('ingestTransform', () => {
const docErr = { code: 'kInvalidArgument', errCode: 'cortex.invalidArgument.updateDisabled', reason: 'An eConsent template in this import exists in the target and is not in draft', message: 'Document Key 2222, Document title "title"' }
it.each([
// test, resource, memo, expected
['Consent that match the existing study should not change', { object: 'ec__document_template', ec__status: 'draft', ec__key: '1111', ec__study: 'c_study.abc' }, {}, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '1111', ec__study: 'c_study.abc' }],
['Consent that don`t match the existing study should change to match', { object: 'ec__document_template', ec__status: 'draft', ec__key: '1111', ec__study: 'c_study.cba' }, {}, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '1111', ec__study: 'c_study.abc' }],
['Consent that match the existing study should not change', { object: 'ec__document_template', ec__status: 'draft', ec__key: '1111', ec__study: 'c_study.abc' }, { manifest: {} }, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '1111', ec__study: 'c_study.abc' }],
['Consent that don`t match the existing study should change to match', { object: 'ec__document_template', ec__status: 'draft', ec__key: '1111', ec__study: 'c_study.cba' }, { manifest: {} }, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '1111', ec__study: 'c_study.abc' }],
])('%s', (test, resource, memo, expected) => {

let transformedResource
Expand Down
6 changes: 3 additions & 3 deletions packages/mdctl-axon-tools/__tests__/MIG-71/MIG-71.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ describe('ingestTransform', () => {

it.each([
// test, resource, memo, expected
['Consents with same ec__key and ec__identifier should be overwritten', { object: 'ec__document_template', ec__status: 'draft', ec__key: '11111', ec__title: 'title 1 MIG', ec__identifier: '000001'}, {}, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '11111', ec__title: 'title 1 MIG', ec__identifier: '000001' }],
['Consents with same ec__identifier but different ec__key should have last 5 digits of ec__key appended onto the ec__identifier', { object: 'ec__document_template', ec__status: 'draft', ec__key: '33333', ec__title: 'title 3', ec__identifier: '000001' }, {}, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '33333', ec__title: 'title 3', ec__identifier: '000001-33333' }],
['Consents with same ec__key but different ec__identifier should overwrite the template in the target org with the same ec__key', { object: 'ec__document_template', ec__status: 'draft', ec__key: '22222', ec__title: 'title MIG AGAIN', ec__identifier: '000001' }, {}, { object: 'ec__document_template', ec__status: 'draft', ec__key: '22222', ec__title: 'title MIG AGAIN', ec__identifier: '000001-22222', ec__sites: [] }],
['Consents with same ec__key and ec__identifier should be overwritten', { object: 'ec__document_template', ec__status: 'draft', ec__key: '11111', ec__title: 'title 1 MIG', ec__identifier: '000001'}, { manifest: {} }, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '11111', ec__title: 'title 1 MIG', ec__identifier: '000001' }],
['Consents with same ec__identifier but different ec__key should have last 5 digits of ec__key appended onto the ec__identifier', { object: 'ec__document_template', ec__status: 'draft', ec__key: '33333', ec__title: 'title 3', ec__identifier: '000001' }, { manifest: {} }, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [], ec__key: '33333', ec__title: 'title 3', ec__identifier: '000001-33333' }],
['Consents with same ec__key but different ec__identifier should overwrite the template in the target org with the same ec__key', { object: 'ec__document_template', ec__status: 'draft', ec__key: '22222', ec__title: 'title MIG AGAIN', ec__identifier: '000001' }, { manifest: {} }, { object: 'ec__document_template', ec__status: 'draft', ec__key: '22222', ec__title: 'title MIG AGAIN', ec__identifier: '000001-22222', ec__sites: [] }],
])('%s', (test, resource, memo, expected) => {

let transformedResource
Expand Down
10 changes: 5 additions & 5 deletions packages/mdctl-axon-tools/__tests__/TOOLS-42/TOOLS-42.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ describe('ingestTransform', () => {

it.each([
// test, resource, memo, expected
['should perform studyReferenceAdjustment', { object: 'c_some_object', c_study: '' }, { study: { c_key: 'abc' } }, { object: 'c_some_object', c_study: 'c_study.abc' }],
['should perform studyAdjustments and add c_no_pii to false if it does not exist', { object: 'c_study' }, {}, { object: 'c_study', c_no_pii: false }],
['should perform studyAdjustments and preserve c_no_pii if it does exist', { object: 'c_study', c_no_pii: true }, {}, { object: 'c_study', c_no_pii: true }],
['should perform econsentDocumentTemplateAdjustments', { object: 'ec__document_template', ec__status: 'draft' }, {}, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [] }],
['should perform studyReferenceAdjustment', { object: 'c_some_object', c_study: '' }, { study: { c_key: 'abc' }, manifest: {} }, { object: 'c_some_object', c_study: 'c_study.abc' }],
['should perform studyAdjustments and add c_no_pii to false if it does not exist', { object: 'c_study' }, { manifest: {} }, { object: 'c_study', c_no_pii: false }],
['should perform studyAdjustments and preserve c_no_pii if it does exist', { object: 'c_study', c_no_pii: true }, { manifest: {} }, { object: 'c_study', c_no_pii: true }],
['should perform econsentDocumentTemplateAdjustments', { object: 'ec__document_template', ec__status: 'draft' }, { manifest: {} }, { object: 'ec__document_template', ec__status: 'draft', ec__sites: [] }],
// eslint-disable-next-line object-curly-newline
['should not perform changes to manifest object', { object: 'manifest', c_study: {}, importOwner: false, exportOwner: false }, { study: { c_key: 'abc' } }, { object: 'manifest', c_study: {}, importOwner: false, exportOwner: false }]
['should not perform changes to manifest object', { object: 'manifest', c_study: {}, importOwner: false, exportOwner: false }, { study: { c_key: 'abc' }, manifest: {} }, { object: 'manifest', c_study: {}, importOwner: false, exportOwner: false }]
])('%s', (test, resource, memo, expected) => {

transform.beforeAll(memo)
Expand Down
4 changes: 3 additions & 1 deletion packages/mdctl-axon-tools/lib/StudyManifestTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,9 @@ class StudyManifestTools {
}
case 'ec__document_template': {
// Get the eConsents ID's from the study or the manifest
ids = (await this.getObjectIDsArray(org, key, property, values)).map(v => v._id)
// econsent template properties are namespaced ec__, rather than c_
const ecProp = property === 'c_study' ? 'ec__study' : 'ec__key'
ids = (await this.getObjectIDsArray(org, key, ecProp, values)).map(v => v._id)
// Load the manifest for the current ID's and their dependencies
objectAndDependencies = await this.getConsentManifestEntities(org, ids, orgReferenceProps)
break
Expand Down
16 changes: 10 additions & 6 deletions packages/mdctl-axon-tools/packageScripts/ingestTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ module.exports = class extends Transform {
each(resource, memo) {

// if it is the manifest we let it go as is
if (resource.object === 'manifest') return resource
if (resource.object === 'manifest') {
memo.manifest = resource
return resource
}

this.checkIfDependenciesAvailable(resource, memo)

Expand Down Expand Up @@ -145,8 +148,9 @@ module.exports = class extends Transform {
.grant(consts.accessLevels.read)
.throwNotFound(false)
.paths('ec__status', 'ec__title', 'ec__key', 'ec__identifier')
.execute()

.execute(),
manifest = memo.manifest

if (doc && doc.ec__status !== 'draft') {
throw Fault.create('kInvalidArgument',
{
Expand Down Expand Up @@ -183,13 +187,13 @@ module.exports = class extends Transform {
if (doc && doc.ec__sites) {
resource.ec__sites.push(...doc.ec__sites)
}

// make sure sites array only contains sites that are in the target
const manifestSiteKeys = manifest.c_site && manifest.c_site.includes || []
// make sure sites array only contains sites that are in the target or in the manifest
resource.ec__sites = resource.ec__sites.filter((v) => {
const spl = v.split('.'),
// eslint-disable-next-line camelcase
c_key = spl[1]
return c_sites.find({ c_key }).hasNext()
return c_sites.find({ c_key }).skipAcl().grant(consts.accessLevels.read).hasNext() || manifestSiteKeys.includes(c_key)
})


Expand Down