@uxland/primary-shell 7.36.5 → 7.37.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.
@@ -1,16 +1,20 @@
1
+ import { PrimariaGlobalStateManager } from '../global-state/global-state';
2
+ export declare const LAST_WORKED_DIAGNOSTICS_KEY = "lastWorkedDiagnostics";
1
3
  export declare abstract class EcapEventManager {
2
4
  /**
3
5
  * Publish an Ecap event.
4
- * @param event - Event name.
5
6
  * @param eventType - Event type.
6
- * @param url - Asociated URL to event.
7
+ * @param accio - Action.
8
+ * @param payload - Additional payload properties.
7
9
  */
8
- abstract publish(eventType: string, accio: string, payload?: Record<string, string>): void;
10
+ abstract publish(eventType: string, accio: string, payload?: Record<string, unknown>): void;
9
11
  }
10
12
  declare class EcapEventManagerImpl implements EcapEventManager {
11
- publish(eventType: string, accio: string, payload?: Record<string, string>): void;
13
+ private globalStateManager;
14
+ constructor(globalStateManager: PrimariaGlobalStateManager);
15
+ publish(eventType: string, accio: string, payload?: Record<string, unknown>): void;
12
16
  private createEcapEvent;
13
17
  private raiseEcapEvent;
14
18
  }
15
- export declare const createEcapEventManager: () => EcapEventManagerImpl;
19
+ export declare const createEcapEventManager: (globalStateManager: PrimariaGlobalStateManager) => EcapEventManagerImpl;
16
20
  export {};
@@ -1,5 +1,6 @@
1
1
  export interface IEcapEvent {
2
2
  TipusEvent: string;
3
3
  Accio: string;
4
- [key: string]: string;
4
+ diagnostics?: unknown[];
5
+ [key: string]: unknown;
5
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxland/primary-shell",
3
- "version": "7.36.5",
3
+ "version": "7.37.0",
4
4
  "description": "Primaria Shell",
5
5
  "author": "UXLand <dev@uxland.es>",
6
6
  "homepage": "https://github.com/uxland/harmonix/tree/app#readme",
package/src/api/api.ts CHANGED
@@ -61,7 +61,7 @@ const pluginBusyManager = new PluginBusyManagerImpl();
61
61
  const quickActionBusyManager = new QuickActionBusyManagerImpl(broker);
62
62
  const interactionService = new ParimariaInteractionServiceImpl();
63
63
  const notificationService = new PrimariaNotificationServiceImpl();
64
- const ecapEventManager = createEcapEventManager();
64
+ const ecapEventManager = createEcapEventManager(globalStateManager);
65
65
  const pdfViewerManager = createPdfViewerManager(broker, notificationService);
66
66
  const importDataManager = new ImportDataManagerImpl(interactionService);
67
67
 
@@ -1,5 +1,12 @@
1
1
  import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import { createEcapEventManager } from "./ecap-event-manager";
2
+ import { createEcapEventManager, LAST_WORKED_DIAGNOSTICS_KEY } from "./ecap-event-manager";
3
+
4
+ const createMockGlobalStateManager = (data: Record<string, unknown> = {}) =>
5
+ ({
6
+ getData: vi.fn((key: string) => data[key]),
7
+ setData: vi.fn(),
8
+ clearData: vi.fn(),
9
+ }) as any;
3
10
 
4
11
  describe("EcapEventManagerImpl", () => {
5
12
  const mockPostMessage = vi.fn();
@@ -16,29 +23,67 @@ describe("EcapEventManagerImpl", () => {
16
23
  };
17
24
  });
18
25
 
19
- it("should publish and post the event correctly", () => {
20
- const eventManager = createEcapEventManager();
26
+ it("should publish and post the event correctly without diagnostics for non-whitelisted events", () => {
27
+ const diagnostics = [{ codi: "J06" }];
28
+ const globalStateManager = createMockGlobalStateManager({ [LAST_WORKED_DIAGNOSTICS_KEY]: diagnostics });
29
+ const eventManager = createEcapEventManager(globalStateManager);
21
30
  const payload = { url: "https://example.com", user: "john" };
22
31
 
23
32
  eventManager.publish("click", "navigate", payload);
24
33
 
25
- const expectedEvent = {
26
- TipusEvent: "click",
27
- Accio: "navigate",
28
- ...payload,
29
- };
34
+ const postedEvent = JSON.parse(mockPostMessage.mock.calls[0][0]);
35
+ expect(postedEvent.diagnostics).toBeUndefined();
36
+ expect(globalStateManager.getData).not.toHaveBeenCalled();
37
+ });
38
+
39
+ it("should include diagnostics for whitelisted events", () => {
40
+ const diagnostics = [{ codi: "J06", cataleg: "CIM-10", descripcio: "Test", idEcap: "1", idCipds: "2", idCdr: "3" }];
41
+ const globalStateManager = createMockGlobalStateManager({ [LAST_WORKED_DIAGNOSTICS_KEY]: diagnostics });
42
+ const eventManager = createEcapEventManager(globalStateManager);
43
+
44
+ eventManager.publish("PRESCRIPCIO_ACTIVA", "NO_TANCAR", {});
45
+
46
+ const postedEvent = JSON.parse(mockPostMessage.mock.calls[0][0]);
47
+ expect(postedEvent.diagnostics).toEqual(diagnostics);
48
+ expect(globalStateManager.getData).toHaveBeenCalledWith(LAST_WORKED_DIAGNOSTICS_KEY);
49
+ });
50
+
51
+ it.each([
52
+ "PROVES_ORDRES_CLINIQUES_CONSULTAR",
53
+ "RESULT_OC",
54
+ "LABORATORI_SEROTECA_PETICIO_CONSULTA",
55
+ "ORDRE_TRACTAMENT",
56
+ "PRESCRIPCIO_ACTIVA",
57
+ "REV_IT",
58
+ "OC_EXPRES",
59
+ ])("should include diagnostics for whitelisted event %s", (eventType) => {
60
+ const diagnostics = [{ codi: "J06" }];
61
+ const globalStateManager = createMockGlobalStateManager({ [LAST_WORKED_DIAGNOSTICS_KEY]: diagnostics });
62
+ const eventManager = createEcapEventManager(globalStateManager);
63
+
64
+ eventManager.publish(eventType, "NO_TANCAR", {});
65
+
66
+ const postedEvent = JSON.parse(mockPostMessage.mock.calls[0][0]);
67
+ expect(postedEvent.diagnostics).toEqual(diagnostics);
68
+ });
69
+
70
+ it("should include empty diagnostics array for whitelisted events when none set", () => {
71
+ const globalStateManager = createMockGlobalStateManager();
72
+ const eventManager = createEcapEventManager(globalStateManager);
73
+
74
+ eventManager.publish("ORDRE_TRACTAMENT", "NO_TANCAR", {});
30
75
 
31
- expect(mockPostMessage).toHaveBeenCalledWith(JSON.stringify(expectedEvent), "*");
32
- expect(mockConsoleLog).toHaveBeenCalledWith("method", JSON.stringify(expectedEvent));
76
+ const postedEvent = JSON.parse(mockPostMessage.mock.calls[0][0]);
77
+ expect(postedEvent.diagnostics).toEqual([]);
33
78
  });
34
79
 
35
80
  it("should not fail if window.parent is undefined", () => {
36
81
  (window as any).parent = undefined;
37
82
 
38
- const eventManager = createEcapEventManager();
83
+ const globalStateManager = createMockGlobalStateManager();
84
+ const eventManager = createEcapEventManager(globalStateManager);
39
85
  const payload = { id: "123" };
40
86
 
41
- // No error should be thrown
42
87
  expect(() => {
43
88
  eventManager.publish("custom", "action", payload);
44
89
  }).not.toThrow();
@@ -1,22 +1,42 @@
1
+ import type { PrimariaGlobalStateManager } from "../global-state/global-state";
1
2
  import { IEcapEvent } from "./typings";
2
3
 
4
+ export const LAST_WORKED_DIAGNOSTICS_KEY = "lastWorkedDiagnostics";
5
+
6
+ const EVENTS_WITH_DIAGNOSTICS = [
7
+ "PROVES_ORDRES_CLINIQUES_CONSULTAR",
8
+ "RESULT_OC",
9
+ "LABORATORI_SEROTECA_PETICIO_CONSULTA",
10
+ "ORDRE_TRACTAMENT",
11
+ "PRESCRIPCIO_ACTIVA",
12
+ "REV_IT",
13
+ "OC_EXPRES",
14
+ ] as const;
15
+
3
16
  export abstract class EcapEventManager {
4
17
  /**
5
18
  * Publish an Ecap event.
6
- * @param event - Event name.
7
19
  * @param eventType - Event type.
8
- * @param url - Asociated URL to event.
20
+ * @param accio - Action.
21
+ * @param payload - Additional payload properties.
9
22
  */
10
- abstract publish(eventType: string, accio: string, payload?: Record<string, string>): void;
23
+ abstract publish(eventType: string, accio: string, payload?: Record<string, unknown>): void;
11
24
  }
12
25
 
13
26
  class EcapEventManagerImpl implements EcapEventManager {
14
- publish(eventType: string, accio: string, payload?: Record<string, string>) {
27
+ constructor(private globalStateManager: PrimariaGlobalStateManager) {}
28
+
29
+ publish(eventType: string, accio: string, payload?: Record<string, unknown>) {
15
30
  const ecapEvent = this.createEcapEvent(eventType, accio, payload ?? {});
31
+
32
+ if (EVENTS_WITH_DIAGNOSTICS.includes(eventType as (typeof EVENTS_WITH_DIAGNOSTICS)[number])) {
33
+ ecapEvent.diagnostics = this.globalStateManager.getData<unknown[]>(LAST_WORKED_DIAGNOSTICS_KEY) ?? [];
34
+ }
35
+
16
36
  this.raiseEcapEvent(ecapEvent);
17
37
  }
18
38
 
19
- private createEcapEvent(eventType: string, accio: string, payload: Record<string, string>) {
39
+ private createEcapEvent(eventType: string, accio: string, payload: Record<string, unknown>) {
20
40
  return {
21
41
  TipusEvent: eventType,
22
42
  Accio: accio,
@@ -29,6 +49,5 @@ class EcapEventManagerImpl implements EcapEventManager {
29
49
  }
30
50
  }
31
51
 
32
- const ecapEventManager = new EcapEventManagerImpl();
33
-
34
- export const createEcapEventManager = () => ecapEventManager;
52
+ export const createEcapEventManager = (globalStateManager: PrimariaGlobalStateManager) =>
53
+ new EcapEventManagerImpl(globalStateManager);
@@ -1,5 +1,6 @@
1
1
  export interface IEcapEvent {
2
2
  TipusEvent: string;
3
3
  Accio: string;
4
- [key:string]: string;
4
+ diagnostics?: unknown[];
5
+ [key: string]: unknown;
5
6
  }