@measurequick/measurequick-report-generator 1.5.216 → 1.5.218
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PDFDocument } from "pdf-lib";
|
|
1
|
+
import { PDFDocument, rgb } from "pdf-lib";
|
|
2
2
|
import * as base64 from "../base-64/icons.js";
|
|
3
3
|
import * as pdf from "../base-64/mq-vitals-heating.js";
|
|
4
4
|
import * as systemInfoPage from "./system-info-page.js";
|
|
@@ -283,25 +283,41 @@ export async function getReport(payload, _test) {
|
|
|
283
283
|
coSupRaw,
|
|
284
284
|
});
|
|
285
285
|
|
|
286
|
+
// CO level helper function
|
|
287
|
+
// Normal: 0-8 ppm, Elevated: 9-35 ppm, Dangerous: 36-69 ppm, Emergency: 70+ ppm
|
|
288
|
+
function getCOLevel(ppm) {
|
|
289
|
+
if (!isFinite(ppm) || ppm <= 8) return "Normal";
|
|
290
|
+
if (ppm >= 9 && ppm <= 35) return "Elevated";
|
|
291
|
+
if (ppm >= 36 && ppm <= 69) return "Dangerous";
|
|
292
|
+
return "Emergency";
|
|
293
|
+
}
|
|
294
|
+
|
|
286
295
|
var reasons = [];
|
|
287
|
-
if (isFinite(coAmbRaw) && coAmbRaw >
|
|
288
|
-
if (isFinite(coRetRaw) && coRetRaw >
|
|
289
|
-
if (isFinite(coSupRaw) && coSupRaw >
|
|
296
|
+
if (isFinite(coAmbRaw) && coAmbRaw > 8) reasons.push({ type: "Ambient", value: coAmbRaw, level: getCOLevel(coAmbRaw) });
|
|
297
|
+
if (isFinite(coRetRaw) && coRetRaw > 8) reasons.push({ type: "Return", value: coRetRaw, level: getCOLevel(coRetRaw) });
|
|
298
|
+
if (isFinite(coSupRaw) && coSupRaw > 8) reasons.push({ type: "Supply", value: coSupRaw, level: getCOLevel(coSupRaw) });
|
|
290
299
|
var coHigh = reasons.length > 0;
|
|
291
|
-
VH_LOG("CO threshold check >
|
|
300
|
+
VH_LOG("CO threshold check > 8 ppm:", { coHigh, reasons });
|
|
292
301
|
|
|
293
302
|
if (coHigh) {
|
|
294
303
|
VH_LOG("Setting CO warnings in form fields: COWarning / COWarning2");
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
304
|
+
// Find the highest severity level
|
|
305
|
+
var highestLevel = "Elevated";
|
|
306
|
+
var maxPpm = 0;
|
|
307
|
+
for (var r = 0; r < reasons.length; r++) {
|
|
308
|
+
if (reasons[r].value > maxPpm) maxPpm = reasons[r].value;
|
|
309
|
+
if (reasons[r].level === "Emergency") highestLevel = "Emergency";
|
|
310
|
+
else if (reasons[r].level === "Dangerous" && highestLevel !== "Emergency") highestLevel = "Dangerous";
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Build details string showing each elevated reading
|
|
314
|
+
var details = reasons.map(function(r) { return r.type + ": " + Math.round(r.value) + " ppm (" + r.level + ")"; }).join(", ");
|
|
315
|
+
|
|
316
|
+
var warningMsg = "WARNING: " + highestLevel + " CO Detected! " + details + "\nVentilate the area and investigate the source.";
|
|
317
|
+
var warningMsg2 = "WARNING: " + highestLevel + " CO Detected! " + details + " Ventilate the area and investigate the source.";
|
|
318
|
+
|
|
319
|
+
safeSetText(form, "COWarning", warningMsg);
|
|
320
|
+
safeSetText(form, "COWarning2", warningMsg2);
|
|
305
321
|
} else {
|
|
306
322
|
VH_LOG("Clearing CO warnings (values within threshold)");
|
|
307
323
|
// clear warnings if not applicable
|
|
@@ -548,16 +564,51 @@ export async function getReport(payload, _test) {
|
|
|
548
564
|
passFails.splice(3, 1);
|
|
549
565
|
pfLabels.splice(3, 1);
|
|
550
566
|
}
|
|
567
|
+
|
|
568
|
+
// CO threshold levels (matching mq-hvac app)
|
|
569
|
+
// Normal: 0-8 ppm (Green)
|
|
570
|
+
// Elevated: 9-35 ppm (Yellow/Orange)
|
|
571
|
+
// Dangerous: 36-69 ppm (Red)
|
|
572
|
+
// Emergency: 70+ ppm (Red)
|
|
573
|
+
function getCOIcon(coValue) {
|
|
574
|
+
if (coValue === null || coValue === undefined || isNaN(coValue)) {
|
|
575
|
+
return iconRangeGreen; // default to green if no value
|
|
576
|
+
}
|
|
577
|
+
if (coValue <= 8) {
|
|
578
|
+
return iconRangeGreen; // Normal
|
|
579
|
+
} else if (coValue >= 9 && coValue <= 35) {
|
|
580
|
+
return iconRangeYellow; // Elevated
|
|
581
|
+
} else {
|
|
582
|
+
return iconRangeRed; // Dangerous (36-69) or Emergency (70+)
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function getCOStateText(coValue) {
|
|
587
|
+
if (coValue === null || coValue === undefined || isNaN(coValue)) {
|
|
588
|
+
return "";
|
|
589
|
+
}
|
|
590
|
+
if (coValue <= 8) {
|
|
591
|
+
return "Normal";
|
|
592
|
+
} else if (coValue >= 9 && coValue <= 35) {
|
|
593
|
+
return "Elevated";
|
|
594
|
+
} else if (coValue >= 36 && coValue <= 69) {
|
|
595
|
+
return "Dangerous";
|
|
596
|
+
} else {
|
|
597
|
+
return "Emergency";
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// Collect items that have values
|
|
602
|
+
let validItems = [];
|
|
551
603
|
for (let i = 0; i < passFails.length; i++) {
|
|
552
604
|
const meas = test.testInfo[passFails[i]];
|
|
553
605
|
|
|
554
|
-
//
|
|
606
|
+
// Skip items with no value
|
|
555
607
|
if (meas === undefined || meas === null || meas === "") {
|
|
556
|
-
safeSetText(form, `SSR${i + 1}`, "");
|
|
557
608
|
continue;
|
|
558
609
|
}
|
|
559
610
|
|
|
560
|
-
//
|
|
611
|
+
// Determine icon based on value
|
|
561
612
|
let icon;
|
|
562
613
|
if (meas === "Caution") {
|
|
563
614
|
icon = iconRangeYellow;
|
|
@@ -566,53 +617,65 @@ export async function getReport(payload, _test) {
|
|
|
566
617
|
} else {
|
|
567
618
|
icon = iconRangeRed;
|
|
568
619
|
}
|
|
569
|
-
if (passFails[i] === "heating_efficiency_pass_fail")
|
|
620
|
+
if (passFails[i] === "heating_efficiency_pass_fail") {
|
|
570
621
|
icon = iconRangeGreen;
|
|
571
|
-
|
|
572
|
-
// Set the icon as before
|
|
573
|
-
safeSetImage(form, `ImageSubsystem${i + 1}_af_image`, icon);
|
|
622
|
+
}
|
|
574
623
|
|
|
575
624
|
const suffix = test.testInfo[passFails[i] + "_override"] ? " *" : "";
|
|
576
|
-
const fieldName = `SSR${i + 1}`;
|
|
577
|
-
|
|
578
|
-
// Default label for non-special cases
|
|
579
625
|
let label = pfLabels[i] + suffix;
|
|
626
|
+
let textColor = rgb(0, 0, 0); // default black
|
|
580
627
|
|
|
581
|
-
// Special handling
|
|
628
|
+
// Special handling for Ambient CO
|
|
582
629
|
if (passFails[i] === "ambient_pass_fail") {
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
)
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
label = "CO
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
597
|
-
|
|
630
|
+
const coValue = test.data && test.data.co_ambient !== undefined && test.data.co_ambient !== null
|
|
631
|
+
? Number(test.data.co_ambient)
|
|
632
|
+
: null;
|
|
633
|
+
|
|
634
|
+
// Use CO-specific icon based on actual value
|
|
635
|
+
if (coValue !== null && !isNaN(coValue)) {
|
|
636
|
+
icon = getCOIcon(coValue);
|
|
637
|
+
const stateText = getCOStateText(coValue);
|
|
638
|
+
label = "Ambient CO: " + Math.round(coValue) + " ppm" + (stateText ? " (" + stateText + ")" : "") + suffix;
|
|
639
|
+
|
|
640
|
+
// Set text color based on CO level
|
|
641
|
+
if (coValue >= 36) {
|
|
642
|
+
textColor = rgb(1, 0, 0); // Red for Dangerous/Emergency
|
|
643
|
+
} else if (coValue >= 9) {
|
|
644
|
+
textColor = rgb(0.8, 0.4, 0); // Orange for Elevated
|
|
645
|
+
}
|
|
598
646
|
} else {
|
|
599
|
-
//
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
647
|
+
// No CO value, use pass/fail status
|
|
648
|
+
const isFail = !(meas === "Pass" || meas === "High" || meas === "Mid" || meas === "Caution");
|
|
649
|
+
if (isFail) {
|
|
650
|
+
label = "CO Ambient High, Investigate Source!" + suffix;
|
|
651
|
+
textColor = rgb(1, 0, 0);
|
|
652
|
+
icon = iconRangeRed;
|
|
653
|
+
}
|
|
606
654
|
}
|
|
607
655
|
}
|
|
608
656
|
|
|
609
|
-
|
|
657
|
+
validItems.push({ label, icon, textColor });
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// Fill fields sequentially with valid items (no gaps)
|
|
661
|
+
for (let i = 0; i < validItems.length; i++) {
|
|
662
|
+
const item = validItems[i];
|
|
663
|
+
const fieldName = `SSR${i + 1}`;
|
|
664
|
+
|
|
665
|
+
safeSetImage(form, `ImageSubsystem${i + 1}_af_image`, item.icon);
|
|
666
|
+
|
|
610
667
|
try {
|
|
611
668
|
const tf = form.getTextField(fieldName);
|
|
612
|
-
tf.setText(label);
|
|
613
|
-
tf.setTextColor(
|
|
669
|
+
tf.setText(item.label);
|
|
670
|
+
tf.setTextColor(item.textColor);
|
|
614
671
|
} catch (e) {}
|
|
615
672
|
}
|
|
673
|
+
|
|
674
|
+
// Clear any remaining unused fields
|
|
675
|
+
for (let i = validItems.length; i < passFails.length; i++) {
|
|
676
|
+
safeSetText(form, `SSR${i + 1}`, "");
|
|
677
|
+
// Clear the icon by not setting it (or set to null if needed)
|
|
678
|
+
}
|
|
616
679
|
} else safeSetText(form, `SSR1`, "Not yet reviewed");
|
|
617
680
|
|
|
618
681
|
if (payload.meta.report_type != "FullReport") {
|