evo360-types 1.3.762 → 1.3.766

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.
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AutomationRunStatusEnum = exports.AutomationOutputTypeEnum = exports.AUTOMATION_TIME_RANGE_OPERATORS = exports.AutomationOperatorEnum = exports.AUTOMATION_PATIENT_FACTS = exports.AUTOMATION_LEAD_FACTS = exports.AUTOMATION_APPOINTMENT_FACTS = exports.HubAutomationPermissions = void 0;
17
+ exports.MESSAGE_PROMPT_MAX_CHARS = exports.GENERATED_MESSAGE_VARIABLE = exports.PATIENT_BIRTHDAY_MESSAGE_KIND = exports.AutomationRunStatusEnum = exports.AutomationOutputTypeEnum = exports.AUTOMATION_TIME_RANGE_OPERATORS = exports.AutomationOperatorEnum = exports.AUTOMATION_PATIENT_FACTS = exports.AUTOMATION_LEAD_FACTS = exports.AUTOMATION_APPOINTMENT_FACTS = exports.HubAutomationPermissions = void 0;
18
18
  __exportStar(require("./fb_collections"), exports);
19
19
  // ======================================================
20
20
  // hub-automation
@@ -28,8 +28,10 @@ __exportStar(require("./fb_collections"), exports);
28
28
  // NOTE:
29
29
  // - These are hand-written contracts (no z.infer). Zod schemas live in
30
30
  // src/apps/hub-automation/zod-schemas.ts.
31
- // - F1 has no `patient.*` facts and no patient hydration (decision Q15):
32
- // contact-data validation is the handler's responsibility at run time.
31
+ // - F1 has no `patient.*` facts and no patient hydration (decision Q15),
32
+ // except for the patient filters (feat-311: sex/age, read from the patient
33
+ // doc only when one of them is active): contact-data validation is the
34
+ // handler's responsibility at run time.
33
35
  // ======================================================
34
36
  // ----- Permissions (Firestore path: tenants/{t}/apps/hub-automation/...)
35
37
  exports.HubAutomationPermissions = {
@@ -123,3 +125,14 @@ exports.AutomationRunStatusEnum = {
123
125
  BlockedDryRunRequired: "blocked_dry_run_required",
124
126
  Error: "error",
125
127
  };
128
+ // ------------------------------------------------------
129
+ // feat-311 (F3): "Mensagem de aniversário (IA)" output
130
+ //
131
+ // Auto task `patient_birthday_message` (TaskAutoHandlerEnum.PatientBirthdayMessage):
132
+ // generates the text with the routine's prompt (LLM) and sends it through the
133
+ // chosen channel's template, filling the reserved variable `{{mensagem}}`.
134
+ // ------------------------------------------------------
135
+ exports.PATIENT_BIRTHDAY_MESSAGE_KIND = "birthday_message.send";
136
+ // Reserved template variable filled with the generated text (P3).
137
+ exports.GENERATED_MESSAGE_VARIABLE = "mensagem";
138
+ exports.MESSAGE_PROMPT_MAX_CHARS = 2000;
@@ -15,8 +15,10 @@ import type { DomainEventOrigin } from "../domain-events";
15
15
  // NOTE:
16
16
  // - These are hand-written contracts (no z.infer). Zod schemas live in
17
17
  // src/apps/hub-automation/zod-schemas.ts.
18
- // - F1 has no `patient.*` facts and no patient hydration (decision Q15):
19
- // contact-data validation is the handler's responsibility at run time.
18
+ // - F1 has no `patient.*` facts and no patient hydration (decision Q15),
19
+ // except for the patient filters (feat-311: sex/age, read from the patient
20
+ // doc only when one of them is active): contact-data validation is the
21
+ // handler's responsibility at run time.
20
22
  // ======================================================
21
23
 
22
24
  // ----- Permissions (Firestore path: tenants/{t}/apps/hub-automation/...)
@@ -86,6 +88,16 @@ export interface IAutomationDateWindow {
86
88
  offset_mode: AutomationDateOffsetMode;
87
89
  }
88
90
 
91
+ // feat-311: patient filters, shared by the `appointment` and `patient` blocks
92
+ // (same key names in both, so the backend has a single predicate).
93
+ export type AutomationPatientSex = "female" | "male" | "other";
94
+
95
+ // Inclusive age range in full years (0..130). At least one bound; min <= max.
96
+ export interface IAutomationAgeRange {
97
+ min?: number;
98
+ max?: number;
99
+ }
100
+
89
101
  export interface IAutomationAppointmentSelection {
90
102
  target: "appointment";
91
103
  appointment: {
@@ -147,15 +159,31 @@ export interface IAutomationAppointmentSelection {
147
159
  // `start === end` is invalid (rejected by zod). An appointment without a
148
160
  // coercible startDate does not match.
149
161
  time_range?: { start: string; end: string };
162
+
163
+ // ---- feat-311: patient filters. All optional and additive.
164
+ // - Data comes from the PATIENT doc (`gender`, `birthdate`), not from the
165
+ // appointment embeds.
166
+ // - The patient is read (one batched read per run) ONLY when one of these
167
+ // filters is active; otherwise there is no patient hydration.
168
+ // - Age = full years at the LOCAL appointment date (tenant timezone).
169
+ // - Absence is STRICT (deliberate divergence from the feat-147 rule): with
170
+ // any of these filters active, an appointment whose patient cannot be
171
+ // resolved/found, or lacks the field the filter uses, is EXCLUDED — this
172
+ // holds for `patient_sex_not_in` too.
173
+ patient_sex_in?: AutomationPatientSex[];
174
+ patient_sex_not_in?: AutomationPatientSex[];
175
+ patient_age?: IAutomationAgeRange;
150
176
  };
151
177
  }
152
178
 
153
- // feat-085 (F3): lead/patient selections. Cron selection is appointment-only;
154
- // these targets only arrive via the domain-event trigger, where the consumer
155
- // PRE-LOADS the single target from the event (the `lead`/`patient` filters below
156
- // are therefore not enforced at event runtime — they exist so a routine can be
157
- // authored/validated with a lead/patient target and, later, for a possible
158
- // lead/patient sweep). Discriminated by `target`.
179
+ // feat-085 (F3): lead/patient selections. Discriminated by `target`.
180
+ // - Lead targets only arrive via the domain-event trigger, where the consumer
181
+ // PRE-LOADS the single target from the event; the `lead` filters below are
182
+ // therefore not enforced at runtime (reserved, authoring/validation only).
183
+ // - Patient: without `patient.birthday` it is the domain-event selection above
184
+ // (status/source/tag filters reserved, not enforced). feat-311: WITH
185
+ // `patient.birthday` it is the cron/webhook birthday SWEEP, where the patient
186
+ // sex/age filters ARE enforced (status/source/tag stay reserved).
159
187
  export interface IAutomationLeadSelection {
160
188
  target: "lead";
161
189
  lead: {
@@ -173,6 +201,20 @@ export interface IAutomationPatientSelection {
173
201
  status_in?: string[];
174
202
  source_codes?: string[];
175
203
  tag_names?: string[];
204
+
205
+ // ---- feat-311: birthday sweep. Target date = runDate + offset_days in the
206
+ // tenant timezone (yyyy-MM-dd); selects the patients whose birthday falls on
207
+ // it (29/02 counts as 28/02 in non-leap years). `0` = today's birthdays;
208
+ // `1` = tomorrow's ("1 day before"). Range -30..30.
209
+ // PRESENT ⇒ sweep, valid only with a cron/webhook trigger (an event trigger
210
+ // with `birthday` is rejected on save). ABSENT ⇒ the domain-event patient
211
+ // selection, unchanged.
212
+ birthday?: { offset_days: number };
213
+ // Patient filters (same semantics/strict absence as in the appointment
214
+ // block). Age = the age the patient COMPLETES on the birthday (D3).
215
+ patient_sex_in?: AutomationPatientSex[];
216
+ patient_sex_not_in?: AutomationPatientSex[];
217
+ patient_age?: IAutomationAgeRange;
176
218
  };
177
219
  }
178
220
 
@@ -553,10 +595,18 @@ export interface IAutomationRunTrace {
553
595
  // `POST /routines/:id/dry-run` (capped, alongside `selected_targets_total`).
554
596
  // It is NEVER persisted in the run doc — IAutomationRunTrace keeps its counts +
555
597
  // capped samples so the 1MB Firestore limit stays intact.
598
+ //
599
+ // feat-311: also projects PATIENT targets (birthday sweep). `appointment_id` /
600
+ // `calendar_id` are therefore optional (present for appointment targets);
601
+ // `target_kind` absent = "appointment" (legacy responses).
556
602
  export interface IAutomationSelectedTargetProjection {
557
- appointment_id: string;
558
- calendar_id: string;
559
- // yyyy-MM-dd (target date the run resolved for this appointment)
603
+ target_kind?: "appointment" | "patient";
604
+ appointment_id?: string;
605
+ calendar_id?: string;
606
+ // Patient targets (and appointment targets when the patient was hydrated).
607
+ patient_id?: string;
608
+ // yyyy-MM-dd (target date the run resolved for this target; for a birthday
609
+ // target it is this year's birthday)
560
610
  target_date: string;
561
611
  // ISO 8601 instant; the client formats it in the tenant timezone.
562
612
  start_date?: string;
@@ -570,8 +620,63 @@ export interface IAutomationSelectedTargetProjection {
570
620
  // (`appointmentType`) and the BASE enum (`appointmentBaseType`).
571
621
  appointment_type?: string;
572
622
  appointment_base_type?: string;
623
+ // feat-311: filled only when the selection hydrated the patient (patient
624
+ // filter active, or a birthday target). Age at the target date.
625
+ patient_sex?: AutomationPatientSex;
626
+ patient_age?: number;
573
627
  // feat-270: ids of the branches this target matched in the same dry-run
574
628
  // (exclusive mode → 0..1; all-matching → 0..N; the fallback branch counts).
575
629
  // Empty array = "no branch". Absent = not computed.
576
630
  branch_ids?: string[];
577
631
  }
632
+
633
+ // ------------------------------------------------------
634
+ // feat-311 (F3): "Mensagem de aniversário (IA)" output
635
+ //
636
+ // Auto task `patient_birthday_message` (TaskAutoHandlerEnum.PatientBirthdayMessage):
637
+ // generates the text with the routine's prompt (LLM) and sends it through the
638
+ // chosen channel's template, filling the reserved variable `{{mensagem}}`.
639
+ // ------------------------------------------------------
640
+ export const PATIENT_BIRTHDAY_MESSAGE_KIND = "birthday_message.send";
641
+ // Reserved template variable filled with the generated text (P3).
642
+ export const GENERATED_MESSAGE_VARIABLE = "mensagem";
643
+ export const MESSAGE_PROMPT_MAX_CHARS = 2000;
644
+
645
+ export type GeneratedMessageChannel = "whatsapp" | "email";
646
+
647
+ export interface IPatientBirthdayMessagePayload {
648
+ // "{{patient.id}}"
649
+ patient_id: string;
650
+ channels?: GeneratedMessageChannel[];
651
+ whatsapp_channel_id?: string;
652
+ whatsapp_template_id?: string;
653
+ email_channel_id?: string;
654
+ email_template_id?: string;
655
+ department_id?: string;
656
+ // Required to send (P3) — the handler reports `prompt_missing` without it;
657
+ // <= MESSAGE_PROMPT_MAX_CHARS.
658
+ prompt?: string;
659
+ // yyyy-MM-dd; injected by the materializer (the birthday this task is for).
660
+ birthday_date?: string;
661
+ force_send?: boolean;
662
+ }
663
+
664
+ // "Testar prompt" — POST /outputs/preview-message (hub_automation_admin,
665
+ // RBAC hub_automation_write).
666
+ export interface IMessagePreviewRequest {
667
+ patient_id: string;
668
+ prompt: string;
669
+ channel: GeneratedMessageChannel;
670
+ // yyyy-MM-dd; absent = the patient's next birthday (tenant timezone).
671
+ birthday_date?: string;
672
+ }
673
+
674
+ export interface IMessagePreviewResponse {
675
+ ok: boolean;
676
+ error?: string;
677
+ text?: string;
678
+ chars?: number;
679
+ recipient?: { is_patient: boolean; first_name?: string; relation?: string };
680
+ model?: string;
681
+ usage?: { input_tokens: number; output_tokens: number; cost_usd: number | null };
682
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evo360-types",
3
- "version": "1.3.762",
3
+ "version": "1.3.766",
4
4
  "description": "HREVO360 Shared Types",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",