@squaredr/fieldcraft-pro 1.7.0 → 1.8.0

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.
@@ -305,6 +305,121 @@ function requireLicense(Component, featureName) {
305
305
  LicenseGated.displayName = `requireLicense(${Component.displayName || Component.name || "Component"})`;
306
306
  return LicenseGated;
307
307
  }
308
+ function formatDuration(ms) {
309
+ if (ms == null) return "\u2014";
310
+ const totalSeconds = Math.round(ms / 1e3);
311
+ if (totalSeconds < 60) return `${totalSeconds}s`;
312
+ const minutes = Math.floor(totalSeconds / 60);
313
+ const seconds = totalSeconds % 60;
314
+ return `${minutes}m ${seconds}s`;
315
+ }
316
+ function countAnswered(values) {
317
+ let count = 0;
318
+ for (const v of Object.values(values)) {
319
+ if (v !== void 0 && v !== null && v !== "") count++;
320
+ }
321
+ return count;
322
+ }
323
+ function getTotalFieldCount(schema) {
324
+ let count = 0;
325
+ for (const section of schema.sections) {
326
+ for (const q of section.questions) {
327
+ if (!DISPLAY_ONLY_TYPES.has(q.type)) count++;
328
+ }
329
+ }
330
+ return count;
331
+ }
332
+ function ResponseTable({
333
+ schema,
334
+ responses,
335
+ onRowClick,
336
+ selectable,
337
+ selectedIds,
338
+ onToggleSelect,
339
+ onSelectAll
340
+ }) {
341
+ const totalFields = getTotalFieldCount(schema);
342
+ const allPageSelected = selectable && responses.length > 0 && responses.every(
343
+ (r) => r.sessionToken && selectedIds?.has(r.sessionToken)
344
+ );
345
+ const colCount = 4 + (selectable ? 1 : 0);
346
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full border-collapse text-[13px]", children: [
347
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "bg-muted", children: [
348
+ selectable && /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-3 py-2 w-8 border-b-2 border-border", children: /* @__PURE__ */ jsxRuntime.jsx(
349
+ "input",
350
+ {
351
+ type: "checkbox",
352
+ checked: allPageSelected,
353
+ onChange: () => onSelectAll?.(),
354
+ className: "accent-primary"
355
+ }
356
+ ) }),
357
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-3 py-2 text-left font-semibold text-foreground border-b-2 border-border whitespace-nowrap", children: "Submitted" }),
358
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-3 py-2 text-left font-semibold text-foreground border-b-2 border-border whitespace-nowrap", children: "Completion Time" }),
359
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-3 py-2 text-left font-semibold text-foreground border-b-2 border-border whitespace-nowrap", children: "Fields Answered" }),
360
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-3 py-2 text-left font-semibold text-foreground border-b-2 border-border whitespace-nowrap", children: "Score" })
361
+ ] }) }),
362
+ /* @__PURE__ */ jsxRuntime.jsxs("tbody", { children: [
363
+ responses.map((response, idx) => {
364
+ const answered = countAnswered(response.values);
365
+ return /* @__PURE__ */ jsxRuntime.jsxs(
366
+ "tr",
367
+ {
368
+ onClick: () => onRowClick?.(response),
369
+ className: onRowClick ? "cursor-pointer border-b border-border hover:bg-accent transition-colors" : "border-b border-border",
370
+ children: [
371
+ selectable && /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2 w-8", children: /* @__PURE__ */ jsxRuntime.jsx(
372
+ "input",
373
+ {
374
+ type: "checkbox",
375
+ checked: !!(response.sessionToken && selectedIds?.has(response.sessionToken)),
376
+ onChange: (e) => {
377
+ e.stopPropagation();
378
+ if (response.sessionToken) onToggleSelect?.(response.sessionToken);
379
+ },
380
+ onClick: (e) => e.stopPropagation(),
381
+ className: "accent-primary"
382
+ }
383
+ ) }),
384
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2 text-foreground whitespace-nowrap", children: new Date(response.submittedAt).toLocaleString() }),
385
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2 text-foreground whitespace-nowrap", children: formatDuration(response.completionTimeMs) }),
386
+ /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-3 py-2 text-foreground whitespace-nowrap", children: [
387
+ answered,
388
+ "/",
389
+ totalFields
390
+ ] }),
391
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2 text-foreground whitespace-nowrap", children: response.totalScore ?? "\u2014" })
392
+ ]
393
+ },
394
+ response.sessionToken || idx
395
+ );
396
+ }),
397
+ responses.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx(
398
+ "td",
399
+ {
400
+ colSpan: colCount,
401
+ className: "px-3 py-8 text-center text-muted-foreground",
402
+ children: "No responses yet"
403
+ }
404
+ ) })
405
+ ] })
406
+ ] }) });
407
+ }
408
+ var DISPLAY_ONLY_TYPES = /* @__PURE__ */ new Set([
409
+ "info-block",
410
+ "info_block",
411
+ "section-header",
412
+ "page-break",
413
+ "image",
414
+ "divider",
415
+ "spacer",
416
+ "video",
417
+ "rich-text",
418
+ "welcome-screen",
419
+ "thank-you-screen",
420
+ "hidden",
421
+ "calculated"
422
+ ]);
308
423
 
309
424
  // src/response-viewer/clinical-display-data.ts
310
425
  var BODY_REGION_LABELS = {
@@ -442,166 +557,6 @@ function getScoreSeverity(instrumentKey, score) {
442
557
  if (!thresholds) return void 0;
443
558
  return thresholds.find((t) => score >= t.min && score <= t.max);
444
559
  }
445
- function ResponseTable({
446
- schema,
447
- responses,
448
- onRowClick,
449
- selectable,
450
- selectedIds,
451
- onToggleSelect,
452
- onSelectAll
453
- }) {
454
- const questions = getAllQuestions(schema);
455
- const allPageSelected = selectable && responses.length > 0 && responses.every(
456
- (r) => r.sessionToken && selectedIds?.has(r.sessionToken)
457
- );
458
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full border-collapse text-[13px]", children: [
459
- /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "bg-muted", children: [
460
- selectable && /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-3 py-2 w-8 border-b-2 border-border", children: /* @__PURE__ */ jsxRuntime.jsx(
461
- "input",
462
- {
463
- type: "checkbox",
464
- checked: allPageSelected,
465
- onChange: () => onSelectAll?.(),
466
- className: "accent-primary"
467
- }
468
- ) }),
469
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-3 py-2 text-left font-semibold text-foreground border-b-2 border-border whitespace-nowrap", children: "Submitted" }),
470
- questions.map((q) => /* @__PURE__ */ jsxRuntime.jsx(
471
- "th",
472
- {
473
- className: "px-3 py-2 text-left font-semibold text-foreground border-b-2 border-border whitespace-nowrap",
474
- children: q.label
475
- },
476
- q.id
477
- )),
478
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-3 py-2 text-left font-semibold text-foreground border-b-2 border-border whitespace-nowrap", children: "Score" })
479
- ] }) }),
480
- /* @__PURE__ */ jsxRuntime.jsxs("tbody", { children: [
481
- responses.map((response, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
482
- "tr",
483
- {
484
- onClick: () => onRowClick?.(response),
485
- className: onRowClick ? "cursor-pointer border-b border-border hover:bg-accent transition-colors" : "border-b border-border",
486
- children: [
487
- selectable && /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2 w-8", children: /* @__PURE__ */ jsxRuntime.jsx(
488
- "input",
489
- {
490
- type: "checkbox",
491
- checked: !!(response.sessionToken && selectedIds?.has(response.sessionToken)),
492
- onChange: (e) => {
493
- e.stopPropagation();
494
- if (response.sessionToken) onToggleSelect?.(response.sessionToken);
495
- },
496
- onClick: (e) => e.stopPropagation(),
497
- className: "accent-primary"
498
- }
499
- ) }),
500
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2 text-foreground max-w-50 overflow-hidden text-ellipsis whitespace-nowrap", children: new Date(response.submittedAt).toLocaleString() }),
501
- questions.map((q) => /* @__PURE__ */ jsxRuntime.jsx(
502
- "td",
503
- {
504
- className: "px-3 py-2 text-foreground max-w-50 overflow-hidden text-ellipsis whitespace-nowrap",
505
- children: formatCellValue(response.values[q.id], q.type)
506
- },
507
- q.id
508
- )),
509
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2 text-foreground max-w-50 overflow-hidden text-ellipsis whitespace-nowrap", children: response.totalScore ?? "\u2014" })
510
- ]
511
- },
512
- response.sessionToken || idx
513
- )),
514
- responses.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx(
515
- "td",
516
- {
517
- colSpan: questions.length + 2 + (selectable ? 1 : 0),
518
- className: "px-3 py-8 text-center text-muted-foreground",
519
- children: "No responses yet"
520
- }
521
- ) })
522
- ] })
523
- ] }) });
524
- }
525
- function getAllQuestions(schema) {
526
- const questions = [];
527
- for (const section of schema.sections) {
528
- for (const q of section.questions) {
529
- if (q.type === "info-block" || q.type === "section-header" || q.type === "page-break") {
530
- continue;
531
- }
532
- questions.push(q);
533
- }
534
- }
535
- return questions;
536
- }
537
- function formatCellValue(value, type) {
538
- if (value == null) return "\u2014";
539
- if (type) {
540
- switch (type) {
541
- case "vitals_entry": {
542
- if (typeof value !== "object" || value === null) break;
543
- const v = value;
544
- const parts = [];
545
- if (v.systolicBp && v.diastolicBp) parts.push(`BP ${v.systolicBp}/${v.diastolicBp}`);
546
- if (v.heartRate) parts.push(`HR ${v.heartRate}`);
547
- if (v.temperature) parts.push(`${v.temperature}\xB0F`);
548
- if (v.oxygenSaturation) parts.push(`SpO\u2082 ${v.oxygenSaturation}%`);
549
- return parts.length > 0 ? parts.join(", ") : "\u2014";
550
- }
551
- case "medication_list":
552
- if (Array.isArray(value)) return `${value.length} medication${value.length !== 1 ? "s" : ""}`;
553
- break;
554
- case "allergy_list":
555
- if (Array.isArray(value)) return `${value.length} allerg${value.length !== 1 ? "ies" : "y"}`;
556
- break;
557
- case "body_diagram":
558
- if (Array.isArray(value)) {
559
- const labels = value.map((id) => BODY_REGION_LABELS[id] ?? id);
560
- return labels.join(", ");
561
- }
562
- break;
563
- case "pain_scale":
564
- if (typeof value === "number") return `${value}/10`;
565
- break;
566
- case "bmi_calculator": {
567
- if (typeof value !== "object" || value === null) break;
568
- const d = value;
569
- if (d.bmi != null) return `BMI ${d.bmi}`;
570
- break;
571
- }
572
- case "payment": {
573
- if (typeof value !== "object" || value === null) break;
574
- const p = value;
575
- const status = p.status;
576
- return status ? status.charAt(0).toUpperCase() + status.slice(1) : "\u2014";
577
- }
578
- case "insurance_card": {
579
- if (typeof value !== "object" || value === null) break;
580
- const ins = value;
581
- const parts = [ins.carrierId, ins.planName].filter(Boolean);
582
- return parts.length > 0 ? parts.join(" \u2014 ") : "Card uploaded";
583
- }
584
- case "legal_name": {
585
- if (typeof value !== "object" || value === null) break;
586
- const n = value;
587
- return [n.first, n.last].filter(Boolean).join(" ") || "\u2014";
588
- }
589
- case "address": {
590
- if (typeof value !== "object" || value === null) break;
591
- const a = value;
592
- return [a.city, a.state].filter(Boolean).join(", ") || "\u2014";
593
- }
594
- case "consent":
595
- return value === true || value === "true" || value === "agreed" ? "Agreed" : "Not agreed";
596
- case "signature":
597
- return typeof value === "string" && value.startsWith("data:image") ? "Signed" : "\u2014";
598
- }
599
- }
600
- if (typeof value === "boolean") return value ? "Yes" : "No";
601
- if (Array.isArray(value)) return value.join(", ");
602
- if (typeof value === "object") return JSON.stringify(value);
603
- return String(value);
604
- }
605
560
  function ResponseCard({
606
561
  response,
607
562
  fields,
@@ -1599,13 +1554,26 @@ function exportToJson(responses, filename = "responses.json") {
1599
1554
  const content = JSON.stringify(responses, null, 2);
1600
1555
  downloadBlob(content, filename, "application/json;charset=utf-8;");
1601
1556
  }
1557
+ var DISPLAY_ONLY_TYPES2 = /* @__PURE__ */ new Set([
1558
+ "info-block",
1559
+ "info_block",
1560
+ "section-header",
1561
+ "page-break",
1562
+ "image",
1563
+ "divider",
1564
+ "spacer",
1565
+ "video",
1566
+ "rich-text",
1567
+ "welcome-screen",
1568
+ "thank-you-screen",
1569
+ "hidden",
1570
+ "calculated"
1571
+ ]);
1602
1572
  function getExportableQuestions(schema) {
1603
1573
  const questions = [];
1604
1574
  for (const section of schema.sections) {
1605
1575
  for (const q of section.questions) {
1606
- if (q.type === "info-block" || q.type === "section-header" || q.type === "page-break") {
1607
- continue;
1608
- }
1576
+ if (DISPLAY_ONLY_TYPES2.has(q.type)) continue;
1609
1577
  questions.push(q);
1610
1578
  }
1611
1579
  }
@@ -1671,6 +1639,10 @@ function formatExportValue(value, type) {
1671
1639
  return String(value);
1672
1640
  }
1673
1641
  function escapeCsvField(field) {
1642
+ const first = field.charAt(0);
1643
+ if (first === "=" || first === "+" || first === "-" || first === "@" || first === " " || first === "\r") {
1644
+ field = `'${field}`;
1645
+ }
1674
1646
  if (field.includes(",") || field.includes('"') || field.includes("\n")) {
1675
1647
  return `"${field.replace(/"/g, '""')}"`;
1676
1648
  }
@@ -1685,7 +1657,7 @@ function downloadBlob(content, filename, mimeType) {
1685
1657
  document.body.appendChild(link);
1686
1658
  link.click();
1687
1659
  document.body.removeChild(link);
1688
- URL.revokeObjectURL(url);
1660
+ setTimeout(() => URL.revokeObjectURL(url), 1e4);
1689
1661
  }
1690
1662
 
1691
1663
  // src/response-viewer/pagination-utils.ts
@@ -1921,9 +1893,12 @@ function ResponseViewerInner({
1921
1893
  [responses, searchQuery, schema]
1922
1894
  );
1923
1895
  const isFiltered = hasActiveFilters(filterState);
1924
- const filteredResponses = applyFilters(searchedResponses, filterState);
1896
+ const filteredResponses = react.useMemo(
1897
+ () => applyFilters(searchedResponses, filterState),
1898
+ [searchedResponses, filterState]
1899
+ );
1925
1900
  const pag = paginate(filteredResponses, currentPage, effectivePageSize);
1926
- const questions = getAllQuestions2(schema);
1901
+ const questions = getAllQuestions(schema);
1927
1902
  const isSelectable = selectable && (!!onBulkDelete || !!onBulkExport);
1928
1903
  function handleSelect(response) {
1929
1904
  setSelectedResponse(response);
@@ -2025,7 +2000,7 @@ function ResponseViewerInner({
2025
2000
  });
2026
2001
  }
2027
2002
  function getFields(response) {
2028
- return questions.map((q) => ({
2003
+ return questions.filter((q) => response.values[q.id] !== void 0).map((q) => ({
2029
2004
  questionId: q.id,
2030
2005
  label: q.label,
2031
2006
  type: q.type,
@@ -2178,10 +2153,10 @@ function ResponseViewerInner({
2178
2153
  className: "h-7 text-xs",
2179
2154
  onClick: () => {
2180
2155
  const csvFilename = filename ? filename.replace(/\.\w+$/, ".csv") : "responses.csv";
2181
- exportToCsv(schema, responses, csvFilename, { dateFormat, columnLabels });
2182
- onExport?.("csv", responses.length);
2156
+ exportToCsv(schema, filteredResponses, csvFilename, { dateFormat, columnLabels });
2157
+ onExport?.("csv", filteredResponses.length);
2183
2158
  },
2184
- disabled: responses.length === 0,
2159
+ disabled: filteredResponses.length === 0,
2185
2160
  children: "Export CSV"
2186
2161
  }
2187
2162
  ),
@@ -2193,10 +2168,10 @@ function ResponseViewerInner({
2193
2168
  className: "h-7 text-xs",
2194
2169
  onClick: () => {
2195
2170
  const jsonFilename = filename ? filename.replace(/\.\w+$/, ".json") : "responses.json";
2196
- exportToJson(responses, jsonFilename);
2197
- onExport?.("json", responses.length);
2171
+ exportToJson(filteredResponses, jsonFilename);
2172
+ onExport?.("json", filteredResponses.length);
2198
2173
  },
2199
- disabled: responses.length === 0,
2174
+ disabled: filteredResponses.length === 0,
2200
2175
  children: "Export JSON"
2201
2176
  }
2202
2177
  )
@@ -2477,13 +2452,26 @@ function ResponseViewerInner({
2477
2452
  }
2478
2453
  );
2479
2454
  }
2480
- function getAllQuestions2(schema) {
2455
+ var DISPLAY_ONLY_TYPES3 = /* @__PURE__ */ new Set([
2456
+ "info-block",
2457
+ "info_block",
2458
+ "section-header",
2459
+ "page-break",
2460
+ "image",
2461
+ "divider",
2462
+ "spacer",
2463
+ "video",
2464
+ "rich-text",
2465
+ "welcome-screen",
2466
+ "thank-you-screen",
2467
+ "hidden",
2468
+ "calculated"
2469
+ ]);
2470
+ function getAllQuestions(schema) {
2481
2471
  const questions = [];
2482
2472
  for (const section of schema.sections) {
2483
2473
  for (const q of section.questions) {
2484
- if (q.type === "info-block" || q.type === "section-header" || q.type === "page-break") {
2485
- continue;
2486
- }
2474
+ if (DISPLAY_ONLY_TYPES3.has(q.type)) continue;
2487
2475
  questions.push(q);
2488
2476
  }
2489
2477
  }
@@ -1,3 +1,3 @@
1
- export { ResponseViewer } from '../chunk-GZIV2XAD.mjs';
1
+ export { ResponseViewer } from '../chunk-MLP5EDWP.mjs';
2
2
  import '../chunk-QQ4JZGTD.mjs';
3
3
  import '../chunk-4MMKB2EW.mjs';