@clinicemr/esm-post-registration-redirect-app 1.0.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.
@@ -0,0 +1,15 @@
1
+ .container {
2
+ padding: 1.5rem 2rem;
3
+ max-width: 1200px;
4
+ margin: 0 auto;
5
+ }
6
+
7
+ .title {
8
+ margin-bottom: 1rem;
9
+ font-weight: 600;
10
+ }
11
+
12
+ .emptyTile {
13
+ padding: 2rem;
14
+ text-align: center;
15
+ }
@@ -0,0 +1,62 @@
1
+ import React, { useEffect } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { InlineLoading } from '@carbon/react';
4
+ import { navigate, useConfig, useSession } from '@openmrs/esm-framework';
5
+ import type { PostRegistrationRedirectConfig } from './config-schema';
6
+
7
+ /**
8
+ * Acts as a one-shot redirect target for the patient registration app.
9
+ *
10
+ * Configure `@openmrs/esm-patient-registration-app.links.submitButton` to
11
+ * `${openmrsSpaBase}/post-registration/${patientUuid}`
12
+ * and this component will:
13
+ * - send Registration Clerks to the My Registered Patients list, and
14
+ * - send everyone else to the patient chart (the standard workflow).
15
+ */
16
+ const PostRegistrationRedirect: React.FC = () => {
17
+ const { t } = useTranslation();
18
+ const session = useSession();
19
+ const config = useConfig<PostRegistrationRedirectConfig>();
20
+
21
+ useEffect(() => {
22
+ // Wait until the session is loaded; useSession returns an empty object initially.
23
+ if (!session?.user) return;
24
+
25
+ const patientUuid = extractPatientUuidFromUrl();
26
+ const userRoles: string[] = (session.user.roles ?? []).map((r: { display?: string; name?: string }) =>
27
+ String(r.display ?? r.name ?? ''),
28
+ );
29
+ const isRegistrationClerk = userRoles.some(
30
+ (role) => role.trim().toLowerCase() === config.registrationClerkRoleName.trim().toLowerCase(),
31
+ );
32
+
33
+ if (isRegistrationClerk) {
34
+ navigate({ to: `\${openmrsSpaBase}/${config.registeredPatientsListPath}` });
35
+ } else if (patientUuid) {
36
+ navigate({ to: `\${openmrsSpaBase}/patient/${patientUuid}/chart` });
37
+ } else {
38
+ // No patient UUID in URL — fall back to home rather than the chart of an unknown patient.
39
+ navigate({ to: `\${openmrsSpaBase}/home` });
40
+ }
41
+ }, [session, config.registrationClerkRoleName, config.registeredPatientsListPath]);
42
+
43
+ return (
44
+ <div style={{ padding: '2rem' }}>
45
+ <InlineLoading description={t('redirecting', 'Redirecting…')} />
46
+ </div>
47
+ );
48
+ };
49
+
50
+ /**
51
+ * Pulls the patient UUID out of `/openmrs/spa/post-registration/<uuid>`.
52
+ * Returns an empty string if no UUID-looking segment is present.
53
+ */
54
+ function extractPatientUuidFromUrl(): string {
55
+ const path = window.location.pathname.replace(/\/$/, '');
56
+ const segments = path.split('/');
57
+ const idx = segments.findIndex((s) => s === 'post-registration');
58
+ if (idx === -1 || idx + 1 >= segments.length) return '';
59
+ return segments[idx + 1] ?? '';
60
+ }
61
+
62
+ export default PostRegistrationRedirect;
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://json.openmrs.org/routes.schema.json",
3
+ "backendDependencies": {
4
+ "webservices.rest": ">=2.2.0"
5
+ },
6
+ "pages": [
7
+ {
8
+ "component": "postRegistrationRedirect",
9
+ "route": "post-registration"
10
+ },
11
+ {
12
+ "component": "myRegisteredPatients",
13
+ "route": "my-registered-patients"
14
+ }
15
+ ],
16
+ "extensions": []
17
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "myRegisteredPatients": "My Registered Patients",
3
+ "noPatientsRegistered": "You haven't registered any patients yet.",
4
+ "redirecting": "Redirecting…",
5
+ "patientName": "Name",
6
+ "identifier": "Identifier",
7
+ "gender": "Gender",
8
+ "age": "Age",
9
+ "registeredOn": "Registered on",
10
+ "openChart": "Open chart",
11
+ "errorLoading": "Could not load patients you've registered."
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "esModuleInterop": true,
4
+ "module": "esnext",
5
+ "allowSyntheticDefaultImports": true,
6
+ "jsx": "react",
7
+ "skipLibCheck": true,
8
+ "moduleResolution": "node",
9
+ "lib": ["dom", "es5", "scripthost", "es2015", "es2015.promise", "es2016.array.include", "es2018", "es2020", "es2022"],
10
+ "resolveJsonModule": true,
11
+ "noEmit": true,
12
+ "target": "esnext"
13
+ }
14
+ }
@@ -0,0 +1,16 @@
1
+ const baseConfig = require('openmrs/default-webpack-config');
2
+ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
3
+
4
+ module.exports = function (env, argv) {
5
+ const config = typeof baseConfig === 'function' ? baseConfig(env, argv) : baseConfig;
6
+
7
+ if (config.plugins) {
8
+ config.plugins = config.plugins.filter(
9
+ (plugin) => !(plugin instanceof ForkTsCheckerWebpackPlugin),
10
+ );
11
+ }
12
+
13
+ config.devtool = false;
14
+
15
+ return config;
16
+ };