@bento-core/table 1.0.1-ccdiintegrated.1 → 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') {
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) === ']') {
@@ -162,7 +188,18 @@ function downloadJson(tableData, table, downloadFileName) {
162
188
  let survivalStatus = entry.last_known_survival_status;
163
189
  let sampleId = entry.sample_id;
164
190
  let dataCategory = entry.data_category;
191
+ let participantId = entry.participant_id;
192
+ let anatomicSite = entry.anatomic_site;
193
+ let sampleDescription = entry.sample_description;
194
+ let percentTumor = entry.percent_tumor;
195
+ let percentNecrosis = entry.percent_necrosis;
196
+ let consentCodes = entry.consent_codes;
165
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
+ });
166
203
  if (survivalStatus && survivalStatus.toString().charAt(0) === '[' && survivalStatus.toString().charAt(survivalStatus.toString().length - 1) === ']') {
167
204
  survivalStatus = survivalStatus.toString().substring(1, survivalStatus.length - 1);
168
205
  toReturn['Last Known Survival Status'] = survivalStatus;
@@ -175,6 +212,30 @@ function downloadJson(tableData, table, downloadFileName) {
175
212
  dataCategory = dataCategory.toString().substring(1, dataCategory.length - 1);
176
213
  toReturn['Data Category'] = dataCategory;
177
214
  }
215
+ if (participantId && participantId.toString().charAt(0) === '[' && participantId.toString().charAt(participantId.toString().length - 1) === ']') {
216
+ participantId = participantId.toString().substring(1, participantId.length - 1);
217
+ toReturn['Participant ID'] = participantId;
218
+ }
219
+ if (anatomicSite && anatomicSite.toString().charAt(0) === '[' && anatomicSite.toString().charAt(anatomicSite.toString().length - 1) === ']') {
220
+ anatomicSite = anatomicSite.toString().substring(1, anatomicSite.length - 1);
221
+ toReturn['Anatomic Site'] = anatomicSite;
222
+ }
223
+ if (sampleDescription && sampleDescription.toString().charAt(0) === '[' && sampleDescription.toString().charAt(sampleDescription.toString().length - 1) === ']') {
224
+ sampleDescription = sampleDescription.toString().substring(1, sampleDescription.length - 1);
225
+ toReturn['Sample Description'] = sampleDescription;
226
+ }
227
+ if (percentTumor && percentTumor.toString().charAt(0) === '[' && percentTumor.toString().charAt(percentTumor.toString().length - 1) === ']') {
228
+ percentTumor = percentTumor.toString().substring(1, percentTumor.length - 1);
229
+ toReturn['Percent Tumor'] = percentTumor;
230
+ }
231
+ if (percentNecrosis && percentNecrosis.toString().charAt(0) === '[' && percentNecrosis.toString().charAt(percentNecrosis.toString().length - 1) === ']') {
232
+ percentNecrosis = percentNecrosis.toString().substring(1, percentNecrosis.length - 1);
233
+ toReturn['Percent Necrosis'] = percentNecrosis;
234
+ }
235
+ if (consentCodes && consentCodes.toString().charAt(0) === '[' && consentCodes.toString().charAt(consentCodes.toString().length - 1) === ']') {
236
+ consentCodes = consentCodes.toString().substring(1, consentCodes.length - 1);
237
+ toReturn['Consent Codes'] = consentCodes;
238
+ }
178
239
  toDelete.forEach(column => delete toReturn[column.dataField]);
179
240
  return toReturn;
180
241
  });
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.1-ccdiintegrated.1",
4
- "description": "",
3
+ "version": "1.0.1-ccdiintegrated.3",
5
4
  "homepage": "https://github.com/CBIIT/bento-frontend#readme",
6
5
  "bugs": {
7
6
  "url": "https://github.com/CBIIT/bento-frontend/issues"
@@ -39,5 +38,6 @@
39
38
  },
40
39
  "publishConfig": {
41
40
  "access": "public"
42
- }
41
+ },
42
+ "description": ""
43
43
  }
@@ -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') {
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) === ']') {
@@ -103,8 +137,20 @@ export function downloadJson(tableData, table, downloadFileName) {
103
137
  let survivalStatus = entry.last_known_survival_status;
104
138
  let sampleId = entry.sample_id;
105
139
  let dataCategory = entry.data_category;
140
+ let participantId = entry.participant_id;
141
+ let anatomicSite = entry.anatomic_site;
142
+ let sampleDescription = entry.sample_description;
143
+ let percentTumor = entry.percent_tumor;
144
+ let percentNecrosis = entry.percent_necrosis;
145
+ let consentCodes = entry.consent_codes;
106
146
  const toReturn = { ...entry };
107
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
+
108
154
  if (survivalStatus && survivalStatus.toString().charAt(0) === '[' && survivalStatus.toString().charAt(survivalStatus.toString().length - 1) === ']') {
109
155
  survivalStatus = survivalStatus.toString().substring(1, survivalStatus.length - 1);
110
156
  toReturn['Last Known Survival Status'] = survivalStatus;
@@ -117,6 +163,31 @@ export function downloadJson(tableData, table, downloadFileName) {
117
163
  dataCategory = dataCategory.toString().substring(1, dataCategory.length - 1);
118
164
  toReturn['Data Category'] = dataCategory;
119
165
  }
166
+ if (participantId && participantId.toString().charAt(0) === '[' && participantId.toString().charAt(participantId.toString().length - 1) === ']') {
167
+ participantId = participantId.toString().substring(1, participantId.length - 1);
168
+ toReturn['Participant ID'] = participantId;
169
+ }
170
+ if (anatomicSite && anatomicSite.toString().charAt(0) === '[' && anatomicSite.toString().charAt(anatomicSite.toString().length - 1) === ']') {
171
+ anatomicSite = anatomicSite.toString().substring(1, anatomicSite.length - 1);
172
+ toReturn['Anatomic Site'] = anatomicSite;
173
+ }
174
+ if (sampleDescription && sampleDescription.toString().charAt(0) === '[' && sampleDescription.toString().charAt(sampleDescription.toString().length - 1) === ']') {
175
+ sampleDescription = sampleDescription.toString().substring(1, sampleDescription.length - 1);
176
+ toReturn['Sample Description'] = sampleDescription;
177
+ }
178
+ if (percentTumor && percentTumor.toString().charAt(0) === '[' && percentTumor.toString().charAt(percentTumor.toString().length - 1) === ']') {
179
+ percentTumor = percentTumor.toString().substring(1, percentTumor.length - 1);
180
+ toReturn['Percent Tumor'] = percentTumor;
181
+ }
182
+ if (percentNecrosis && percentNecrosis.toString().charAt(0) === '[' && percentNecrosis.toString().charAt(percentNecrosis.toString().length - 1) === ']') {
183
+ percentNecrosis = percentNecrosis.toString().substring(1, percentNecrosis.length - 1);
184
+ toReturn['Percent Necrosis'] = percentNecrosis;
185
+ }
186
+ if (consentCodes && consentCodes.toString().charAt(0) === '[' && consentCodes.toString().charAt(consentCodes.toString().length - 1) === ']') {
187
+ consentCodes = consentCodes.toString().substring(1, consentCodes.length - 1);
188
+ toReturn['Consent Codes'] = consentCodes;
189
+ }
190
+
120
191
  toDelete.forEach((column) => delete toReturn[column.dataField]);
121
192
  return toReturn;
122
193
  });