@kenyaemr/esm-care-panel-app 5.4.2-pre.2308 → 5.4.2-pre.2314

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/dist/routes.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"kenyaemr":"^19.0.0"},"pages":[],"extensions":[{"name":"care-panel-patient-summary","component":"carePanelPatientSummary","slot":"patient-chart-care-panel-dashboard-slot","order":10,"meta":{"columnSpan":4}},{"name":"care-panel-summary-dashboard-link","component":"carePanelSummaryDashboardLink","slot":"patient-chart-dashboard-slot","order":3,"meta":{"columns":1,"columnSpan":1,"slot":"patient-chart-care-panel-dashboard-slot","layoutMode":"anchored","path":"Care panel"}},{"name":"delete-regimen-confirmation-dialog","component":"deleteRegimenConfirmationDialog"},{"name":"hiv-patient-visit-summary-dashboard-link","component":"hivPatientSummaryDashboardLink","slot":"hiv-care-and-treatment-slot","meta":{"columns":1,"columnSpan":1,"slot":"patient-chart-hiv-patient-summary-slot","path":"HIV Patient Summary","layoutMode":"anchored"}},{"name":"hiv-patient-visit-summary","slot":"patient-chart-hiv-patient-summary-slot","component":"hivPatientSummary","order":3,"online":true,"offline":false},{"name":"dispensing-patient-vitals","component":"dispensingPaentientVitals","slot":"dispensing-condition-and-diagnoses","order":1,"online":true,"offline":true},{"name":"patient-discharge-side-rail-icon","component":"patientDischargeSideRailIcon","slot":"action-menu-ward-patient-items-slot"}],"workspaces":[{"name":"patient-regimen-workspace","title":"Patient Regimen","component":"regimenFormWorkspace","type":"form","canMaximize":true,"canHide":true,"width":"wider"},{"name":"patient-care-discharge-workspace","title":"Patient Discharge","component":"patientDischargeWorkspace","type":"workspace","canMaximize":true,"canHide":true,"width":"extra-wide","groups":["ward-patient"]}],"version":"5.4.2-pre.2308"}
1
+ {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"kenyaemr":"^19.0.0"},"pages":[],"extensions":[{"name":"care-panel-patient-summary","component":"carePanelPatientSummary","slot":"patient-chart-care-panel-dashboard-slot","order":10,"meta":{"columnSpan":4}},{"name":"care-panel-summary-dashboard-link","component":"carePanelSummaryDashboardLink","slot":"patient-chart-dashboard-slot","order":3,"meta":{"columns":1,"columnSpan":1,"slot":"patient-chart-care-panel-dashboard-slot","layoutMode":"anchored","path":"Care panel"}},{"name":"delete-regimen-confirmation-dialog","component":"deleteRegimenConfirmationDialog"},{"name":"hiv-patient-visit-summary-dashboard-link","component":"hivPatientSummaryDashboardLink","slot":"hiv-care-and-treatment-slot","meta":{"columns":1,"columnSpan":1,"slot":"patient-chart-hiv-patient-summary-slot","path":"HIV Patient Summary","layoutMode":"anchored"}},{"name":"hiv-patient-visit-summary","slot":"patient-chart-hiv-patient-summary-slot","component":"hivPatientSummary","order":3,"online":true,"offline":false},{"name":"dispensing-patient-vitals","component":"dispensingPaentientVitals","slot":"dispensing-condition-and-diagnoses","order":1,"online":true,"offline":true},{"name":"patient-discharge-side-rail-icon","component":"patientDischargeSideRailIcon","slot":"action-menu-ward-patient-items-slot"}],"workspaces":[{"name":"patient-regimen-workspace","title":"Patient Regimen","component":"regimenFormWorkspace","type":"form","canMaximize":true,"canHide":true,"width":"wider"},{"name":"patient-care-discharge-workspace","title":"Patient Discharge","component":"patientDischargeWorkspace","type":"workspace","canMaximize":true,"canHide":true,"width":"extra-wide","groups":["ward-patient"]}],"version":"5.4.2-pre.2314"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kenyaemr/esm-care-panel-app",
3
- "version": "5.4.2-pre.2308",
3
+ "version": "5.4.2-pre.2314",
4
4
  "description": "Patient care panels microfrontend for the OpenMRS SPA",
5
5
  "browser": "dist/kenyaemr-esm-care-panel-app.js",
6
6
  "main": "src/index.ts",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "lodash-es": "^4.17.15",
41
- "react-to-print": "^3.1.0"
41
+ "react-to-print": "2.14.13"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@carbon/react": "1.x",
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
2
  import dayjs from 'dayjs';
3
3
  import userEvent from '@testing-library/user-event';
4
- import { render, screen } from '@testing-library/react';
5
- import { useReactToPrint } from 'react-to-print';
4
+ import { render, screen, act } from '@testing-library/react';
6
5
  import { useConfig } from '@openmrs/esm-framework';
7
6
  import { usePatientSummary } from '../hooks/usePatientSummary';
8
7
  import { mockPatient } from '../../../../__mocks__/patient-summary.mock';
@@ -12,15 +11,20 @@ jest.mock('../hooks/usePatientSummary');
12
11
 
13
12
  const mockedUseConfig = useConfig as jest.Mock;
14
13
  const mockedUsePatientSummary = usePatientSummary as jest.Mock;
15
- const mockedUseReactToPrint = jest.mocked(useReactToPrint);
16
14
 
17
- jest.mock('react-to-print', () => {
18
- const originalModule = jest.requireActual('react-to-print');
15
+ // Mock window.open and window.print
16
+ const mockOpen = jest.fn();
17
+ const mockPrint = jest.fn();
18
+ const mockClose = jest.fn();
19
19
 
20
- return {
21
- ...originalModule,
22
- useReactToPrint: jest.fn().mockReturnValue(jest.fn()),
23
- };
20
+ Object.defineProperty(window, 'open', {
21
+ writable: true,
22
+ value: mockOpen,
23
+ });
24
+
25
+ Object.defineProperty(window, 'print', {
26
+ writable: true,
27
+ value: mockPrint,
24
28
  });
25
29
 
26
30
  describe('PatientSummary', () => {
@@ -30,13 +34,18 @@ describe('PatientSummary', () => {
30
34
  error: false,
31
35
  isLoading: true,
32
36
  });
37
+
38
+ // Reset mocks
39
+ mockOpen.mockClear();
40
+ mockPrint.mockClear();
41
+ mockClose.mockClear();
33
42
  });
34
43
 
35
44
  afterEach(() => jest.clearAllMocks());
36
45
 
37
46
  it('renders a skeleton loader when loading', () => {
38
47
  render(<PatientSummary patientUuid={mockPatient.uuid} />);
39
- const skeletonLoader = screen.getByRole('progressbar');
48
+ const skeletonLoader = document.querySelector('.cds--skeleton');
40
49
  expect(skeletonLoader).toBeInTheDocument();
41
50
  });
42
51
 
@@ -99,6 +108,18 @@ describe('PatientSummary', () => {
99
108
 
100
109
  mockedUseConfig.mockReturnValue({ logo: {} });
101
110
 
111
+ // Mock the print window
112
+ const mockPrintWindow = {
113
+ document: {
114
+ write: jest.fn(),
115
+ close: jest.fn(),
116
+ },
117
+ focus: jest.fn(),
118
+ print: jest.fn(),
119
+ close: jest.fn(),
120
+ };
121
+ mockOpen.mockReturnValue(mockPrintWindow);
122
+
102
123
  render(<PatientSummary patientUuid={mockPatient.uuid} />);
103
124
 
104
125
  const printButton = screen.getByRole('button', { name: /print/i });
@@ -107,7 +128,12 @@ describe('PatientSummary', () => {
107
128
  await screen.findByText(/patient summary/i);
108
129
  await user.click(printButton);
109
130
 
110
- // FIXME: Why does this happen twice?
111
- expect(mockedUseReactToPrint).toHaveBeenCalled();
131
+ // Wait for the print functionality to be triggered
132
+ await act(async () => {
133
+ await new Promise((resolve) => setTimeout(resolve, 150));
134
+ });
135
+
136
+ // Verify that window.open was called
137
+ expect(mockOpen).toHaveBeenCalledWith('', '_blank');
112
138
  });
113
139
  });
@@ -1,8 +1,7 @@
1
- import React, { useRef, useState, useEffect } from 'react';
1
+ import React, { useRef, useState, useEffect, useCallback } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import { StructuredListSkeleton } from '@carbon/react';
4
4
  import { usePatientSummary } from '../hooks/usePatientSummary';
5
- import { useReactToPrint } from 'react-to-print';
6
5
  import PrintComponent from '../print-layout/print.component';
7
6
  import PatientSummaryHeader from './patient-summary-header.component';
8
7
  import PatientSummaryBody from './patient-summary-body.component';
@@ -19,13 +18,25 @@ const PatientSummary: React.FC<PatientSummaryProps> = ({ patientUuid }) => {
19
18
  const printRef = useRef<HTMLDivElement>(null);
20
19
  const [showPrintComponent, setShowPrintComponent] = useState(false);
21
20
 
22
- const handlePrint = useReactToPrint({
23
- contentRef: printRef,
24
- documentTitle: 'Patient Summary',
25
- onAfterPrint: () => {
26
- setShowPrintComponent(false);
27
- },
28
- });
21
+ const handlePrint = useCallback(async () => {
22
+ try {
23
+ // TODO: use backend to generate the print content
24
+ if (printRef.current) {
25
+ const printWindow = window.open('', '_blank');
26
+ if (printWindow) {
27
+ const printContent = printRef.current.innerHTML;
28
+ printWindow.document.documentElement.innerHTML = printContent;
29
+ printWindow.focus();
30
+ printWindow.print();
31
+ printWindow.close();
32
+ }
33
+ }
34
+ } catch (error) {
35
+ console.error('Print error:', error);
36
+ // Fallback to browser print
37
+ window.print();
38
+ }
39
+ }, []);
29
40
 
30
41
  const onPrintClick = () => {
31
42
  setShowPrintComponent(true);
@@ -33,7 +44,11 @@ const PatientSummary: React.FC<PatientSummaryProps> = ({ patientUuid }) => {
33
44
 
34
45
  useEffect(() => {
35
46
  if (showPrintComponent && printRef.current) {
36
- handlePrint?.();
47
+ // Use setTimeout to ensure the component is fully rendered
48
+ setTimeout(() => {
49
+ handlePrint();
50
+ setShowPrintComponent(false);
51
+ }, 100);
37
52
  }
38
53
  }, [showPrintComponent, handlePrint]);
39
54