Skip to content

Commit

Permalink
Added some logging to the script to be informative of the output and …
Browse files Browse the repository at this point in the history
…fixed a few things found in the process
  • Loading branch information
SeriousHorncat committed Jul 7, 2023
1 parent 95498d6 commit 6945d16
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions etc/fixtures/migrations/migrate-new-sections-phenotips-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ db = db.getSiblingDB(databaseName);
try {
const analyses = db.analyses.find();
analyses.forEach(element => {
print(`Migrating case ${element.name} -----`)

let briefToModelGoalsFields = [];
let namesOfFieldsToMove = ['Model of Interest', 'Goals', 'Proposed Model/Project']
let HPOTermsValues = [];
Expand All @@ -67,6 +69,7 @@ try {
section.content = section.content.filter((contentItem) => {
return !namesOfFieldsToMove.includes(contentItem.field);
});
print(` - Removing sections from Brief to go to Model Goals...`)
} else if (section.header === 'Pedigree') {
section['attachment_field'] = 'Pedigree';
if(section.content.length == 0) {
Expand All @@ -75,6 +78,7 @@ try {
'field': 'Pedigree',
'value': []
}]
print(` - Creating image dataset for empty pedigree...`)
} else {
let updatedContent = []
section.content.forEach((image) => {
Expand All @@ -88,6 +92,7 @@ try {
value: newValues
})
})
print(` - Migrateing image dataset for for pedigree...`)
section.content = updatedContent
}
} else if (section.header === 'Clinical History') {
Expand All @@ -97,6 +102,11 @@ try {
HPOTermsValues = contentItem.value;
}
});

section.content = section.content.filter((contentItem) => {
return !contentItem.field === 'HPO Terms';
});
print(` - Removing HPO Terms From Clinical History...`)
} else {
if(!['Function', 'Molecular', 'Gene'].some(element => section.header.includes(element))) {
section.content.forEach(contentItem => {
Expand All @@ -106,6 +116,7 @@ try {
}
})

// Adding new sections for each gene
genes = []
element.genomic_units.forEach(unit => {
if (unit.gene) {
Expand All @@ -115,7 +126,6 @@ try {

if (genes.length > 0) {
genes.forEach(gene => {

newGeneSections = [{
"header": gene.concat(" Gene to Phenotype"),
"attachment_field": gene.concat(" Gene to Phenotype"),
Expand All @@ -134,26 +144,28 @@ try {
"attachment_field": gene.concat(" Function"),
"content": [{"type": "images-dataset", "field": gene.concat(" Function"), "value": []},]
}]
print(` - Adding Moving HPO terms from Clinical History...`)
print(` - Adding new sections for ${gene}...`)
element.sections.push(...newGeneSections)
})

element.sections.push(...newGeneSections)
}

// Adding model goals section
element.sections.push({
header: 'Model Goals', 'content': [
...briefToModelGoalsFields,
{'field': 'Existing Collaborations', 'value': [], type: 'section-text'},
{'field': 'Existing Funding', 'value': [], type: 'section-text'},
]
})

print(element.sections);
print(` - Copyed sections from brief into Model Goals...`)

// update
db.analyses.update(
{'_id': element._id},
{'$set': element}
)
print(`Updated ${element.name} -----`)
});
} catch (err) {
console.log(err.stack);
Expand Down

0 comments on commit 6945d16

Please sign in to comment.