From a75d2a34248c313bf07fae343b0f181f86c33dac Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Mon, 17 Aug 2020 11:54:03 +0200 Subject: [PATCH] fixed $unwind of deleted measurements --- data_import/import.js | 25 +++++++++++++++++++++++-- src/routes/sample.ts | 8 ++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/data_import/import.js b/data_import/import.js index 6e8f870..38f4526 100644 --- a/data_import/import.js +++ b/data_import/import.js @@ -52,6 +52,25 @@ const dptLog = []; const dptSampleAddLog = []; // log samples created during dpt insertion const typeLog = []; +const duplicateMNames = [ + "Badamid LA70 GF30 TM-Z2", + "Latamid 66 H2 G30", + "Latamid 66 H2 G35", + "Latamid 66 H2 G50", + "Radilon ARV350KB", + "Schulamid 66 GF 25H", + "Schulamid 66 GF25 H", + "Ultradur B 4330 G6 HR", + "Ultradur B 4300 G10", + "Ultradur B 4300 G 4", + "Ultradur B 4300 G6", + "Ultradur B 4315 G6 HR", + "Ultraform N 2200 G 43", + "Ultraform N 2200 G 43 AT", + "Ultrason E 2010 G6", + "Zytel 70G30HSLR" +]; +const duplicateMNamesLog = []; // TODO: conditions main(); @@ -65,6 +84,7 @@ async function main() { // await saveMaterials(); } fs.writeFileSync('./data_import/numberToColor.json', JSON.stringify(numberToColor)); + fs.writeFileSync('./data_import/duplicateMNames.json', JSON.stringify(duplicateMNamesLog)); } if (stages.samples) { // samples sampleDeviceMap(); @@ -651,8 +671,9 @@ async function allMaterials() { // process all samples for (let index in data) { let sample = data[index]; - if (sample['materialname'].replace(/\s+/g, '') === 'Latamid66H2G30') { - console.log(sample); + // TODO: remove next if, only for duplicate m names + if (duplicateMNames.indexOf(sample['materialname']) >= 0) { + duplicateMNamesLog.push(sample); } if (sample['supplier'] === '') { // empty supplier fields sample['supplier'] = 'unknown'; diff --git a/src/routes/sample.ts b/src/routes/sample.ts index 55665e5..4fe1763 100644 --- a/src/routes/sample.ts +++ b/src/routes/sample.ts @@ -827,10 +827,10 @@ function addMeasurements(queryPtr, templates) { queryPtr.push( {$addFields: {[templates[0].name]: {$let: {vars: { arr: {$filter: { - input: '$measurements', cond: {$in: [ - '$$this.measurement_template', - templates.map(e => mongoose.Types.ObjectId(e._id)) - ]} + input: '$measurements', cond: {$and: [ + {$in: ['$$this.measurement_template', templates.map(e => mongoose.Types.ObjectId(e._id))]}, + {$ne: ['$$this.status', globals.status.del]} + ]}, }}}, in: {$cond: [{$lte: [{$size: '$$arr'}, 1]}, {$arrayElemAt: ['$$arr', 0]}, '$$arr']} }}}},