Archived
2

Merge pull request #31 in ~VLE2FE/definma-api from develop to master

* commit 'a75d2a34248c313bf07fae343b0f181f86c33dac':
  fixed $unwind of deleted measurements
This commit is contained in:
Veit Lukas (PEA4-Fe) 2020-08-17 11:54:46 +02:00
commit 56474cfc4a
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 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';

View File

@ -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']}
}}}},