From e7a30fc7a16b056bac9daa771cf18b1170c7dbcd Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Sat, 30 Sep 2023 14:01:44 +0530 Subject: [PATCH] change if condition for retestmarking --- cloud-functions/nodejs/functions/index.js | 45 ++++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/cloud-functions/nodejs/functions/index.js b/cloud-functions/nodejs/functions/index.js index 5a37445..446f5bc 100644 --- a/cloud-functions/nodejs/functions/index.js +++ b/cloud-functions/nodejs/functions/index.js @@ -262,21 +262,30 @@ const admin = require("firebase-admin"); admin.initializeApp(); exports.retestMarking = async (event, context) => { - const resource = context.resource; - // log out the resource string that triggered the function - console.log('Function triggered by change to: ' + resource); - // now log the full event object - console.log(JSON.stringify(event)); - const { _id, classificationResult } = event.value.fields; - console.log("classificationResult", classificationResult.stringValue); - if (classificationResult?.stringValue?.includes("Negative Borderline")) { - const docs = await admin.firestore().collection("patientData").where("_id", "==", _id.stringValue).get(); - docs?.forEach(async (doc) => { - await admin.firestore().collection("patientData").doc(doc.id).update({ - testStatus: false, - retested: true - // incubationTime: admin.firestore.FieldValue.delete() - }); - }) - } -}; + const resource = context.resource; + // log out the resource string that triggered the function + console.log('Function triggered by change to: ' + resource); + // now log the full event object + console.log(JSON.stringify(event)); + const { _id, classificationResult } = event.value.fields; + console.log("classificationResult", classificationResult.stringValue); + if (classificationResult?.stringValue?.includes("Negative Borderline")) { + const docs = await admin.firestore().collection("patientData").where("_id", "==", _id.stringValue).get(); + docs?.forEach(async (doc) => { + await admin.firestore().collection("patientData").doc(doc.id).update({ + testStatus: false, + retested: true + // incubationTime: admin.firestore.FieldValue.delete() + }); + }) + } else if (classificationResult?.stringValue?.includes("Inconclusive")) { + const docs = await admin.firestore().collection("patientData").where("_id", "==", _id.stringValue).get(); + docs?.forEach(async (doc) => { + await admin.firestore().collection("patientData").doc(doc.id).update({ + testStatus: false, + retested: true + // incubationTime: admin.firestore.FieldValue.delete() + }); + }) + } + };