@blackcode_sa/metaestetics-api 1.7.47 → 1.8.1

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 (83) hide show
  1. package/dist/admin/index.d.mts +1815 -1667
  2. package/dist/admin/index.d.ts +1815 -1667
  3. package/dist/admin/index.js +6993 -6535
  4. package/dist/admin/index.mjs +6991 -6532
  5. package/dist/backoffice/index.d.mts +1418 -1418
  6. package/dist/backoffice/index.d.ts +1418 -1418
  7. package/dist/backoffice/index.js +1464 -1454
  8. package/dist/backoffice/index.mjs +1509 -1499
  9. package/dist/index.d.mts +16217 -14582
  10. package/dist/index.d.ts +16217 -14582
  11. package/dist/index.js +11419 -13806
  12. package/dist/index.mjs +12081 -14593
  13. package/package.json +5 -5
  14. package/src/admin/aggregation/appointment/index.ts +1 -0
  15. package/src/admin/aggregation/clinic/index.ts +1 -0
  16. package/src/admin/aggregation/forms/index.ts +1 -0
  17. package/src/admin/aggregation/index.ts +8 -0
  18. package/src/admin/aggregation/patient/index.ts +1 -0
  19. package/src/admin/aggregation/practitioner/index.ts +1 -0
  20. package/src/admin/aggregation/practitioner-invite/index.ts +1 -0
  21. package/src/admin/aggregation/procedure/index.ts +1 -0
  22. package/src/admin/aggregation/reviews/index.ts +1 -0
  23. package/src/admin/booking/index.ts +1 -1
  24. package/src/admin/calendar/index.ts +1 -0
  25. package/src/admin/documentation-templates/index.ts +1 -0
  26. package/src/admin/free-consultation/index.ts +1 -0
  27. package/src/admin/index.ts +23 -118
  28. package/src/admin/mailing/appointment/index.ts +1 -0
  29. package/src/admin/mailing/index.ts +1 -2
  30. package/src/admin/mailing/practitionerInvite/index.ts +1 -0
  31. package/src/admin/notifications/index.ts +1 -0
  32. package/src/admin/requirements/index.ts +1 -0
  33. package/src/admin/users/index.ts +1 -0
  34. package/src/admin/users/user-profile.admin.ts +1 -0
  35. package/src/backoffice/constants/index.ts +1 -0
  36. package/src/backoffice/errors/index.ts +1 -0
  37. package/src/backoffice/index.ts +5 -14
  38. package/src/backoffice/services/index.ts +7 -0
  39. package/src/backoffice/validations/index.ts +1 -0
  40. package/src/index.backup.ts +407 -0
  41. package/src/index.ts +5 -406
  42. package/src/services/PATIENTAUTH.MD +197 -0
  43. package/src/services/__tests__/auth/auth.setup.ts +2 -2
  44. package/src/services/__tests__/auth.service.test.ts +1 -1
  45. package/src/services/__tests__/user.service.test.ts +1 -1
  46. package/src/services/appointment/index.ts +1 -2
  47. package/src/services/{auth.service.ts → auth/auth.service.ts} +36 -22
  48. package/src/services/{auth.v2.service.ts → auth/auth.v2.service.ts} +17 -17
  49. package/src/services/auth/index.ts +2 -16
  50. package/src/services/calendar/calendar-refactored.service.ts +1 -1
  51. package/src/services/calendar/index.ts +5 -0
  52. package/src/services/clinic/index.ts +4 -0
  53. package/src/services/index.ts +12 -0
  54. package/src/services/media/index.ts +1 -0
  55. package/src/services/notifications/index.ts +1 -0
  56. package/src/services/patient/README.md +48 -0
  57. package/src/services/patient/To-Do.md +43 -0
  58. package/src/services/patient/index.ts +2 -0
  59. package/src/services/patient/patient.service.ts +289 -34
  60. package/src/services/patient/utils/index.ts +9 -0
  61. package/src/services/patient/utils/medical.utils.ts +114 -157
  62. package/src/services/patient/utils/profile.utils.ts +9 -0
  63. package/src/services/patient/utils/sensitive.utils.ts +79 -14
  64. package/src/services/patient/utils/token.utils.ts +211 -0
  65. package/src/services/practitioner/index.ts +1 -0
  66. package/src/services/procedure/index.ts +1 -0
  67. package/src/services/reviews/index.ts +1 -0
  68. package/src/services/user/index.ts +1 -0
  69. package/src/services/{user.service.ts → user/user.service.ts} +61 -12
  70. package/src/services/{user.v2.service.ts → user/user.v2.service.ts} +12 -12
  71. package/src/types/index.ts +42 -42
  72. package/src/types/patient/index.ts +33 -6
  73. package/src/types/patient/token.types.ts +61 -0
  74. package/src/types/user/index.ts +38 -0
  75. package/src/utils/index.ts +1 -0
  76. package/src/validations/calendar.schema.ts +6 -45
  77. package/src/validations/documentation-templates/index.ts +1 -0
  78. package/src/validations/documentation-templates.schema.ts +1 -1
  79. package/src/validations/index.ts +20 -0
  80. package/src/validations/patient/token.schema.ts +29 -0
  81. package/src/validations/patient.schema.ts +23 -6
  82. package/src/validations/profile-info.schema.ts +1 -1
  83. 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,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,12 @@
1
+ export * from "./appointment";
2
+ export * from "./auth";
3
+ export * from "./calendar";
4
+ export * from "./clinic";
5
+ export * from "./documentation-templates";
6
+ export * from "./media";
7
+ export * from "./notifications";
8
+ export * from "./patient";
9
+ export * from "./practitioner";
10
+ export * from "./procedure";
11
+ export * from "./reviews";
12
+ export * from "./base.service";
@@ -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";