@bento-core/table 1.0.1-ccdiintegrated.2 → 1.0.1-ccdiintegrated.3

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.
@@ -7,6 +7,7 @@ exports.convertToCSV = convertToCSV;
7
7
  exports.createFileName = createFileName;
8
8
  exports.downloadCSV = downloadCSV;
9
9
  exports.downloadJson = downloadJson;
10
+ exports.formatAgeForDownload = formatAgeForDownload;
10
11
  var _Dataformat = require("./Dataformat");
11
12
  var _Types = require("./Types");
12
13
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -14,6 +15,31 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
14
15
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
16
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
16
17
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
+ const AGE_FIELDS = new Set(['age_at_diagnosis', 'participant_age_at_collection', 'age_at_treatment_start', 'age_at_treatment_end', 'age_at_response', 'age_at_last_known_survival_status', 'age_at_event_free_survival_status']);
19
+
20
+ /**
21
+ * Sentinel OpenSearch age values (-999) become "Not Reported" for CSV/JSON download.
22
+ * Supports scalars, arrays (files table), and bracketed strings.
23
+ */
24
+ function formatAgeForDownload(value) {
25
+ if (Array.isArray(value)) {
26
+ if (value.length === 0) {
27
+ return 'Not Reported';
28
+ }
29
+ return value.map(item => formatAgeForDownload(item)).join('; ');
30
+ }
31
+ if (value === -999 || value === '-999' || value == null || value === '') {
32
+ return 'Not Reported';
33
+ }
34
+ if (typeof value === 'string' && value.startsWith('[') && value.endsWith(']')) {
35
+ const inner = value.slice(1, -1).trim();
36
+ if (!inner) {
37
+ return 'Not Reported';
38
+ }
39
+ return inner.split(',').map(item => formatAgeForDownload(item.trim())).join('; ');
40
+ }
41
+ return String(value);
42
+ }
17
43
  function createFileName(fileName, type) {
18
44
  const date = new Date();
19
45
  const yyyy = date.getFullYear();
@@ -54,13 +80,13 @@ function convertToCSV(jsonse, keysToInclude, header) {
54
80
  if (line !== '') line += ',';
55
81
  if (keyName === 'file_size') {
56
82
  line += entry[keyName] !== null ? "\"".concat((0, _Dataformat.formatBytes)(entry[keyName]), "\"") : ' ';
57
- } else if (keyName === 'age_at_diagnosis' || keyName === 'participant_age_at_collection') {
58
- if (entry[keyName] === -999) {
59
- line += 'Not Reported';
83
+ } else if (AGE_FIELDS.has(keyName)) {
84
+ if (entry[keyName] == null) {
85
+ line += ' ';
60
86
  } else {
61
- line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
87
+ line += "\"".concat(formatAgeForDownload(entry[keyName]), "\"");
62
88
  }
63
- } else if (keyName === 'last_known_survival_status' || keyName === 'sample_id' || keyName === 'data_category' || keyName === 'participant_id' || keyName === 'anatomic_site' || keyName === 'participant_age_at_collection' || keyName === 'sample_description' || keyName === 'percent_tumor' || keyName === 'percent_necrosis' || keyName === 'consent_codes') {
89
+ } else if (keyName === 'last_known_survival_status' || keyName === 'sample_id' || keyName === 'data_category' || keyName === 'participant_id' || keyName === 'anatomic_site' || keyName === 'sample_description' || keyName === 'percent_tumor' || keyName === 'percent_necrosis' || keyName === 'consent_codes') {
64
90
  if (!entry[keyName] || entry[keyName] === '[]') {
65
91
  line += '';
66
92
  } else if (entry[keyName].toString().charAt(0) === '[' && entry[keyName].toString().charAt(entry[keyName].toString().length - 1) === ']') {
@@ -164,12 +190,16 @@ function downloadJson(tableData, table, downloadFileName) {
164
190
  let dataCategory = entry.data_category;
165
191
  let participantId = entry.participant_id;
166
192
  let anatomicSite = entry.anatomic_site;
167
- let ageAtCollection = entry.participant_age_at_collection;
168
193
  let sampleDescription = entry.sample_description;
169
194
  let percentTumor = entry.percent_tumor;
170
195
  let percentNecrosis = entry.percent_necrosis;
171
196
  let consentCodes = entry.consent_codes;
172
197
  const toReturn = _objectSpread({}, entry);
198
+ AGE_FIELDS.forEach(field => {
199
+ if (Object.prototype.hasOwnProperty.call(entry, field) && entry[field] != null) {
200
+ toReturn[field] = formatAgeForDownload(entry[field]);
201
+ }
202
+ });
173
203
  if (survivalStatus && survivalStatus.toString().charAt(0) === '[' && survivalStatus.toString().charAt(survivalStatus.toString().length - 1) === ']') {
174
204
  survivalStatus = survivalStatus.toString().substring(1, survivalStatus.length - 1);
175
205
  toReturn['Last Known Survival Status'] = survivalStatus;
@@ -190,10 +220,6 @@ function downloadJson(tableData, table, downloadFileName) {
190
220
  anatomicSite = anatomicSite.toString().substring(1, anatomicSite.length - 1);
191
221
  toReturn['Anatomic Site'] = anatomicSite;
192
222
  }
193
- if (ageAtCollection && ageAtCollection.toString().charAt(0) === '[' && ageAtCollection.toString().charAt(ageAtCollection.toString().length - 1) === ']') {
194
- ageAtCollection = ageAtCollection.toString().substring(1, ageAtCollection.length - 1);
195
- toReturn['Age at Collection'] = ageAtCollection;
196
- }
197
223
  if (sampleDescription && sampleDescription.toString().charAt(0) === '[' && sampleDescription.toString().charAt(sampleDescription.toString().length - 1) === ']') {
198
224
  sampleDescription = sampleDescription.toString().substring(1, sampleDescription.length - 1);
199
225
  toReturn['Sample Description'] = sampleDescription;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.1-ccdiintegrated.2",
3
+ "version": "1.0.1-ccdiintegrated.3",
4
4
  "homepage": "https://github.com/CBIIT/bento-frontend#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/CBIIT/bento-frontend/issues"
@@ -1,6 +1,40 @@
1
1
  import { formatBytes, formatColumnValues } from './Dataformat';
2
2
  import { actionCellTypes, notIncludedCellStyle } from './Types';
3
3
 
4
+ const AGE_FIELDS = new Set([
5
+ 'age_at_diagnosis',
6
+ 'participant_age_at_collection',
7
+ 'age_at_treatment_start',
8
+ 'age_at_treatment_end',
9
+ 'age_at_response',
10
+ 'age_at_last_known_survival_status',
11
+ 'age_at_event_free_survival_status',
12
+ ]);
13
+
14
+ /**
15
+ * Sentinel OpenSearch age values (-999) become "Not Reported" for CSV/JSON download.
16
+ * Supports scalars, arrays (files table), and bracketed strings.
17
+ */
18
+ export function formatAgeForDownload(value) {
19
+ if (Array.isArray(value)) {
20
+ if (value.length === 0) {
21
+ return 'Not Reported';
22
+ }
23
+ return value.map((item) => formatAgeForDownload(item)).join('; ');
24
+ }
25
+ if (value === -999 || value === '-999' || value == null || value === '') {
26
+ return 'Not Reported';
27
+ }
28
+ if (typeof value === 'string' && value.startsWith('[') && value.endsWith(']')) {
29
+ const inner = value.slice(1, -1).trim();
30
+ if (!inner) {
31
+ return 'Not Reported';
32
+ }
33
+ return inner.split(',').map((item) => formatAgeForDownload(item.trim())).join('; ');
34
+ }
35
+ return String(value);
36
+ }
37
+
4
38
  export function createFileName(fileName, type) {
5
39
  const date = new Date();
6
40
  const yyyy = date.getFullYear();
@@ -40,13 +74,13 @@ export function convertToCSV(jsonse, keysToInclude, header) {
40
74
  if (line !== '') line += ',';
41
75
  if (keyName === 'file_size') {
42
76
  line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
43
- } else if (keyName === 'age_at_diagnosis' || keyName === 'participant_age_at_collection') {
44
- if (entry[keyName] === -999) {
45
- line += 'Not Reported';
77
+ } else if (AGE_FIELDS.has(keyName)) {
78
+ if (entry[keyName] == null) {
79
+ line += ' ';
46
80
  } else {
47
- line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
81
+ line += `"${formatAgeForDownload(entry[keyName])}"`;
48
82
  }
49
- } else if (keyName === 'last_known_survival_status' || keyName === 'sample_id' || keyName === 'data_category' || keyName === 'participant_id' || keyName === 'anatomic_site' || keyName === 'participant_age_at_collection' || keyName === 'sample_description' || keyName === 'percent_tumor' || keyName === 'percent_necrosis' || keyName === 'consent_codes') {
83
+ } else if (keyName === 'last_known_survival_status' || keyName === 'sample_id' || keyName === 'data_category' || keyName === 'participant_id' || keyName === 'anatomic_site' || keyName === 'sample_description' || keyName === 'percent_tumor' || keyName === 'percent_necrosis' || keyName === 'consent_codes') {
50
84
  if (!entry[keyName] || entry[keyName] === '[]') {
51
85
  line += '';
52
86
  } else if (entry[keyName].toString().charAt(0) === '[' && entry[keyName].toString().charAt(entry[keyName].toString().length - 1) === ']') {
@@ -105,13 +139,18 @@ export function downloadJson(tableData, table, downloadFileName) {
105
139
  let dataCategory = entry.data_category;
106
140
  let participantId = entry.participant_id;
107
141
  let anatomicSite = entry.anatomic_site;
108
- let ageAtCollection = entry.participant_age_at_collection;
109
142
  let sampleDescription = entry.sample_description;
110
143
  let percentTumor = entry.percent_tumor;
111
144
  let percentNecrosis = entry.percent_necrosis;
112
145
  let consentCodes = entry.consent_codes;
113
146
  const toReturn = { ...entry };
114
147
 
148
+ AGE_FIELDS.forEach((field) => {
149
+ if (Object.prototype.hasOwnProperty.call(entry, field) && entry[field] != null) {
150
+ toReturn[field] = formatAgeForDownload(entry[field]);
151
+ }
152
+ });
153
+
115
154
  if (survivalStatus && survivalStatus.toString().charAt(0) === '[' && survivalStatus.toString().charAt(survivalStatus.toString().length - 1) === ']') {
116
155
  survivalStatus = survivalStatus.toString().substring(1, survivalStatus.length - 1);
117
156
  toReturn['Last Known Survival Status'] = survivalStatus;
@@ -132,10 +171,6 @@ export function downloadJson(tableData, table, downloadFileName) {
132
171
  anatomicSite = anatomicSite.toString().substring(1, anatomicSite.length - 1);
133
172
  toReturn['Anatomic Site'] = anatomicSite;
134
173
  }
135
- if (ageAtCollection && ageAtCollection.toString().charAt(0) === '[' && ageAtCollection.toString().charAt(ageAtCollection.toString().length - 1) === ']') {
136
- ageAtCollection = ageAtCollection.toString().substring(1, ageAtCollection.length - 1);
137
- toReturn['Age at Collection'] = ageAtCollection;
138
- }
139
174
  if (sampleDescription && sampleDescription.toString().charAt(0) === '[' && sampleDescription.toString().charAt(sampleDescription.toString().length - 1) === ']') {
140
175
  sampleDescription = sampleDescription.toString().substring(1, sampleDescription.length - 1);
141
176
  toReturn['Sample Description'] = sampleDescription;