@blackcode_sa/metaestetics-api 1.7.45 → 1.8.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.
Files changed (55) hide show
  1. package/dist/admin/index.d.mts +999 -959
  2. package/dist/admin/index.d.ts +999 -959
  3. package/dist/admin/index.js +69 -69
  4. package/dist/admin/index.mjs +67 -69
  5. package/dist/index.d.mts +14675 -13040
  6. package/dist/index.d.ts +14675 -13040
  7. package/dist/index.js +12224 -14615
  8. package/dist/index.mjs +12452 -14968
  9. package/package.json +5 -5
  10. package/src/admin/index.ts +8 -1
  11. package/src/index.backup.ts +407 -0
  12. package/src/index.ts +5 -406
  13. package/src/services/PATIENTAUTH.MD +197 -0
  14. package/src/services/__tests__/auth/auth.setup.ts +2 -2
  15. package/src/services/__tests__/auth.service.test.ts +1 -1
  16. package/src/services/__tests__/user.service.test.ts +1 -1
  17. package/src/services/appointment/index.ts +1 -2
  18. package/src/services/{auth.service.ts → auth/auth.service.ts} +36 -22
  19. package/src/services/{auth.v2.service.ts → auth/auth.v2.service.ts} +17 -17
  20. package/src/services/auth/index.ts +2 -16
  21. package/src/services/calendar/calendar-refactored.service.ts +1 -1
  22. package/src/services/calendar/externalCalendar.service.ts +178 -0
  23. package/src/services/calendar/index.ts +5 -0
  24. package/src/services/clinic/index.ts +4 -0
  25. package/src/services/index.ts +14 -0
  26. package/src/services/media/index.ts +1 -0
  27. package/src/services/notifications/index.ts +1 -0
  28. package/src/services/patient/README.md +48 -0
  29. package/src/services/patient/To-Do.md +43 -0
  30. package/src/services/patient/index.ts +2 -0
  31. package/src/services/patient/patient.service.ts +289 -34
  32. package/src/services/patient/utils/index.ts +9 -0
  33. package/src/services/patient/utils/medical.utils.ts +114 -157
  34. package/src/services/patient/utils/profile.utils.ts +9 -0
  35. package/src/services/patient/utils/sensitive.utils.ts +79 -14
  36. package/src/services/patient/utils/token.utils.ts +211 -0
  37. package/src/services/practitioner/index.ts +1 -0
  38. package/src/services/procedure/index.ts +1 -0
  39. package/src/services/reviews/index.ts +1 -0
  40. package/src/services/user/index.ts +1 -0
  41. package/src/services/{user.service.ts → user/user.service.ts} +61 -12
  42. package/src/services/{user.v2.service.ts → user/user.v2.service.ts} +12 -12
  43. package/src/types/index.ts +42 -42
  44. package/src/types/patient/index.ts +33 -6
  45. package/src/types/patient/token.types.ts +61 -0
  46. package/src/types/user/index.ts +38 -0
  47. package/src/utils/index.ts +1 -0
  48. package/src/validations/calendar.schema.ts +6 -45
  49. package/src/validations/documentation-templates/index.ts +1 -0
  50. package/src/validations/documentation-templates.schema.ts +1 -1
  51. package/src/validations/index.ts +20 -0
  52. package/src/validations/patient/token.schema.ts +29 -0
  53. package/src/validations/patient.schema.ts +23 -6
  54. package/src/validations/profile-info.schema.ts +1 -1
  55. package/src/validations/schemas.ts +24 -24
@@ -38,18 +38,18 @@ import {
38
38
  Firestore,
39
39
  } from "firebase/firestore";
40
40
  import { FirebaseApp } from "firebase/app";
41
- import { User, UserRole, USERS_COLLECTION } from "../types";
41
+ import { User, UserRole, USERS_COLLECTION } from "../../types";
42
42
  import { z } from "zod";
43
43
  import {
44
44
  emailSchema,
45
45
  passwordSchema,
46
46
  userRoleSchema,
47
- } from "../validations/schemas";
48
- import { AuthError, AUTH_ERRORS } from "../errors/auth.errors";
49
- import { FirebaseErrorCode } from "../errors/firebase.errors";
50
- import { FirebaseError } from "../errors/firebase.errors";
51
- import { BaseService } from "./base.service";
52
- import { UserService } from "./user.service";
47
+ } from "../../validations/schemas";
48
+ import { AuthError, AUTH_ERRORS } from "../../errors/auth.errors";
49
+ import { FirebaseErrorCode } from "../../errors/firebase.errors";
50
+ import { FirebaseError } from "../../errors/firebase.errors";
51
+ import { BaseService } from "../base.service";
52
+ import { UserService } from "../user/user.service";
53
53
  import { throws } from "assert";
54
54
  import {
55
55
  ClinicGroup,
@@ -62,22 +62,22 @@ import {
62
62
  SubscriptionModel,
63
63
  CLINIC_GROUPS_COLLECTION,
64
64
  ClinicAdmin,
65
- } from "../types/clinic";
66
- import { clinicAdminSignupSchema } from "../validations/clinic.schema";
67
- import { ClinicGroupService } from "./clinic/clinic-group.service";
68
- import { ClinicAdminService } from "./clinic/clinic-admin.service";
69
- import { ClinicService } from "./clinic/clinic.service";
65
+ } from "../../types/clinic";
66
+ import { clinicAdminSignupSchema } from "../../validations/clinic.schema";
67
+ import { ClinicGroupService } from "../clinic/clinic-group.service";
68
+ import { ClinicAdminService } from "../clinic/clinic-admin.service";
69
+ import { ClinicService } from "../clinic/clinic.service";
70
70
  import {
71
71
  Practitioner,
72
72
  CreatePractitionerData,
73
73
  PractitionerStatus,
74
74
  PractitionerBasicInfo,
75
75
  PractitionerCertification,
76
- } from "../types/practitioner";
77
- import { PractitionerService } from "./practitioner/practitioner.service";
78
- import { practitionerSignupSchema } from "../validations/practitioner.schema";
79
- import { CertificationLevel } from "../backoffice/types/static/certification.types";
80
- import { MediaService } from "./media/media.service";
76
+ } from "../../types/practitioner";
77
+ import { PractitionerService } from "../practitioner/practitioner.service";
78
+ import { practitionerSignupSchema } from "../../validations/practitioner.schema";
79
+ import { CertificationLevel } from "../../backoffice/types/static/certification.types";
80
+ import { MediaService } from "../media/media.service";
81
81
  // Import utility functions
82
82
  import {
83
83
  checkEmailExists,
@@ -86,7 +86,7 @@ import {
86
86
  handleSignupError,
87
87
  buildPractitionerData,
88
88
  validatePractitionerProfileData,
89
- } from "./auth/utils";
89
+ } from "./utils";
90
90
 
91
91
  export class AuthService extends BaseService {
92
92
  private googleProvider = new GoogleAuthProvider();
@@ -110,7 +110,10 @@ export class AuthService extends BaseService {
110
110
  async signUp(
111
111
  email: string,
112
112
  password: string,
113
- initialRole: UserRole = UserRole.PATIENT
113
+ initialRole: UserRole = UserRole.PATIENT,
114
+ options?: {
115
+ patientInviteToken?: string;
116
+ }
114
117
  ): Promise<User> {
115
118
  const { user: firebaseUser } = await createUserWithEmailAndPassword(
116
119
  this.auth,
@@ -118,7 +121,7 @@ export class AuthService extends BaseService {
118
121
  password
119
122
  );
120
123
 
121
- return this.userService.createUser(firebaseUser, [initialRole]);
124
+ return this.userService.createUser(firebaseUser, [initialRole], options);
122
125
  }
123
126
 
124
127
  /**
@@ -608,14 +611,25 @@ export class AuthService extends BaseService {
608
611
  * Prijavljuje korisnika sa Google nalogom
609
612
  */
610
613
  async signInWithGoogle(
611
- initialRole: UserRole = UserRole.PATIENT
614
+ initialRole: UserRole = UserRole.PATIENT,
615
+ options?: {
616
+ patientInviteToken?: string;
617
+ }
612
618
  ): Promise<User> {
613
619
  const { user: firebaseUser } = await signInWithPopup(
614
620
  this.auth,
615
621
  this.googleProvider
616
622
  );
617
623
 
618
- return this.userService.getOrCreateUser(firebaseUser);
624
+ const existingUser = await this.userService.getUserByEmail(
625
+ firebaseUser.email!
626
+ );
627
+ if (existingUser) {
628
+ await this.userService.updateUserLoginTimestamp(existingUser.uid);
629
+ return existingUser;
630
+ }
631
+
632
+ return this.userService.createUser(firebaseUser, [initialRole], options);
619
633
  }
620
634
 
621
635
  /**
@@ -33,18 +33,18 @@ import {
33
33
  Firestore,
34
34
  } from "firebase/firestore";
35
35
  import { FirebaseApp } from "firebase/app";
36
- import { User, UserRole, USERS_COLLECTION } from "../types";
36
+ import { User, UserRole, USERS_COLLECTION } from "../../types";
37
37
  import { z } from "zod";
38
38
  import {
39
39
  emailSchema,
40
40
  passwordSchema,
41
41
  userRoleSchema,
42
- } from "../validations/schemas";
43
- import { AuthError, AUTH_ERRORS } from "../errors/auth.errors";
44
- import { FirebaseErrorCode } from "../errors/firebase.errors";
45
- import { FirebaseError } from "../errors/firebase.errors";
46
- import { BaseService } from "./base.service";
47
- import { UserService } from "./user.service";
42
+ } from "../../validations/schemas";
43
+ import { AuthError, AUTH_ERRORS } from "../../errors/auth.errors";
44
+ import { FirebaseErrorCode } from "../../errors/firebase.errors";
45
+ import { FirebaseError } from "../../errors/firebase.errors";
46
+ import { BaseService } from "../base.service";
47
+ import { UserService } from "../user/user.service";
48
48
  import { throws } from "assert";
49
49
  import {
50
50
  ClinicGroup,
@@ -57,22 +57,22 @@ import {
57
57
  SubscriptionModel,
58
58
  CLINIC_GROUPS_COLLECTION,
59
59
  ClinicAdmin,
60
- } from "../types/clinic";
61
- import { clinicAdminSignupSchema } from "../validations/clinic.schema";
62
- import { ClinicGroupService } from "./clinic/clinic-group.service";
63
- import { ClinicAdminService } from "./clinic/clinic-admin.service";
64
- import { ClinicService } from "./clinic/clinic.service";
60
+ } from "../../types/clinic";
61
+ import { clinicAdminSignupSchema } from "../../validations/clinic.schema";
62
+ import { ClinicGroupService } from "../clinic/clinic-group.service";
63
+ import { ClinicAdminService } from "../clinic/clinic-admin.service";
64
+ import { ClinicService } from "../clinic/clinic.service";
65
65
  import {
66
66
  Practitioner,
67
67
  CreatePractitionerData,
68
68
  PractitionerStatus,
69
69
  PractitionerBasicInfo,
70
70
  PractitionerCertification,
71
- } from "../types/practitioner";
72
- import { PractitionerService } from "./practitioner/practitioner.service";
73
- import { practitionerSignupSchema } from "../validations/practitioner.schema";
74
- import { CertificationLevel } from "../backoffice/types/static/certification.types";
75
- import { getFirebaseFunctions } from "../config/firebase";
71
+ } from "../../types/practitioner";
72
+ import { PractitionerService } from "../practitioner/practitioner.service";
73
+ import { practitionerSignupSchema } from "../../validations/practitioner.schema";
74
+ import { CertificationLevel } from "../../backoffice/types/static/certification.types";
75
+ import { getFirebaseFunctions } from "../../config/firebase";
76
76
  import {
77
77
  httpsCallable,
78
78
  HttpsCallableResult,
@@ -3,19 +3,5 @@
3
3
  * Centralized exports for all utility modules
4
4
  */
5
5
 
6
- // Firebase utilities
7
- export { checkEmailExists, cleanupFirebaseUser } from "./utils/firebase.utils";
8
-
9
- // Error handling utilities
10
- export {
11
- handleFirebaseError,
12
- handleSignupError,
13
- extractErrorMessage,
14
- } from "./utils/error.utils";
15
-
16
- // Practitioner utilities
17
- export {
18
- buildPractitionerData,
19
- validatePractitionerProfileData,
20
- isPractitionerDataComplete,
21
- } from "./utils/practitioner.utils";
6
+ export * from "./utils";
7
+ export * from "./auth.service";
@@ -52,7 +52,7 @@ import {
52
52
  import {
53
53
  createAppointmentSchema,
54
54
  updateAppointmentSchema,
55
- } from "../../validations/calendar.schema";
55
+ } from "../../validations/appointment.schema";
56
56
 
57
57
  // Import utility functions
58
58
  import {
@@ -0,0 +1,178 @@
1
+ import { Auth } from "firebase/auth";
2
+ import { Firestore } from "firebase/firestore";
3
+ import { FirebaseApp } from "firebase/app";
4
+ import { BaseService } from "../base.service";
5
+
6
+ /**
7
+ * IMPORTANT: This URL should be loaded from an environment configuration
8
+ * (e.g., .env file) and should point to your deployed `externalCalendarApi`
9
+ * Cloud Function.
10
+ */
11
+ const EXTERNAL_CALENDAR_API_BASE_URL =
12
+ "https://europe-west6-your-project-id.cloudfunctions.net/externalCalendarApi";
13
+
14
+ /**
15
+ * Interface for the `generateAuthUrl` endpoint response.
16
+ */
17
+ interface GenerateAuthUrlResponse {
18
+ success: boolean;
19
+ authUrl?: string;
20
+ error?: string;
21
+ }
22
+
23
+ /**
24
+ * Interface for a generic API response for success/error status.
25
+ */
26
+ interface ApiResponse {
27
+ success: boolean;
28
+ error?: string;
29
+ [key: string]: any;
30
+ }
31
+
32
+ /**
33
+ * Interface for the `getConnectionStatus` endpoint response.
34
+ */
35
+ interface ConnectionStatusResponse {
36
+ success: boolean;
37
+ isConnected: boolean;
38
+ connectionDetails?: {
39
+ syncStatus: string;
40
+ calendarId?: string;
41
+ };
42
+ error?: string;
43
+ }
44
+
45
+ /**
46
+ * External Calendar Service
47
+ *
48
+ * This service acts as a client-side wrapper (SDK) for the `externalCalendarApi`
49
+ * Firebase Cloud Function. It handles making authenticated HTTP requests from the
50
+ * frontend applications (web, mobile) to the backend, ensuring that no sensitive
51
+ * logic resides on the client.
52
+ */
53
+ export class ExternalCalendarService extends BaseService {
54
+ /**
55
+ * Creates a new ExternalCalendarService instance.
56
+ * @param db - Firestore instance.
57
+ * @param auth - Firebase Auth instance.
58
+ * @param app - Firebase App instance.
59
+ */
60
+ constructor(db: Firestore, auth: Auth, app: FirebaseApp) {
61
+ super(db, auth, app);
62
+ }
63
+
64
+ /**
65
+ * A private helper method to make authenticated calls to our backend API.
66
+ * @param endpoint - The API endpoint to call (e.g., '/generateAuthUrl').
67
+ * @param body - The JSON body for the request.
68
+ * @returns A promise that resolves to the JSON response from the API.
69
+ * @throws An error if the user is not authenticated or the network request fails.
70
+ */
71
+ private async callApi<T>(endpoint: string, body: object): Promise<T> {
72
+ if (!this.auth.currentUser) {
73
+ throw new Error("User not authenticated. Cannot call API.");
74
+ }
75
+
76
+ const idToken = await this.auth.currentUser.getIdToken();
77
+ const url = `${EXTERNAL_CALENDAR_API_BASE_URL}${endpoint}`;
78
+
79
+ const response = await fetch(url, {
80
+ method: "POST",
81
+ headers: {
82
+ "Content-Type": "application/json",
83
+ Authorization: `Bearer ${idToken}`,
84
+ },
85
+ body: JSON.stringify(body),
86
+ });
87
+
88
+ if (!response.ok) {
89
+ const errorBody = await response
90
+ .json()
91
+ .catch(() => ({ error: "A network error occurred." }));
92
+ throw new Error(
93
+ errorBody.error || `HTTP error! status: ${response.status}`
94
+ );
95
+ }
96
+
97
+ return response.json() as Promise<T>;
98
+ }
99
+
100
+ /**
101
+ * Requests an authorization URL from the backend to initiate the Google Calendar connection.
102
+ * This is the first step in the OAuth flow.
103
+ *
104
+ * @param entityType - The type of entity connecting the calendar ('practitioner', 'clinic', or 'patient').
105
+ * @param entityId - The unique ID of the entity.
106
+ * @param platform - The platform initiating the request ('web', 'ios', 'android').
107
+ * @returns The Google OAuth 2.0 URL to which the user should be redirected.
108
+ * @throws An error if the API call fails to return a valid URL.
109
+ */
110
+ async generateAuthUrl(
111
+ entityType: "practitioner" | "clinic" | "patient",
112
+ entityId: string,
113
+ platform: "web" | "ios" | "android"
114
+ ): Promise<string> {
115
+ const response = await this.callApi<GenerateAuthUrlResponse>(
116
+ "/generateAuthUrl",
117
+ {
118
+ entityType,
119
+ entityId,
120
+ platform,
121
+ }
122
+ );
123
+
124
+ if (!response.success || !response.authUrl) {
125
+ throw new Error(
126
+ response.error || "Failed to generate authentication URL."
127
+ );
128
+ }
129
+
130
+ return response.authUrl;
131
+ }
132
+
133
+ /**
134
+ * Sends a request to the backend to disconnect a Google Calendar from an entity.
135
+ * This will revoke the tokens and remove the sync data from Firestore.
136
+ *
137
+ * @param entityType - The type of entity to disconnect.
138
+ * @param entityId - The ID of the entity.
139
+ * @returns A promise that resolves when the operation is successful.
140
+ * @throws An error if the API call fails.
141
+ */
142
+ async disconnectCalendar(
143
+ entityType: "practitioner" | "clinic" | "patient",
144
+ entityId: string
145
+ ): Promise<void> {
146
+ const response = await this.callApi<ApiResponse>("/disconnect", {
147
+ entityType,
148
+ entityId,
149
+ });
150
+
151
+ if (!response.success) {
152
+ throw new Error(response.error || "Failed to disconnect calendar.");
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Gets the connection status of an entity's Google Calendar.
158
+ * This is useful for UI to determine whether to show a 'Connect' or 'Disconnect' button.
159
+ *
160
+ * @param entityType - The type of entity to check.
161
+ * @param entityId - The ID of the entity.
162
+ * @returns An object containing the connection status and details.
163
+ */
164
+ async getCalendarConnectionStatus(
165
+ entityType: "practitioner" | "clinic" | "patient",
166
+ entityId: string
167
+ ): Promise<ConnectionStatusResponse> {
168
+ const response = await this.callApi<ConnectionStatusResponse>(
169
+ "/getConnectionStatus",
170
+ {
171
+ entityType,
172
+ entityId,
173
+ }
174
+ );
175
+
176
+ return response;
177
+ }
178
+ }
@@ -0,0 +1,5 @@
1
+ // export * from "./calendar-refactored.service";
2
+ // export * from "./calendar.service";
3
+ export * from "./calendar.v3.service";
4
+ export * from "./externalCalendar.service";
5
+ // export * from "./synced-calendars.service";
@@ -0,0 +1,4 @@
1
+ export * from "./clinic.service";
2
+ export * from "./clinic-admin.service";
3
+ export * from "./clinic-group.service";
4
+ export * from "./practitioner-invite.service";
@@ -0,0 +1,14 @@
1
+ export * from "./auth/";
2
+ export * from "./user/";
3
+
4
+ // export * from "./base.service";
5
+ export * from "./appointment/";
6
+ export * from "./calendar/";
7
+ export * from "./clinic/";
8
+ export * from "./documentation-templates/";
9
+ export * from "./media/";
10
+ export * from "./notifications/";
11
+ export * from "./patient/";
12
+ export * from "./practitioner/";
13
+ export * from "./procedure/";
14
+ export * from "./reviews/";
@@ -0,0 +1 @@
1
+ export * from "./media.service";
@@ -0,0 +1 @@
1
+ export * from "./notification.service";
@@ -0,0 +1,48 @@
1
+ # Patient Service
2
+
3
+ This service provides a comprehensive API for managing patient-related data within the application. It handles the creation, retrieval, and updating of patient profiles, as well as their sensitive, medical, and location-based information.
4
+
5
+ ## Core Responsibilities
6
+
7
+ - **Patient Profile Management**: Creating standard (user-linked) and manual (offline) patient profiles.
8
+ - **Data Segregation**: Manages different aspects of patient data in separate sub-collections for enhanced security and privacy:
9
+ - `sensitive-info`: Personal Identifiable Information (PII) like name, DOB, and contact details.
10
+ - `medical-info`: Health-related data including allergies, conditions, and medications.
11
+ - `location-info`: Geolocation data for search and mapping features.
12
+ - **Security**: Enforces role-based access control, ensuring that only authorized users (patients, practitioners, clinic admins) can access or modify patient data.
13
+
14
+ ## Key Methods
15
+
16
+ ### `createPatientProfile(data: CreatePatientProfileData)`
17
+
18
+ - Creates a standard patient profile linked to an existing, authenticated user account via `userRef`.
19
+ - This is the standard flow for patients registering through the application.
20
+
21
+ ### `createManualPatient(data: CreateManualPatientData, requester: RequesterInfo)`
22
+
23
+ - Allows a `clinic_admin` to create a patient profile that is **not** linked to a user account.
24
+ - This is designed for managing "offline" patients within the clinic's ecosystem.
25
+ - The `isManual` flag is set to `true` on the profile.
26
+ - The patient is automatically associated with the admin's clinic.
27
+
28
+ ### `getPatientProfile(patientId: string)`
29
+
30
+ - Retrieves the public-facing profile of a patient.
31
+
32
+ ### `getSensitiveInfo(patientId: string, requesterUserId: string)`
33
+
34
+ - Retrieves the sensitive PII of a patient. Access is restricted and requires proper authorization.
35
+
36
+ ### `getMedicalInfo(patientId:string)`
37
+
38
+ - Retrieves the medical information for a patient. Access is strictly controlled based on the requester's permissions.
39
+
40
+ ## Data Models
41
+
42
+ The main data models used by this service are:
43
+
44
+ - `PatientProfile`: The core, top-level patient document.
45
+ - `PatientSensitiveInfo`: Sub-collection for private, personal data.
46
+ - `PatientMedicalInfo`: Sub-collection for health records.
47
+
48
+ For detailed information on the data structures, see `Api/src/types/patient/index.ts`.
@@ -0,0 +1,43 @@
1
+ # To-Do: Manual Patient Creation
2
+
3
+ This document outlines the steps required to implement the manual creation of patient profiles by clinic admins. This allows clinics to manage patients who do not yet have an account in the patient application.
4
+
5
+ ## Phase 1: Core Implementation (No User Link)
6
+
7
+ ### 1. Update Data Models and Types (`types/patient/index.ts`)
8
+
9
+ - [ ] Modify `PatientProfile` to make `userRef` optional.
10
+ - [ ] Modify `CreatePatientProfileData` to make `userRef` optional.
11
+ - [ ] Add a new field `isManual: boolean` to `PatientProfile` and `CreatePatientProfileData` to flag patients created without a user account.
12
+ - [ ] Modify `PatientSensitiveInfo` to make `userRef` optional.
13
+ - [ ] Modify `CreatePatientSensitiveInfoData` to make `userRef` optional.
14
+ - [ ] Create a new type `CreateManualPatientData` that combines necessary fields from `CreatePatientProfileData` and `CreatePatientSensitiveInfoData`, but tailored for manual creation (e.g., requires `firstName`, `lastName`, `clinicId`).
15
+
16
+ ### 2. Update Validation Schemas (`validations/patient.schema.ts`)
17
+
18
+ - [ ] Update `patientProfileSchema` to reflect that `userRef` is optional.
19
+ - [ ] Update `createPatientProfileSchema` to make `userRef` optional and include `isManual`.
20
+ - [ ] Update `patientSensitiveInfoSchema` to reflect that `userRef` is optional.
21
+ - [ ] Update `createPatientSensitiveInfoSchema` to make `userRef` optional.
22
+ - [ ] Create a new schema `createManualPatientSchema` to validate the input for the new service method.
23
+
24
+ ### 3. Implement New Service Method (`services/patient/patient.service.ts`)
25
+
26
+ - [ ] Create a new public method: `createManualPatient(data: CreateManualPatientData, requester: RequesterInfo): Promise<PatientProfile>`.
27
+ - [ ] The method should perform security checks to ensure the requester is a `clinic_admin`.
28
+ - [ ] Inside the method:
29
+ - Generate a new `patientId`.
30
+ - Create a `PatientProfile` object with `isManual: true`, no `userRef`, and link it to the admin's clinic (`requester.associatedClinicId`).
31
+ - Create a `PatientSensitiveInfo` object with the provided patient details.
32
+ - Use a Firestore batch write to create both documents atomically.
33
+ - Return the newly created `PatientProfile`.
34
+
35
+ ### 4. Documentation & README
36
+
37
+ - [ ] Update the `Api/docs/guides/patient-management.md` to document the new manual creation flow.
38
+ - [ ] Create a `README.md` file in `Api/src/services/patient/` explaining the purpose of the service and its key methods, including `createManualPatient`.
39
+
40
+ ## Phase 2: Future Enhancements (Post-MVP)
41
+
42
+ - [ ] **Claim/Merge Profile:** Implement logic for a patient to claim a manually created profile when they register for the app. This could involve an invitation flow or matching based on personal details.
43
+ - [ ] **UI Implementation:** Develop the UI components in the Backoffice/Clinic app for clinic admins to use this new functionality.
@@ -0,0 +1,2 @@
1
+ export * from "./patient.service";
2
+ export * from "./patientRequirements.service";