generio-sdk 1.0.92 → 1.0.94

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/README.md CHANGED
@@ -1,5 +1,3 @@
1
1
  # generio-sdk
2
2
 
3
- SDK library for Generio.
4
-
5
- > **⚠️ This package is in active development**
3
+ SDK library for generio
package/dist/index.cjs CHANGED
@@ -1 +1,334 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`uuid`);c=s(c);let l=function(e){return e[e.NewLine=0]=`NewLine`,e[e.Text=1]=`Text`,e[e.BoldText=2]=`BoldText`,e[e.CheckBox=3]=`CheckBox`,e[e.DropDownList=4]=`DropDownList`,e[e.InputText=5]=`InputText`,e[e.ConditionAndOr=6]=`ConditionAndOr`,e[e.Function=7]=`Function`,e[e.Condition=8]=`Condition`,e[e.Button=9]=`Button`,e[e.Append=10]=`Append`,e[e.DigitBox=11]=`DigitBox`,e[e.Merge=12]=`Merge`,e[e.Listing=13]=`Listing`,e[e.Bilateral=14]=`Bilateral`,e[e.Matrix=15]=`Matrix`,e[e.RememberedText=17]=`RememberedText`,e[e.InputTable=18]=`InputTable`,e[e.AppendDiagnose=19]=`AppendDiagnose`,e[e.MoveByExtParams=20]=`MoveByExtParams`,e}({});var u=class{constructor(){}ConvertExaminationDataToGeneratorRows(e){let t=[],n=0,r=0,i={subRows:[]},a=[],o=[];do{do{do{if(e[n]?.formType==l.NewLine)break;if(e[n])switch(e[n].formType){case l.DropDownList:{let t=this.CreateColumnFromExaminationData(e[n]);t.elementIndex=n;let r=[],i=1;do{let a=this.CreateColumnFromExaminationData(e[n]);a.elementIndex=n;let o=e[n]?.formValue?.trim();i===1&&o&&!o.startsWith(`-`)&&!o.endsWith(`-`)&&(t.preselected=!0),r.push(a),n++,i++}while(e[n]?.formType==l.DropDownList&&n<e.length);t.elementSelectOptions=r,o.push(t),n--;break}case l.Text:case l.Append:if(e[n]?.formValue){let t=this.CreateColumnFromExaminationData(e[n]);t.elementIndex=n,o.push(t)}break;case l.InputText:{let t=this.CreateColumnFromExaminationData(e[n]);t.elementIndex=n,t.isDistance=this.IsDistanceDefinition(e[n+1]?.formValue??``),o.push(t);break}case l.BoldText:case l.CheckBox:case l.Button:case l.DigitBox:case l.RememberedText:case l.InputTable:case l.MoveByExtParams:{let t=this.CreateColumnFromExaminationData(e[n]);t.elementIndex=n,o.push(t);break}default:break}n++}while(n<e.length);if(o.length>0){let e={columns:o,rowIndexRef:r};a.push(e)}if(o=[],r++,!i.showHideElementId||!e[n]?.formValue||i.showHideElementId!=e[n]?.formValue)break;n++}while(n<e.length);a.length>0&&(i.subRows=a,t.push(i)),a=[],i={},e[n]?.formType==l.NewLine&&e[n]?.formValue?i.showHideElementId=e[n].formValue??``:i.showHideElementId=``,e[n]?.formType==l.NewLine&&e[n]?.conclusion&&e[n]?.conclusion==`hr`?i.hrBeforeRow=!0:i.hrBeforeRow=!1,n++}while(n<e.length);return t}CreateColumn(e,t,n,r,i,a,o){return{formTypeId:e,formValue:t,finding:n,conclusion:r,guid:i??(0,c.v4)(),radLexId:a,extParam:o}}CreateColumnFromExaminationData(e){return this.CreateColumn(e.formType,e.formValue,e.finding,e.conclusion,e.guid,e.radLexId,e.extParam)}IsDistanceDefinition(e){return e?e.includes(`mm`)||e.trim()===`x`:!1}};const d=`https://gener.io`;async function f(e,t){return(await fetch((t??d)+`/api/cookiesAuth/login`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})).ok?{isSuccess:!0}:{isSuccess:!1}}async function p(e){let t=await fetch((e??d)+`/api/cookiesAuth/logout`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`}});return t.ok||t.status===401||t.status===403?{isSuccess:!0}:{isSuccess:!1}}async function m(e,t){let n=(t??d)+`/api/generioApp/recognizeExaminationCookiesAuth`,r=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return r.ok?r.json():{isSuccess:!1}}async function h(e,t,n){let r=await fetch((n??d)+`/api/GenerioApp/loadFormData`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({examinationId:e,studyInstanceUId:t})});return r.ok?r.json():Promise.reject(Error(`Network issue`))}async function g(e,t,n){let r=await fetch((n??d)+`/api/GenerioApp/loadStudy`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({examinationId:e,studyInstanceUId:t})});return r.ok?r.json():Promise.reject(Error(`Network issue`))}async function _(e,t){let n=await fetch((t??d)+`/api/GenerioApp/updateStudy`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});return n.ok?n.json():Promise.reject(Error(`Network issue`))}async function v(e,t){let n=(t??d)+`/api/datasetsCookiesAuth/getExtParamValueByStudyInstanceUId`,r=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return r.ok?r.json():{}}async function y(e,t){let n=await fetch((t??d)+`/api/annotationPlacements/getAnnotationPlacements`,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return n.ok?n.json():{isSuccess:!1,errorMessage:n.statusText,annotationPlacements:[]}}async function b(e,t){let n=(t??d)+`/api/generioApp/setExtParamsCookiesAuth`,r=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return r.ok?r.json():{isSuccess:!1,errorMessage:`Network issue`}}function x(e,t,n){e.postMessage({action:`setExtParams`,model:t},{targetOrigin:n??d})}async function S(e,t){let n=(t??d)+`/api/generioApp/sendMeasurementsCookiesAuth`,r=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return r.ok?r.json():{isSuccess:!1,errorMessage:`Network issue`}}async function C(e,t){let n=(t??d)+`/api/generioApp/getExaminationMessageCookiesAuth`,r=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return r.ok?r.json():{isSuccess:!1,errorMessage:`Network issue`}}function w(e,t){window.addEventListener(`message`,n=>{if((t??d)==n.origin&&(console.info(`PostMessageListener: Received message from origin: ${n.origin}`,n.data),n.data.action==`generioReady`)){e&&e(n.data.model,n);return}},!1)}function T(e,t,n,r,i){let a=`${i??d}/generator/recognizeExamination?studyInstanceUId=${e}&modality=${t}`;return n&&(a+=`&studyDescription=${n}`),r&&(a+=`&bodyPartExamined=${r}`),a}exports.ExaminationDataHelpers=u,exports.FormTypeEnum=l,exports.GENERIO_ORIGIN=d,exports.getAnnotationPlacements=y,exports.getExaminationMessage=C,exports.getExtParamValueByStudyInstanceUId=v,exports.getGenerioRecognizeExaminationUrl=T,exports.loadFormData=h,exports.loadStudy=g,exports.login=f,exports.logout=p,exports.recognizeExamination=m,exports.sendMeasurements=S,exports.setExtParams=b,exports.setExtParamsPostMessage=x,exports.setupPostMessageListeners=w,exports.updateStudy=_;
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let uuid = require("uuid");
25
+ uuid = __toESM(uuid);
26
+
27
+ //#region src/models/FormTypeEnum.ts
28
+ let FormTypeEnum = /* @__PURE__ */ function(FormTypeEnum$1) {
29
+ FormTypeEnum$1[FormTypeEnum$1["NewLine"] = 0] = "NewLine";
30
+ FormTypeEnum$1[FormTypeEnum$1["Text"] = 1] = "Text";
31
+ FormTypeEnum$1[FormTypeEnum$1["BoldText"] = 2] = "BoldText";
32
+ FormTypeEnum$1[FormTypeEnum$1["CheckBox"] = 3] = "CheckBox";
33
+ FormTypeEnum$1[FormTypeEnum$1["DropDownList"] = 4] = "DropDownList";
34
+ FormTypeEnum$1[FormTypeEnum$1["InputText"] = 5] = "InputText";
35
+ FormTypeEnum$1[FormTypeEnum$1["ConditionAndOr"] = 6] = "ConditionAndOr";
36
+ FormTypeEnum$1[FormTypeEnum$1["Function"] = 7] = "Function";
37
+ FormTypeEnum$1[FormTypeEnum$1["Condition"] = 8] = "Condition";
38
+ FormTypeEnum$1[FormTypeEnum$1["Button"] = 9] = "Button";
39
+ FormTypeEnum$1[FormTypeEnum$1["Append"] = 10] = "Append";
40
+ FormTypeEnum$1[FormTypeEnum$1["DigitBox"] = 11] = "DigitBox";
41
+ FormTypeEnum$1[FormTypeEnum$1["Merge"] = 12] = "Merge";
42
+ FormTypeEnum$1[FormTypeEnum$1["Listing"] = 13] = "Listing";
43
+ FormTypeEnum$1[FormTypeEnum$1["Bilateral"] = 14] = "Bilateral";
44
+ FormTypeEnum$1[FormTypeEnum$1["Matrix"] = 15] = "Matrix";
45
+ FormTypeEnum$1[FormTypeEnum$1["RememberedText"] = 17] = "RememberedText";
46
+ FormTypeEnum$1[FormTypeEnum$1["InputTable"] = 18] = "InputTable";
47
+ FormTypeEnum$1[FormTypeEnum$1["AppendDiagnose"] = 19] = "AppendDiagnose";
48
+ FormTypeEnum$1[FormTypeEnum$1["MoveByExtParams"] = 20] = "MoveByExtParams";
49
+ return FormTypeEnum$1;
50
+ }({});
51
+
52
+ //#endregion
53
+ //#region src/services/ExaminationDataHelpers.ts
54
+ var ExaminationDataHelpers = class {
55
+ constructor() {}
56
+ /**
57
+ * Convert DB items into hbs object. Used in FindingGenerator.handlebars
58
+ * @param items ExaminationData entries
59
+ * @returns entry array for hbs
60
+ */
61
+ ConvertExaminationDataToGeneratorRows(items) {
62
+ const rows = [];
63
+ let i = 0;
64
+ let rowIndexRef = 0;
65
+ let row = { subRows: [] };
66
+ let subRows = [];
67
+ let columns = [];
68
+ do {
69
+ do {
70
+ do {
71
+ if (items[i]?.formType == FormTypeEnum.NewLine) break;
72
+ if (items[i]) switch (items[i].formType) {
73
+ case FormTypeEnum.DropDownList: {
74
+ const elementColumn = this.CreateColumnFromExaminationData(items[i]);
75
+ elementColumn.elementIndex = i;
76
+ const elementSelectOptions = [];
77
+ let optionIndex = 1;
78
+ do {
79
+ const elementSelectOption = this.CreateColumnFromExaminationData(items[i]);
80
+ elementSelectOption.elementIndex = i;
81
+ const _value = items[i]?.formValue?.trim();
82
+ if (optionIndex === 1 && _value && !_value.startsWith("-") && !_value.endsWith("-")) elementColumn.preselected = true;
83
+ elementSelectOptions.push(elementSelectOption);
84
+ i++;
85
+ optionIndex++;
86
+ } while (items[i]?.formType == FormTypeEnum.DropDownList && i < items.length);
87
+ elementColumn.elementSelectOptions = elementSelectOptions;
88
+ columns.push(elementColumn);
89
+ i--;
90
+ break;
91
+ }
92
+ case FormTypeEnum.Text:
93
+ case FormTypeEnum.Append:
94
+ if (items[i]?.formValue) {
95
+ const column = this.CreateColumnFromExaminationData(items[i]);
96
+ column.elementIndex = i;
97
+ columns.push(column);
98
+ }
99
+ break;
100
+ case FormTypeEnum.InputText: {
101
+ const elementColumn = this.CreateColumnFromExaminationData(items[i]);
102
+ elementColumn.elementIndex = i;
103
+ elementColumn.isDistance = this.IsDistanceDefinition(items[i + 1]?.formValue ?? "");
104
+ columns.push(elementColumn);
105
+ break;
106
+ }
107
+ case FormTypeEnum.BoldText:
108
+ case FormTypeEnum.CheckBox:
109
+ case FormTypeEnum.Button:
110
+ case FormTypeEnum.DigitBox:
111
+ case FormTypeEnum.RememberedText:
112
+ case FormTypeEnum.InputTable:
113
+ case FormTypeEnum.MoveByExtParams: {
114
+ const column = this.CreateColumnFromExaminationData(items[i]);
115
+ column.elementIndex = i;
116
+ columns.push(column);
117
+ break;
118
+ }
119
+ default: break;
120
+ }
121
+ i++;
122
+ } while (i < items.length);
123
+ if (columns.length > 0) {
124
+ const subRow = {
125
+ columns,
126
+ rowIndexRef
127
+ };
128
+ subRows.push(subRow);
129
+ }
130
+ columns = [];
131
+ rowIndexRef++;
132
+ if (!row.showHideElementId || !items[i]?.formValue || row.showHideElementId != items[i]?.formValue) break;
133
+ i++;
134
+ } while (i < items.length);
135
+ if (subRows.length > 0) {
136
+ row.subRows = subRows;
137
+ rows.push(row);
138
+ }
139
+ subRows = [];
140
+ row = {};
141
+ if (items[i]?.formType == FormTypeEnum.NewLine && items[i]?.formValue) row.showHideElementId = items[i].formValue ?? "";
142
+ else row.showHideElementId = "";
143
+ if (items[i]?.formType == FormTypeEnum.NewLine && items[i]?.conclusion && items[i]?.conclusion == "hr") row.hrBeforeRow = true;
144
+ else row.hrBeforeRow = false;
145
+ i++;
146
+ } while (i < items.length);
147
+ return rows;
148
+ }
149
+ CreateColumn(formType, formValue, finding, conclusion, guid, radLexId, extParam) {
150
+ return {
151
+ formTypeId: formType,
152
+ formValue,
153
+ finding,
154
+ conclusion,
155
+ guid: guid ?? (0, uuid.v4)(),
156
+ radLexId,
157
+ extParam
158
+ };
159
+ }
160
+ CreateColumnFromExaminationData(item) {
161
+ return this.CreateColumn(item.formType, item.formValue, item.finding, item.conclusion, item.guid, item.radLexId, item.extParam);
162
+ }
163
+ IsDistanceDefinition(originFormValue) {
164
+ if (originFormValue) return originFormValue.includes("mm") || originFormValue.trim() === "x";
165
+ return false;
166
+ }
167
+ };
168
+
169
+ //#endregion
170
+ //#region src/index.ts
171
+ const GENERIO_ORIGIN = "https://gener.io";
172
+ async function login(model, origin) {
173
+ if ((await fetch((origin ?? GENERIO_ORIGIN) + "/api/cookiesAuth/login", {
174
+ method: "POST",
175
+ credentials: "include",
176
+ headers: { "Content-Type": "application/json" },
177
+ body: JSON.stringify(model)
178
+ })).ok) return { isSuccess: true };
179
+ return { isSuccess: false };
180
+ }
181
+ async function logout(origin) {
182
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/cookiesAuth/logout", {
183
+ method: "POST",
184
+ credentials: "include",
185
+ headers: { "Content-Type": "application/json" }
186
+ });
187
+ return response.ok || response.status === 401 || response.status === 403 ? { isSuccess: true } : { isSuccess: false };
188
+ }
189
+ async function recognizeExamination(model, origin) {
190
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/generioApp/recognizeExaminationCookiesAuth";
191
+ const response = await fetch(url, {
192
+ method: "POST",
193
+ credentials: "include",
194
+ body: JSON.stringify(model),
195
+ headers: { "Content-Type": "application/json" }
196
+ });
197
+ return response.ok ? response.json() : { isSuccess: false };
198
+ }
199
+ async function loadFormData(examinationId, studyInstanceUId, origin) {
200
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/GenerioApp/loadFormData", {
201
+ method: "POST",
202
+ credentials: "include",
203
+ headers: { "Content-Type": "application/json" },
204
+ body: JSON.stringify({
205
+ examinationId,
206
+ studyInstanceUId
207
+ })
208
+ });
209
+ return response.ok ? response.json() : Promise.reject(/* @__PURE__ */ new Error("Network issue"));
210
+ }
211
+ async function loadStudy(examinationId, studyInstanceUId, origin) {
212
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/GenerioApp/loadStudy", {
213
+ method: "POST",
214
+ credentials: "include",
215
+ headers: { "Content-Type": "application/json" },
216
+ body: JSON.stringify({
217
+ examinationId,
218
+ studyInstanceUId
219
+ })
220
+ });
221
+ return response.ok ? response.json() : Promise.reject(/* @__PURE__ */ new Error("Network issue"));
222
+ }
223
+ async function updateStudy(model, origin) {
224
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/GenerioApp/updateStudy", {
225
+ method: "POST",
226
+ credentials: "include",
227
+ headers: { "Content-Type": "application/json" },
228
+ body: JSON.stringify(model)
229
+ });
230
+ return response.ok ? response.json() : Promise.reject(/* @__PURE__ */ new Error("Network issue"));
231
+ }
232
+ async function getExtParamValueByStudyInstanceUId(model, origin) {
233
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/datasetsCookiesAuth/getExtParamValueByStudyInstanceUId";
234
+ const response = await fetch(url, {
235
+ method: "POST",
236
+ credentials: "include",
237
+ body: JSON.stringify(model),
238
+ headers: { "Content-Type": "application/json" }
239
+ });
240
+ return response.ok ? response.json() : {};
241
+ }
242
+ async function getAnnotationPlacements(model, origin) {
243
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/annotationPlacements/getAnnotationPlacements", {
244
+ method: "POST",
245
+ credentials: "include",
246
+ body: JSON.stringify(model),
247
+ headers: { "Content-Type": "application/json" }
248
+ });
249
+ return response.ok ? response.json() : {
250
+ isSuccess: false,
251
+ errorMessage: response.statusText,
252
+ annotationPlacements: []
253
+ };
254
+ }
255
+ async function setExtParams(model, origin) {
256
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/generioApp/setExtParamsCookiesAuth";
257
+ const response = await fetch(url, {
258
+ method: "POST",
259
+ credentials: "include",
260
+ body: JSON.stringify(model),
261
+ headers: { "Content-Type": "application/json" }
262
+ });
263
+ return response.ok ? response.json() : {
264
+ isSuccess: false,
265
+ errorMessage: "Network issue"
266
+ };
267
+ }
268
+ function setExtParamsPostMessage(window$1, model, origin) {
269
+ window$1.postMessage({
270
+ action: "setExtParams",
271
+ model
272
+ }, { targetOrigin: origin ?? GENERIO_ORIGIN });
273
+ }
274
+ async function sendMeasurements(model, origin) {
275
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/generioApp/sendMeasurementsCookiesAuth";
276
+ const response = await fetch(url, {
277
+ method: "POST",
278
+ credentials: "include",
279
+ body: JSON.stringify(model),
280
+ headers: { "Content-Type": "application/json" }
281
+ });
282
+ return response.ok ? response.json() : {
283
+ isSuccess: false,
284
+ errorMessage: "Network issue"
285
+ };
286
+ }
287
+ async function getExaminationMessage(model, origin) {
288
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/generioApp/getExaminationMessageCookiesAuth";
289
+ const response = await fetch(url, {
290
+ method: "POST",
291
+ credentials: "include",
292
+ body: JSON.stringify(model),
293
+ headers: { "Content-Type": "application/json" }
294
+ });
295
+ return response.ok ? response.json() : {
296
+ isSuccess: false,
297
+ errorMessage: "Network issue"
298
+ };
299
+ }
300
+ function setupPostMessageListeners(generioReadyHandler, origin) {
301
+ window.addEventListener("message", (event) => {
302
+ if ((origin ?? GENERIO_ORIGIN) != event.origin) return;
303
+ console.info(`PostMessageListener: Received message from origin: ${event.origin}`, event.data);
304
+ if (event.data.action == "generioReady") {
305
+ if (generioReadyHandler) generioReadyHandler(event.data.model, event);
306
+ return;
307
+ }
308
+ }, false);
309
+ }
310
+ function getGenerioRecognizeExaminationUrl(studyInstanceUId, modality, studyDescription, bodyPartExamined, origin) {
311
+ let url = `${origin ?? GENERIO_ORIGIN}/generator/recognizeExamination?studyInstanceUId=${studyInstanceUId}&modality=${modality}`;
312
+ if (studyDescription) url = url + `&studyDescription=${studyDescription}`;
313
+ if (bodyPartExamined) url = url + `&bodyPartExamined=${bodyPartExamined}`;
314
+ return url;
315
+ }
316
+
317
+ //#endregion
318
+ exports.ExaminationDataHelpers = ExaminationDataHelpers;
319
+ exports.FormTypeEnum = FormTypeEnum;
320
+ exports.GENERIO_ORIGIN = GENERIO_ORIGIN;
321
+ exports.getAnnotationPlacements = getAnnotationPlacements;
322
+ exports.getExaminationMessage = getExaminationMessage;
323
+ exports.getExtParamValueByStudyInstanceUId = getExtParamValueByStudyInstanceUId;
324
+ exports.getGenerioRecognizeExaminationUrl = getGenerioRecognizeExaminationUrl;
325
+ exports.loadFormData = loadFormData;
326
+ exports.loadStudy = loadStudy;
327
+ exports.login = login;
328
+ exports.logout = logout;
329
+ exports.recognizeExamination = recognizeExamination;
330
+ exports.sendMeasurements = sendMeasurements;
331
+ exports.setExtParams = setExtParams;
332
+ exports.setExtParamsPostMessage = setExtParamsPostMessage;
333
+ exports.setupPostMessageListeners = setupPostMessageListeners;
334
+ exports.updateStudy = updateStudy;
package/dist/index.js CHANGED
@@ -1 +1,294 @@
1
- import{v4 as e}from"uuid";let t=function(e){return e[e.NewLine=0]=`NewLine`,e[e.Text=1]=`Text`,e[e.BoldText=2]=`BoldText`,e[e.CheckBox=3]=`CheckBox`,e[e.DropDownList=4]=`DropDownList`,e[e.InputText=5]=`InputText`,e[e.ConditionAndOr=6]=`ConditionAndOr`,e[e.Function=7]=`Function`,e[e.Condition=8]=`Condition`,e[e.Button=9]=`Button`,e[e.Append=10]=`Append`,e[e.DigitBox=11]=`DigitBox`,e[e.Merge=12]=`Merge`,e[e.Listing=13]=`Listing`,e[e.Bilateral=14]=`Bilateral`,e[e.Matrix=15]=`Matrix`,e[e.RememberedText=17]=`RememberedText`,e[e.InputTable=18]=`InputTable`,e[e.AppendDiagnose=19]=`AppendDiagnose`,e[e.MoveByExtParams=20]=`MoveByExtParams`,e}({});var n=class{constructor(){}ConvertExaminationDataToGeneratorRows(e){let n=[],r=0,i=0,a={subRows:[]},o=[],s=[];do{do{do{if(e[r]?.formType==t.NewLine)break;if(e[r])switch(e[r].formType){case t.DropDownList:{let n=this.CreateColumnFromExaminationData(e[r]);n.elementIndex=r;let i=[],a=1;do{let t=this.CreateColumnFromExaminationData(e[r]);t.elementIndex=r;let o=e[r]?.formValue?.trim();a===1&&o&&!o.startsWith(`-`)&&!o.endsWith(`-`)&&(n.preselected=!0),i.push(t),r++,a++}while(e[r]?.formType==t.DropDownList&&r<e.length);n.elementSelectOptions=i,s.push(n),r--;break}case t.Text:case t.Append:if(e[r]?.formValue){let t=this.CreateColumnFromExaminationData(e[r]);t.elementIndex=r,s.push(t)}break;case t.InputText:{let t=this.CreateColumnFromExaminationData(e[r]);t.elementIndex=r,t.isDistance=this.IsDistanceDefinition(e[r+1]?.formValue??``),s.push(t);break}case t.BoldText:case t.CheckBox:case t.Button:case t.DigitBox:case t.RememberedText:case t.InputTable:case t.MoveByExtParams:{let t=this.CreateColumnFromExaminationData(e[r]);t.elementIndex=r,s.push(t);break}default:break}r++}while(r<e.length);if(s.length>0){let e={columns:s,rowIndexRef:i};o.push(e)}if(s=[],i++,!a.showHideElementId||!e[r]?.formValue||a.showHideElementId!=e[r]?.formValue)break;r++}while(r<e.length);o.length>0&&(a.subRows=o,n.push(a)),o=[],a={},e[r]?.formType==t.NewLine&&e[r]?.formValue?a.showHideElementId=e[r].formValue??``:a.showHideElementId=``,e[r]?.formType==t.NewLine&&e[r]?.conclusion&&e[r]?.conclusion==`hr`?a.hrBeforeRow=!0:a.hrBeforeRow=!1,r++}while(r<e.length);return n}CreateColumn(t,n,r,i,a,o,s){return{formTypeId:t,formValue:n,finding:r,conclusion:i,guid:a??e(),radLexId:o,extParam:s}}CreateColumnFromExaminationData(e){return this.CreateColumn(e.formType,e.formValue,e.finding,e.conclusion,e.guid,e.radLexId,e.extParam)}IsDistanceDefinition(e){return e?e.includes(`mm`)||e.trim()===`x`:!1}};const r=`https://gener.io`;async function i(e,t){return(await fetch((t??r)+`/api/cookiesAuth/login`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})).ok?{isSuccess:!0}:{isSuccess:!1}}async function a(e){let t=await fetch((e??r)+`/api/cookiesAuth/logout`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`}});return t.ok||t.status===401||t.status===403?{isSuccess:!0}:{isSuccess:!1}}async function o(e,t){let n=(t??r)+`/api/generioApp/recognizeExaminationCookiesAuth`,i=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return i.ok?i.json():{isSuccess:!1}}async function s(e,t,n){let i=await fetch((n??r)+`/api/GenerioApp/loadFormData`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({examinationId:e,studyInstanceUId:t})});return i.ok?i.json():Promise.reject(Error(`Network issue`))}async function c(e,t,n){let i=await fetch((n??r)+`/api/GenerioApp/loadStudy`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({examinationId:e,studyInstanceUId:t})});return i.ok?i.json():Promise.reject(Error(`Network issue`))}async function l(e,t){let n=await fetch((t??r)+`/api/GenerioApp/updateStudy`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});return n.ok?n.json():Promise.reject(Error(`Network issue`))}async function u(e,t){let n=(t??r)+`/api/datasetsCookiesAuth/getExtParamValueByStudyInstanceUId`,i=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return i.ok?i.json():{}}async function d(e,t){let n=await fetch((t??r)+`/api/annotationPlacements/getAnnotationPlacements`,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return n.ok?n.json():{isSuccess:!1,errorMessage:n.statusText,annotationPlacements:[]}}async function f(e,t){let n=(t??r)+`/api/generioApp/setExtParamsCookiesAuth`,i=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return i.ok?i.json():{isSuccess:!1,errorMessage:`Network issue`}}function p(e,t,n){e.postMessage({action:`setExtParams`,model:t},{targetOrigin:n??r})}async function m(e,t){let n=(t??r)+`/api/generioApp/sendMeasurementsCookiesAuth`,i=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return i.ok?i.json():{isSuccess:!1,errorMessage:`Network issue`}}async function h(e,t){let n=(t??r)+`/api/generioApp/getExaminationMessageCookiesAuth`,i=await fetch(n,{method:`POST`,credentials:`include`,body:JSON.stringify(e),headers:{"Content-Type":`application/json`}});return i.ok?i.json():{isSuccess:!1,errorMessage:`Network issue`}}function g(e,t){window.addEventListener(`message`,n=>{if((t??r)==n.origin&&(console.info(`PostMessageListener: Received message from origin: ${n.origin}`,n.data),n.data.action==`generioReady`)){e&&e(n.data.model,n);return}},!1)}function _(e,t,n,i,a){let o=`${a??r}/generator/recognizeExamination?studyInstanceUId=${e}&modality=${t}`;return n&&(o+=`&studyDescription=${n}`),i&&(o+=`&bodyPartExamined=${i}`),o}export{n as ExaminationDataHelpers,t as FormTypeEnum,r as GENERIO_ORIGIN,d as getAnnotationPlacements,h as getExaminationMessage,u as getExtParamValueByStudyInstanceUId,_ as getGenerioRecognizeExaminationUrl,s as loadFormData,c as loadStudy,i as login,a as logout,o as recognizeExamination,m as sendMeasurements,f as setExtParams,p as setExtParamsPostMessage,g as setupPostMessageListeners,l as updateStudy};
1
+ import { v4 } from "uuid";
2
+
3
+ //#region src/models/FormTypeEnum.ts
4
+ let FormTypeEnum = /* @__PURE__ */ function(FormTypeEnum$1) {
5
+ FormTypeEnum$1[FormTypeEnum$1["NewLine"] = 0] = "NewLine";
6
+ FormTypeEnum$1[FormTypeEnum$1["Text"] = 1] = "Text";
7
+ FormTypeEnum$1[FormTypeEnum$1["BoldText"] = 2] = "BoldText";
8
+ FormTypeEnum$1[FormTypeEnum$1["CheckBox"] = 3] = "CheckBox";
9
+ FormTypeEnum$1[FormTypeEnum$1["DropDownList"] = 4] = "DropDownList";
10
+ FormTypeEnum$1[FormTypeEnum$1["InputText"] = 5] = "InputText";
11
+ FormTypeEnum$1[FormTypeEnum$1["ConditionAndOr"] = 6] = "ConditionAndOr";
12
+ FormTypeEnum$1[FormTypeEnum$1["Function"] = 7] = "Function";
13
+ FormTypeEnum$1[FormTypeEnum$1["Condition"] = 8] = "Condition";
14
+ FormTypeEnum$1[FormTypeEnum$1["Button"] = 9] = "Button";
15
+ FormTypeEnum$1[FormTypeEnum$1["Append"] = 10] = "Append";
16
+ FormTypeEnum$1[FormTypeEnum$1["DigitBox"] = 11] = "DigitBox";
17
+ FormTypeEnum$1[FormTypeEnum$1["Merge"] = 12] = "Merge";
18
+ FormTypeEnum$1[FormTypeEnum$1["Listing"] = 13] = "Listing";
19
+ FormTypeEnum$1[FormTypeEnum$1["Bilateral"] = 14] = "Bilateral";
20
+ FormTypeEnum$1[FormTypeEnum$1["Matrix"] = 15] = "Matrix";
21
+ FormTypeEnum$1[FormTypeEnum$1["RememberedText"] = 17] = "RememberedText";
22
+ FormTypeEnum$1[FormTypeEnum$1["InputTable"] = 18] = "InputTable";
23
+ FormTypeEnum$1[FormTypeEnum$1["AppendDiagnose"] = 19] = "AppendDiagnose";
24
+ FormTypeEnum$1[FormTypeEnum$1["MoveByExtParams"] = 20] = "MoveByExtParams";
25
+ return FormTypeEnum$1;
26
+ }({});
27
+
28
+ //#endregion
29
+ //#region src/services/ExaminationDataHelpers.ts
30
+ var ExaminationDataHelpers = class {
31
+ constructor() {}
32
+ /**
33
+ * Convert DB items into hbs object. Used in FindingGenerator.handlebars
34
+ * @param items ExaminationData entries
35
+ * @returns entry array for hbs
36
+ */
37
+ ConvertExaminationDataToGeneratorRows(items) {
38
+ const rows = [];
39
+ let i = 0;
40
+ let rowIndexRef = 0;
41
+ let row = { subRows: [] };
42
+ let subRows = [];
43
+ let columns = [];
44
+ do {
45
+ do {
46
+ do {
47
+ if (items[i]?.formType == FormTypeEnum.NewLine) break;
48
+ if (items[i]) switch (items[i].formType) {
49
+ case FormTypeEnum.DropDownList: {
50
+ const elementColumn = this.CreateColumnFromExaminationData(items[i]);
51
+ elementColumn.elementIndex = i;
52
+ const elementSelectOptions = [];
53
+ let optionIndex = 1;
54
+ do {
55
+ const elementSelectOption = this.CreateColumnFromExaminationData(items[i]);
56
+ elementSelectOption.elementIndex = i;
57
+ const _value = items[i]?.formValue?.trim();
58
+ if (optionIndex === 1 && _value && !_value.startsWith("-") && !_value.endsWith("-")) elementColumn.preselected = true;
59
+ elementSelectOptions.push(elementSelectOption);
60
+ i++;
61
+ optionIndex++;
62
+ } while (items[i]?.formType == FormTypeEnum.DropDownList && i < items.length);
63
+ elementColumn.elementSelectOptions = elementSelectOptions;
64
+ columns.push(elementColumn);
65
+ i--;
66
+ break;
67
+ }
68
+ case FormTypeEnum.Text:
69
+ case FormTypeEnum.Append:
70
+ if (items[i]?.formValue) {
71
+ const column = this.CreateColumnFromExaminationData(items[i]);
72
+ column.elementIndex = i;
73
+ columns.push(column);
74
+ }
75
+ break;
76
+ case FormTypeEnum.InputText: {
77
+ const elementColumn = this.CreateColumnFromExaminationData(items[i]);
78
+ elementColumn.elementIndex = i;
79
+ elementColumn.isDistance = this.IsDistanceDefinition(items[i + 1]?.formValue ?? "");
80
+ columns.push(elementColumn);
81
+ break;
82
+ }
83
+ case FormTypeEnum.BoldText:
84
+ case FormTypeEnum.CheckBox:
85
+ case FormTypeEnum.Button:
86
+ case FormTypeEnum.DigitBox:
87
+ case FormTypeEnum.RememberedText:
88
+ case FormTypeEnum.InputTable:
89
+ case FormTypeEnum.MoveByExtParams: {
90
+ const column = this.CreateColumnFromExaminationData(items[i]);
91
+ column.elementIndex = i;
92
+ columns.push(column);
93
+ break;
94
+ }
95
+ default: break;
96
+ }
97
+ i++;
98
+ } while (i < items.length);
99
+ if (columns.length > 0) {
100
+ const subRow = {
101
+ columns,
102
+ rowIndexRef
103
+ };
104
+ subRows.push(subRow);
105
+ }
106
+ columns = [];
107
+ rowIndexRef++;
108
+ if (!row.showHideElementId || !items[i]?.formValue || row.showHideElementId != items[i]?.formValue) break;
109
+ i++;
110
+ } while (i < items.length);
111
+ if (subRows.length > 0) {
112
+ row.subRows = subRows;
113
+ rows.push(row);
114
+ }
115
+ subRows = [];
116
+ row = {};
117
+ if (items[i]?.formType == FormTypeEnum.NewLine && items[i]?.formValue) row.showHideElementId = items[i].formValue ?? "";
118
+ else row.showHideElementId = "";
119
+ if (items[i]?.formType == FormTypeEnum.NewLine && items[i]?.conclusion && items[i]?.conclusion == "hr") row.hrBeforeRow = true;
120
+ else row.hrBeforeRow = false;
121
+ i++;
122
+ } while (i < items.length);
123
+ return rows;
124
+ }
125
+ CreateColumn(formType, formValue, finding, conclusion, guid, radLexId, extParam) {
126
+ return {
127
+ formTypeId: formType,
128
+ formValue,
129
+ finding,
130
+ conclusion,
131
+ guid: guid ?? v4(),
132
+ radLexId,
133
+ extParam
134
+ };
135
+ }
136
+ CreateColumnFromExaminationData(item) {
137
+ return this.CreateColumn(item.formType, item.formValue, item.finding, item.conclusion, item.guid, item.radLexId, item.extParam);
138
+ }
139
+ IsDistanceDefinition(originFormValue) {
140
+ if (originFormValue) return originFormValue.includes("mm") || originFormValue.trim() === "x";
141
+ return false;
142
+ }
143
+ };
144
+
145
+ //#endregion
146
+ //#region src/index.ts
147
+ const GENERIO_ORIGIN = "https://gener.io";
148
+ async function login(model, origin) {
149
+ if ((await fetch((origin ?? GENERIO_ORIGIN) + "/api/cookiesAuth/login", {
150
+ method: "POST",
151
+ credentials: "include",
152
+ headers: { "Content-Type": "application/json" },
153
+ body: JSON.stringify(model)
154
+ })).ok) return { isSuccess: true };
155
+ return { isSuccess: false };
156
+ }
157
+ async function logout(origin) {
158
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/cookiesAuth/logout", {
159
+ method: "POST",
160
+ credentials: "include",
161
+ headers: { "Content-Type": "application/json" }
162
+ });
163
+ return response.ok || response.status === 401 || response.status === 403 ? { isSuccess: true } : { isSuccess: false };
164
+ }
165
+ async function recognizeExamination(model, origin) {
166
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/generioApp/recognizeExaminationCookiesAuth";
167
+ const response = await fetch(url, {
168
+ method: "POST",
169
+ credentials: "include",
170
+ body: JSON.stringify(model),
171
+ headers: { "Content-Type": "application/json" }
172
+ });
173
+ return response.ok ? response.json() : { isSuccess: false };
174
+ }
175
+ async function loadFormData(examinationId, studyInstanceUId, origin) {
176
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/GenerioApp/loadFormData", {
177
+ method: "POST",
178
+ credentials: "include",
179
+ headers: { "Content-Type": "application/json" },
180
+ body: JSON.stringify({
181
+ examinationId,
182
+ studyInstanceUId
183
+ })
184
+ });
185
+ return response.ok ? response.json() : Promise.reject(/* @__PURE__ */ new Error("Network issue"));
186
+ }
187
+ async function loadStudy(examinationId, studyInstanceUId, origin) {
188
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/GenerioApp/loadStudy", {
189
+ method: "POST",
190
+ credentials: "include",
191
+ headers: { "Content-Type": "application/json" },
192
+ body: JSON.stringify({
193
+ examinationId,
194
+ studyInstanceUId
195
+ })
196
+ });
197
+ return response.ok ? response.json() : Promise.reject(/* @__PURE__ */ new Error("Network issue"));
198
+ }
199
+ async function updateStudy(model, origin) {
200
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/GenerioApp/updateStudy", {
201
+ method: "POST",
202
+ credentials: "include",
203
+ headers: { "Content-Type": "application/json" },
204
+ body: JSON.stringify(model)
205
+ });
206
+ return response.ok ? response.json() : Promise.reject(/* @__PURE__ */ new Error("Network issue"));
207
+ }
208
+ async function getExtParamValueByStudyInstanceUId(model, origin) {
209
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/datasetsCookiesAuth/getExtParamValueByStudyInstanceUId";
210
+ const response = await fetch(url, {
211
+ method: "POST",
212
+ credentials: "include",
213
+ body: JSON.stringify(model),
214
+ headers: { "Content-Type": "application/json" }
215
+ });
216
+ return response.ok ? response.json() : {};
217
+ }
218
+ async function getAnnotationPlacements(model, origin) {
219
+ const response = await fetch((origin ?? GENERIO_ORIGIN) + "/api/annotationPlacements/getAnnotationPlacements", {
220
+ method: "POST",
221
+ credentials: "include",
222
+ body: JSON.stringify(model),
223
+ headers: { "Content-Type": "application/json" }
224
+ });
225
+ return response.ok ? response.json() : {
226
+ isSuccess: false,
227
+ errorMessage: response.statusText,
228
+ annotationPlacements: []
229
+ };
230
+ }
231
+ async function setExtParams(model, origin) {
232
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/generioApp/setExtParamsCookiesAuth";
233
+ const response = await fetch(url, {
234
+ method: "POST",
235
+ credentials: "include",
236
+ body: JSON.stringify(model),
237
+ headers: { "Content-Type": "application/json" }
238
+ });
239
+ return response.ok ? response.json() : {
240
+ isSuccess: false,
241
+ errorMessage: "Network issue"
242
+ };
243
+ }
244
+ function setExtParamsPostMessage(window$1, model, origin) {
245
+ window$1.postMessage({
246
+ action: "setExtParams",
247
+ model
248
+ }, { targetOrigin: origin ?? GENERIO_ORIGIN });
249
+ }
250
+ async function sendMeasurements(model, origin) {
251
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/generioApp/sendMeasurementsCookiesAuth";
252
+ const response = await fetch(url, {
253
+ method: "POST",
254
+ credentials: "include",
255
+ body: JSON.stringify(model),
256
+ headers: { "Content-Type": "application/json" }
257
+ });
258
+ return response.ok ? response.json() : {
259
+ isSuccess: false,
260
+ errorMessage: "Network issue"
261
+ };
262
+ }
263
+ async function getExaminationMessage(model, origin) {
264
+ const url = (origin ?? GENERIO_ORIGIN) + "/api/generioApp/getExaminationMessageCookiesAuth";
265
+ const response = await fetch(url, {
266
+ method: "POST",
267
+ credentials: "include",
268
+ body: JSON.stringify(model),
269
+ headers: { "Content-Type": "application/json" }
270
+ });
271
+ return response.ok ? response.json() : {
272
+ isSuccess: false,
273
+ errorMessage: "Network issue"
274
+ };
275
+ }
276
+ function setupPostMessageListeners(generioReadyHandler, origin) {
277
+ window.addEventListener("message", (event) => {
278
+ if ((origin ?? GENERIO_ORIGIN) != event.origin) return;
279
+ console.info(`PostMessageListener: Received message from origin: ${event.origin}`, event.data);
280
+ if (event.data.action == "generioReady") {
281
+ if (generioReadyHandler) generioReadyHandler(event.data.model, event);
282
+ return;
283
+ }
284
+ }, false);
285
+ }
286
+ function getGenerioRecognizeExaminationUrl(studyInstanceUId, modality, studyDescription, bodyPartExamined, origin) {
287
+ let url = `${origin ?? GENERIO_ORIGIN}/generator/recognizeExamination?studyInstanceUId=${studyInstanceUId}&modality=${modality}`;
288
+ if (studyDescription) url = url + `&studyDescription=${studyDescription}`;
289
+ if (bodyPartExamined) url = url + `&bodyPartExamined=${bodyPartExamined}`;
290
+ return url;
291
+ }
292
+
293
+ //#endregion
294
+ export { ExaminationDataHelpers, FormTypeEnum, GENERIO_ORIGIN, getAnnotationPlacements, getExaminationMessage, getExtParamValueByStudyInstanceUId, getGenerioRecognizeExaminationUrl, loadFormData, loadStudy, login, logout, recognizeExamination, sendMeasurements, setExtParams, setExtParamsPostMessage, setupPostMessageListeners, updateStudy };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generio-sdk",
3
- "version": "1.0.92",
3
+ "version": "1.0.94",
4
4
  "description": "SDK library for generio integration",
5
5
  "type": "module",
6
6
  "license": "MIT",