Archived
2

fixed $unwind of deleted measurements

This commit is contained in:
VLE2FE 2020-08-17 11:54:03 +02:00
parent c6f5186f7e
commit a75d2a3424
2 changed files with 27 additions and 6 deletions

View File

@ -52,6 +52,25 @@ const dptLog = [];
const dptSampleAddLog = []; // log samples created during dpt insertion const dptSampleAddLog = []; // log samples created during dpt insertion
const typeLog = []; 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 // TODO: conditions
main(); main();
@ -65,6 +84,7 @@ async function main() {
// await saveMaterials(); // await saveMaterials();
} }
fs.writeFileSync('./data_import/numberToColor.json', JSON.stringify(numberToColor)); fs.writeFileSync('./data_import/numberToColor.json', JSON.stringify(numberToColor));
fs.writeFileSync('./data_import/duplicateMNames.json', JSON.stringify(duplicateMNamesLog));
} }
if (stages.samples) { // samples if (stages.samples) { // samples
sampleDeviceMap(); sampleDeviceMap();
@ -651,8 +671,9 @@ async function allMaterials() {
// process all samples // process all samples
for (let index in data) { for (let index in data) {
let sample = data[index]; let sample = data[index];
if (sample['materialname'].replace(/\s+/g, '') === 'Latamid66H2G30') { // TODO: remove next if, only for duplicate m names
console.log(sample); if (duplicateMNames.indexOf(sample['materialname']) >= 0) {
duplicateMNamesLog.push(sample);
} }
if (sample['supplier'] === '') { // empty supplier fields if (sample['supplier'] === '') { // empty supplier fields
sample['supplier'] = 'unknown'; sample['supplier'] = 'unknown';

View File

@ -827,10 +827,10 @@ function addMeasurements(queryPtr, templates) {
queryPtr.push( queryPtr.push(
{$addFields: {[templates[0].name]: {$let: {vars: { {$addFields: {[templates[0].name]: {$let: {vars: {
arr: {$filter: { arr: {$filter: {
input: '$measurements', cond: {$in: [ input: '$measurements', cond: {$and: [
'$$this.measurement_template', {$in: ['$$this.measurement_template', templates.map(e => mongoose.Types.ObjectId(e._id))]},
templates.map(e => mongoose.Types.ObjectId(e._id)) {$ne: ['$$this.status', globals.status.del]}
]} ]},
}}}, }}},
in: {$cond: [{$lte: [{$size: '$$arr'}, 1]}, {$arrayElemAt: ['$$arr', 0]}, '$$arr']} in: {$cond: [{$lte: [{$size: '$$arr'}, 1]}, {$arrayElemAt: ['$$arr', 0]}, '$$arr']}
}}}}, }}}},