From 10dcf15272f6a86a227857fdc48206fe1def0d6f Mon Sep 17 00:00:00 2001 From: khavinshankar Date: Thu, 7 Sep 2023 13:45:18 +0530 Subject: [PATCH] added env to save ocr images --- src/automation/autoDataExtractor.js | 100 ++++++++++++++++------------ src/utils/configs.js | 2 + 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/automation/autoDataExtractor.js b/src/automation/autoDataExtractor.js index c4357e0..17f5b8c 100644 --- a/src/automation/autoDataExtractor.js +++ b/src/automation/autoDataExtractor.js @@ -8,6 +8,7 @@ import FormData from 'form-data'; import { getMonitorCoordinates } from "./helper/getMonitorCoordinates.js"; import * as dotenv from "dotenv"; +import { saveOCRImages } from "../utils/configs.js"; dotenv.config({ path: "./.env" }); @@ -15,50 +16,62 @@ const MONITOR_PRESET_NAME_PREFIX = "5 Para_Bed_"; const OCR_URL = process.env.OCR_URL; -const celsiusToFahrenheit = (celsius)=> { - celsius = parseFloat(celsius) - const fahrenheit = (celsius * 9/5) + 32; - return fahrenheit; -} - -const validator = (value, parser, minvalue, maxValue)=>{ - - if(isNaN(value)) - { - return null - } - - value = parser(value) - - return value >=minvalue && value <=maxValue ? value : null -} -const getSanitizedData = (data)=>{ +const celsiusToFahrenheit = (celsius) => { + celsius = parseFloat(celsius); + const fahrenheit = (celsius * 9) / 5 + 32; + return fahrenheit; +}; - console.log(data) +const validator = (value, parser, minvalue, maxValue) => { + if (isNaN(value)) { + return null; + } - const sanitizedData = {} - sanitizedData["spo2"] = !isNaN(data?.["SpO2"]) ? parseFloat(data?.["SpO2"]): null + value = parser(value); - sanitizedData["ventilator_spo2"] = validator(sanitizedData.spo2, parseInt, 0, 100) - - sanitizedData["resp"] = validator(data?.["Respiratory Rate"], parseInt, 10, 70) + return value >= minvalue && value <= maxValue ? value : null; +}; +const getSanitizedData = (data) => { + console.log(data); + + const sanitizedData = {}; + sanitizedData["spo2"] = !isNaN(data?.["SpO2"]) + ? parseFloat(data?.["SpO2"]) + : null; + + sanitizedData["ventilator_spo2"] = validator( + sanitizedData.spo2, + parseInt, + 0, + 100 + ); - sanitizedData["pulse"] = validator(data?.["Pulse Rate"], parseInt, 0, 100) + sanitizedData["resp"] = validator( + data?.["Respiratory Rate"], + parseInt, + 10, + 70 + ); - sanitizedData["temperature"] = validator(data?.["Temperature"], celsiusToFahrenheit, 95, 106) - - - sanitizedData["bp"] = !isNaN(data?.["Blood Pressure"]) ? - { - "systolic": parseFloat(data?.["Blood Pressure"]), - "mean": parseFloat(data?.["Blood Pressure"]), - "diastolic": parseFloat(data?.["Blood Pressure"]) - } : null + sanitizedData["pulse"] = validator(data?.["Pulse Rate"], parseInt, 0, 100); - return sanitizedData + sanitizedData["temperature"] = validator( + data?.["Temperature"], + celsiusToFahrenheit, + 95, + 106 + ); + sanitizedData["bp"] = !isNaN(data?.["Blood Pressure"]) + ? { + systolic: parseFloat(data?.["Blood Pressure"]), + mean: parseFloat(data?.["Blood Pressure"]), + diastolic: parseFloat(data?.["Blood Pressure"]), + } + : null; -} + return sanitizedData; +}; const extractData = async (camParams, bedId) => { const coordinates = await getMonitorCoordinates(bedId); @@ -86,13 +99,14 @@ const extractData = async (camParams, bedId) => { }, }); - // delete image - fs.unlink(imagePath, (err) => { - if (err) { - // TODO: Critical logger setup - console.error(err); - } - }); + if (!saveOCRImages) { + fs.unlink(imagePath, (err) => { + if (err) { + // TODO: Critical logger setup + console.error(err); + } + }); + } return getSanitizedData(response.data.data); }; diff --git a/src/utils/configs.js b/src/utils/configs.js index 80029ee..8d6daab 100644 --- a/src/utils/configs.js +++ b/src/utils/configs.js @@ -10,3 +10,5 @@ export const s3Endpoint = process.env.S3_ENDPOINT || ({ export const s3BucketName = process.env.S3_BUCKET_NAME; export const s3AccessKeyId = process.env.S3_ACCESS_KEY_ID; export const s3SecretAccessKey = process.env.S3_SECRET_ACCESS_KEY; + +export const saveOCRImages = process.env.SAVE_OCR_IMAGES === "true"; \ No newline at end of file