Skip to content

Commit

Permalink
Merge branch 'release/1.0.70'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ala Hawash committed Jan 15, 2024
2 parents 5dd1061 + 9452dec commit 30ef0d3
Show file tree
Hide file tree
Showing 18 changed files with 764 additions and 3,318 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ scratch
# nix
.direnv
result
packages/mdctl-axon-tools/__tests__/MIG-166/env/i18ns/authTasks/
122 changes: 122 additions & 0 deletions packages/mdctl-axon-tools/__tests__/MIG-166/MIG-166.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable import/order */

const { expect } = require('chai'),
path = require('path'),
fs = require('fs'),
StudyDataTranslations = require('../../lib/StudyDataTranslations'),
mockTasks = [
{
c_key: 'taskKey',
_id: 'taskId',
object: 'c_task',
c_steps: {
object: 'list',
data: [
{
_id: 'stepId',
c_parent_step: {
_id: 'parentStepId',
object: 'c_step',
path: '/c_steps/parentStepId'
},
c_key: 'stepKey',
c_account_map: 'name.first',
object: 'c_step'
}
]
}
}
],
org = {
objects: {
c_tasks: {
find: () => ({
limit: () => ({
paths: () => ({
toArray: () => mockTasks
})
})
})
}
}
}

describe('MIG-166', () => {
let studyTranslations

beforeAll(() => {
studyTranslations = new StudyDataTranslations({})
})

it('can read the new manifest option "authenticationTaskTranslations".', () => {
const studyDataTranslations = studyTranslations.isAuthTaskTranslations({
manifest: {
object: 'manifest',
i18ns: {
includes: ['*']
},
authenticationTaskTranslations: true
}
})

// eslint-disable-next-line no-unused-expressions
expect(studyDataTranslations)
.to.be.true
})

it('should throw an error if the manifest file is missing "i18ns".', () => {
let err
try {
studyTranslations.isAuthTaskTranslations({
manifest: {
object: 'manifest',
authenticationTaskTranslations: true
}
})
} catch (error) {
err = error
}

expect(err.errCode)
.to.equal('mdctl.kInvalidArgument.missingI18nObjects')
})

it('should write the required i18n files.', async() => {
jest.spyOn(StudyDataTranslations.prototype, 'getOrg').mockImplementation(() => org)

await studyTranslations.writeAuthTaskTranslationsToDisk(
{ input: __dirname }
)

const output = path.join(__dirname, './env/i18ns/authTasks/axon_data_af-ZA.json'),
data = JSON.parse(fs.readFileSync(output))

expect(fs.existsSync(output))
.to.be.true

expect(data)
.to.deep.equal({
locale: 'af_ZA',
name: 'axon__af_ZA_authTasks',
namespace: 'axon',
object: 'i18n',
tags: [
'authTasks'
],
weight: 0,
data: {
c_task: {
taskKey: {
c_name: 'Waarmerking'
}
},
c_step: {
stepKey: {
c_text: 'Voornaam'
}
}
}
})
})
})
11 changes: 11 additions & 0 deletions packages/mdctl-axon-tools/__tests__/MIG-166/i18ns/test/af-ZA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"task": "Waarmerking",
"password": "Wagwoord",
"parent": "Waarmerkingsvorm-stap",
"email": "E-pos",
"name.first": "Voornaam",
"name.last": "Van",
"mobile": "Telefoonnommer",
"username": "Gebruikersnaam",
"dob": "Geboortedatum"
}
3 changes: 2 additions & 1 deletion packages/mdctl-axon-tools/__tests__/MIG-85/MIG-85.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ describe('MIG-85 - Test partial migrations in StudyManifestTools', () => {
expectedObjects = ['c_study', 'c_task', 'c_visit_schedule', 'ec__document_template', 'c_group', 'c_query_rule',
'c_anchor_date_template', 'c_fault', 'c_dmweb_report', 'c_site', 'c_task_assignment', 'c_participant_schedule',
'c_patient_flag', 'c_looker_integration_record', 'int__vendor_integration_record', 'int__model_mapping',
'int__pipeline', 'orac__studies', 'orac__sites', 'orac__forms', 'orac__form_questions', 'orac__events', 'wf__workflow', 'c_review_type']
'int__pipeline', 'orac__studies', 'orac__sites', 'orac__forms', 'orac__form_questions', 'orac__events', 'wf__workflow', 'c_review_type', 'int__vendor',
'int__task', 'int__expression', 'int__secret', 'int__form', 'int__question', 'int__site']

expect(availableObjects)
.toStrictEqual(expectedObjects)
Expand Down
7 changes: 7 additions & 0 deletions packages/mdctl-axon-tools/__tests__/TOOLS-50/TOOLS-50.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ describe('getStudyManifestEntities', () => {
['orac__forms'],
['orac__form_questions'],
['orac__events']
['int__vendors'],
['int__tasks'],
['int__expressions'],
['int__secrets'],
['int__forms'],
['int__questions'],
['int__sites']
])('should include %s', async(entity) => {

const exportableObject = ['c_site'],
Expand Down
4 changes: 3 additions & 1 deletion packages/mdctl-axon-tools/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const StudyManifestTools = require('./lib/StudyManifestTools')
const StudyDataTranslations = require('./lib/StudyDataTranslations')

module.exports = {
StudyManifestTools
StudyManifestTools,
StudyDataTranslations
}
143 changes: 143 additions & 0 deletions packages/mdctl-axon-tools/lib/StudyDataTranslations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/* eslint-disable camelcase */
const globby = require('globby'),
path = require('path'),
fs = require('fs'),
_ = require('lodash'),
{ privatesAccessor } = require('@medable/mdctl-core-utils/privates'),
{ Driver } = require('@medable/mdctl-api-driver'),
{ Org } = require('@medable/mdctl-api-driver/lib/cortex.object'),
{ Fault } = require('@medable/mdctl-core')

class StudyDataTranslations {

constructor(client, options = {}) {
Object.assign(privatesAccessor(this), {
client,
options
})
}

getOrg() {
const { client } = privatesAccessor(this),
driver = new Driver(client),
org = new Org(driver)

return org
}

isAuthTaskTranslations({ input = process.cwd(), manifest }) {
let manifestData = manifest
if (!manifestData) {
const location = globby.sync(['manifest.{json,yaml}'], { cwd: input })
if (location.length > 0 && fs.existsSync(`${input}/${location[0]}`)) {
manifestData = JSON.parse(fs.readFileSync(`${input}/${location[0]}`))
}
}

if (manifestData.authenticationTaskTranslations && !_.has(manifestData, 'i18ns')) {
throw Fault.create('mdctl.kInvalidArgument.missingI18nObjects', {
message: 'The manifest is missing "i18ns" objects',
reason: 'Incase of using "authenticationTaskTranslations" option. The manifest file must include "i18ns" objects.'
})
}

return manifestData.authenticationTaskTranslations
}

async writeAuthTaskTranslationsToDisk({ input = process.cwd(), format = 'json' }) {
const location = globby.sync(['i18ns/**/*.{json,yaml}'], { cwd: input }),
tasks = await this.readAuthenticationTasks(),
keys = _.concat(
tasks.map(({ c_key, object, _id }) => ({ c_key, object, _id })),
_.flatMap(
tasks.filter(({ c_steps }) => Boolean(c_steps)),
({ c_steps: { data } }) => data
)
),
parentSteps = keys.filter(({ c_parent_step }) => c_parent_step)
.map(({ c_parent_step: { _id } }) => _id)

if (!location.length) return

if (!fs.existsSync(
path.join(input, 'env/i18ns/authTasks')
)) {
fs.mkdirSync(path.join(input, 'env/i18ns/authTasks'), { recursive: true })
}

location.forEach((l) => {
const lang = path.basename(l, `.${format}`),
data = JSON.parse(fs.readFileSync(`${input}/${l}`))

this.addTaskStepNameTranslations({
lang, translations: data, input, keys, parentSteps
})
})

}

async readAuthenticationTasks() {
const org = this.getOrg(),
tasks = await org.objects.c_tasks.find({ c_type: 'authentication' }).limit(false).paths(
'c_key',
'c_steps._id',
'c_steps.c_parent_step',
'c_steps.c_key',
'c_steps.c_account_map'
).toArray()

return tasks
}

addTaskStepNameTranslations({
lang, translations, input, keys, parentSteps
}) {
const locale = lang.replace(/-/g, '_'),
content = {
locale,
name: `axon__${locale}_authTasks`,
namespace: 'axon',
object: 'i18n',
tags: ['authTasks'],
weight: 0,
data: {}
}

keys.forEach(({
object, c_key, c_account_map, _id
}) => {
let data
if (object === 'c_task') {
data = {
c_task: {
[c_key]: {
c_name: translations.task
}
}
}
} else if (c_account_map || parentSteps.includes(_id)) {
data = {
c_step: {
[c_key]: {
c_text: parentSteps.includes(_id) ? translations.parent : translations[c_account_map]
}
}
}
}
_.merge(
content,
{
data
}
)
})

fs.writeFileSync(
path.join(input, `env/i18ns/authTasks/axon_data_${lang}.json`),
JSON.stringify(content, null, 2)
)
}

}

module.exports = StudyDataTranslations
3 changes: 2 additions & 1 deletion packages/mdctl-axon-tools/lib/StudyManifestTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class StudyManifestTools {
return ['c_study', 'c_task', 'c_visit_schedule', 'ec__document_template', 'c_group', 'c_query_rule',
'c_anchor_date_template', 'c_fault', 'c_dmweb_report', 'c_site', 'c_task_assignment', 'c_participant_schedule',
'c_patient_flag', 'c_looker_integration_record', 'int__vendor_integration_record', 'int__model_mapping',
'int__pipeline', 'orac__studies', 'orac__sites', 'orac__forms', 'orac__form_questions', 'orac__events', 'wf__workflow', 'c_review_type']
'int__pipeline', 'orac__studies', 'orac__sites', 'orac__forms', 'orac__form_questions', 'orac__events', 'wf__workflow', 'c_review_type', 'int__vendor',
'int__task', 'int__expression', 'int__secret', 'int__form', 'int__question', 'int__site']
}

validateAndCleanManifest(manifestJSON) {
Expand Down
Loading

0 comments on commit 30ef0d3

Please sign in to comment.