@ttn-shared/ui 0.0.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,2292 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ PatientAdministrativeRisks: () => PatientAdministrativeRisks,
34
+ PatientAppointmentHistory: () => PatientAppointmentHistory,
35
+ PatientAssistanceRisks: () => PatientAssistanceRisks,
36
+ PatientForm: () => PatientForm,
37
+ PatientNotes: () => PatientNotes,
38
+ TTNSharedProvider: () => TTNSharedProvider,
39
+ useTTNSharedContext: () => useTTNSharedContext
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+
43
+ // src/components/PatientForm.tsx
44
+ var import_react7 = require("react");
45
+ var import_dayjs = __toESM(require("dayjs"), 1);
46
+ var import_core7 = require("@mantine/core");
47
+ var import_form = require("@mantine/form");
48
+ var import_icons_react6 = require("@tabler/icons-react");
49
+
50
+ // src/hooks/select.ts
51
+ var import_react_query = require("@tanstack/react-query");
52
+
53
+ // src/config/axios.ts
54
+ var import_axios = __toESM(require("axios"), 1);
55
+ var getBaseURL = (url, token) => {
56
+ return {
57
+ baseURL: url,
58
+ headers: {
59
+ Accept: "application/json",
60
+ Authorization: token
61
+ }
62
+ };
63
+ };
64
+ var HTTP_MEDICAL = (token, baseURL) => {
65
+ const url = `${baseURL}/medical`;
66
+ return import_axios.default.create(getBaseURL(url, token));
67
+ };
68
+ var HTTP_PAYROLL = (token, baseURL) => {
69
+ const url = `${baseURL}/payroll`;
70
+ return import_axios.default.create(getBaseURL(url, token));
71
+ };
72
+ var HTTP_ADMIN = (token, baseURL) => {
73
+ const url = `${baseURL}/admin`;
74
+ return import_axios.default.create(getBaseURL(url, token));
75
+ };
76
+
77
+ // src/services/select.ts
78
+ var getDocumentTypes = async (token, baseURL) => {
79
+ const response = await HTTP_PAYROLL(token, baseURL).get(
80
+ "/document_types/"
81
+ );
82
+ return response.data;
83
+ };
84
+ var getAffiliationTypes = async (token, baseURL, filters) => {
85
+ const response = await HTTP_MEDICAL(token, baseURL).get(
86
+ "/generals/affiliation-types/",
87
+ { params: filters }
88
+ );
89
+ return response.data;
90
+ };
91
+ var getProvinces = async (token, baseURL, filters) => {
92
+ const response = await HTTP_ADMIN(token, baseURL).get("/provinces/", {
93
+ params: { entity_account: filters?.eaccount }
94
+ });
95
+ return response.data;
96
+ };
97
+ var getCities = async (token, baseURL, provinceId) => {
98
+ const response = await HTTP_ADMIN(token, baseURL).get("/cities/", {
99
+ params: { provinceId }
100
+ });
101
+ return response.data;
102
+ };
103
+ var getStratums = async (token, baseURL) => {
104
+ const response = await HTTP_MEDICAL(token, baseURL).get(
105
+ "/patient/stratums"
106
+ );
107
+ return response.data;
108
+ };
109
+ var getEthnicGroups = async (token, baseURL, filters) => {
110
+ const response = await HTTP_MEDICAL(token, baseURL).get(
111
+ "/generals/ethnic-groups/",
112
+ { params: filters }
113
+ );
114
+ return response.data;
115
+ };
116
+ var getEducationLevels = async (token, baseURL, filters) => {
117
+ const response = await HTTP_MEDICAL(token, baseURL).get(
118
+ "/generals/education-levels/",
119
+ { params: filters }
120
+ );
121
+ return response.data;
122
+ };
123
+ var getCompanyTypes = async (token, baseURL, filters) => {
124
+ const response = await HTTP_MEDICAL(token, baseURL).get(
125
+ "/client/companytype/",
126
+ { params: filters }
127
+ );
128
+ return response.data;
129
+ };
130
+ var getCompanyClients = async (token, baseURL, filters) => {
131
+ const response = await HTTP_MEDICAL(token, baseURL).get("/client/", {
132
+ params: filters
133
+ });
134
+ return response.data;
135
+ };
136
+ var getContracts = async (token, baseURL, filters) => {
137
+ const response = await HTTP_MEDICAL(token, baseURL).get(
138
+ "/client/contract/",
139
+ { params: filters }
140
+ );
141
+ return response.data;
142
+ };
143
+ var getContractPopulations = async (token, baseURL, filters) => {
144
+ const response = await HTTP_MEDICAL(token, baseURL).get(
145
+ "/client/contractpopulation/",
146
+ { params: filters }
147
+ );
148
+ return response.data;
149
+ };
150
+ var getIncomeGroups = async (token, baseURL, filters) => {
151
+ const response = await HTTP_MEDICAL(token, baseURL).get(
152
+ "/client/copaymentRate/",
153
+ { params: filters }
154
+ );
155
+ return response.data;
156
+ };
157
+
158
+ // src/providers/TTNSharedProvider.tsx
159
+ var import_react = require("react");
160
+ var import_jsx_runtime = require("react/jsx-runtime");
161
+ var TTNSharedContext = (0, import_react.createContext)(null);
162
+ var TTNSharedProvider = ({
163
+ children,
164
+ ...props
165
+ }) => {
166
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TTNSharedContext.Provider, { value: props, children });
167
+ };
168
+ var useTTNSharedContext = () => {
169
+ const context = (0, import_react.useContext)(TTNSharedContext);
170
+ if (!context) {
171
+ throw new Error("useTTNSharedContext must be used within a TTNSharedProvider");
172
+ }
173
+ return context;
174
+ };
175
+
176
+ // src/hooks/select.ts
177
+ var useDocumentTypes = ({ enabled = true }) => {
178
+ const { token, baseUrl } = useTTNSharedContext();
179
+ const query = (0, import_react_query.useQuery)({
180
+ queryKey: ["document-types"],
181
+ queryFn: () => getDocumentTypes(token, baseUrl),
182
+ enabled
183
+ });
184
+ return { data: query.data?.results };
185
+ };
186
+ var useAffiliationTypes = ({
187
+ enabled = true,
188
+ filters
189
+ }) => {
190
+ const { token, baseUrl } = useTTNSharedContext();
191
+ const query = (0, import_react_query.useQuery)({
192
+ queryKey: ["affiliation-types", filters?.eaccount],
193
+ queryFn: () => getAffiliationTypes(token, baseUrl, filters),
194
+ enabled
195
+ });
196
+ return { data: query.data?.results };
197
+ };
198
+ var useProvinces = ({
199
+ enabled = true,
200
+ filters
201
+ }) => {
202
+ const { token, baseUrl } = useTTNSharedContext();
203
+ const query = (0, import_react_query.useQuery)({
204
+ queryKey: ["provinces", filters?.eaccount],
205
+ queryFn: () => getProvinces(token, baseUrl, filters),
206
+ enabled
207
+ });
208
+ return { data: query.data?.data };
209
+ };
210
+ var useCities = ({
211
+ enabled = true,
212
+ provinceId
213
+ }) => {
214
+ const { token, baseUrl } = useTTNSharedContext();
215
+ const query = (0, import_react_query.useQuery)({
216
+ queryKey: ["cities", provinceId],
217
+ queryFn: () => getCities(token, baseUrl, provinceId),
218
+ enabled
219
+ });
220
+ return { data: query.data?.data };
221
+ };
222
+ var useStratums = ({ enabled = true }) => {
223
+ const { token, baseUrl } = useTTNSharedContext();
224
+ const query = (0, import_react_query.useQuery)({
225
+ queryKey: ["stratums"],
226
+ queryFn: () => getStratums(token, baseUrl),
227
+ enabled
228
+ });
229
+ return { data: query.data?.results };
230
+ };
231
+ var useEthnicGroups = ({
232
+ enabled = true,
233
+ filters
234
+ }) => {
235
+ const { token, baseUrl } = useTTNSharedContext();
236
+ const query = (0, import_react_query.useQuery)({
237
+ queryKey: ["ethnic-groups", filters?.eaccount],
238
+ queryFn: () => getEthnicGroups(token, baseUrl, filters),
239
+ enabled
240
+ });
241
+ return { data: query.data?.results };
242
+ };
243
+ var useEducationLevels = ({
244
+ enabled = true,
245
+ filters
246
+ }) => {
247
+ const { token, baseUrl } = useTTNSharedContext();
248
+ const query = (0, import_react_query.useQuery)({
249
+ queryKey: ["education-levels", filters?.eaccount],
250
+ queryFn: () => getEducationLevels(token, baseUrl, filters),
251
+ enabled
252
+ });
253
+ return { data: query.data?.results };
254
+ };
255
+ var useCompanyTypes = ({
256
+ enabled = true,
257
+ filters
258
+ }) => {
259
+ const { token, baseUrl } = useTTNSharedContext();
260
+ const query = (0, import_react_query.useQuery)({
261
+ queryKey: ["company-types", filters?.status, filters?.eaccount],
262
+ queryFn: () => getCompanyTypes(token, baseUrl, filters),
263
+ enabled
264
+ });
265
+ return { data: query.data?.results };
266
+ };
267
+ var useCompanyClients = ({
268
+ enabled = true,
269
+ filters
270
+ }) => {
271
+ const { token, baseUrl } = useTTNSharedContext();
272
+ const query = (0, import_react_query.useQuery)({
273
+ queryKey: ["company-clients", filters?.contractCompanyType, filters?.status, filters?.eaccount],
274
+ queryFn: () => getCompanyClients(token, baseUrl, filters),
275
+ enabled
276
+ });
277
+ return { data: query.data?.results };
278
+ };
279
+ var useContracts = ({
280
+ enabled = true,
281
+ filters
282
+ }) => {
283
+ const { token, baseUrl } = useTTNSharedContext();
284
+ const query = (0, import_react_query.useQuery)({
285
+ queryKey: ["contracts", filters?.cType, filters?.client, filters?.status, filters?.eaccount],
286
+ queryFn: () => getContracts(token, baseUrl, filters),
287
+ enabled
288
+ });
289
+ return { data: query.data?.results };
290
+ };
291
+ var useContractPopulations = ({
292
+ enabled = true,
293
+ filters
294
+ }) => {
295
+ const { token, baseUrl } = useTTNSharedContext();
296
+ const query = (0, import_react_query.useQuery)({
297
+ queryKey: ["contract-populations", filters?.contract, filters?.eaccount, filters?.status],
298
+ queryFn: () => getContractPopulations(token, baseUrl, filters),
299
+ enabled
300
+ });
301
+ return { data: query.data?.results };
302
+ };
303
+ var useIncomeGroups = ({
304
+ enabled = true,
305
+ filters
306
+ }) => {
307
+ const { token, baseUrl } = useTTNSharedContext();
308
+ const query = (0, import_react_query.useQuery)({
309
+ queryKey: ["income-groups", filters?.corpclientId, filters?.eaccount],
310
+ queryFn: () => getIncomeGroups(token, baseUrl, filters),
311
+ enabled
312
+ });
313
+ return { data: query.data?.results };
314
+ };
315
+
316
+ // src/constants/select.ts
317
+ var genderOptions = [
318
+ { value: "male", label: "Masculino" },
319
+ { value: "female", label: "Femenino" }
320
+ ];
321
+ var maritalStatusOptions = [
322
+ { value: "single", label: "Soltero(a)" },
323
+ { value: "married", label: "Casado(a)" },
324
+ { value: "divorced", label: "Divorciado(a)" },
325
+ { value: "widowed", label: "Viudo(a)" },
326
+ { value: "freeunion", label: "Uni\xF3n Libre" }
327
+ ];
328
+ var bloodTypeOptions = [
329
+ { value: "A+", label: "A+" },
330
+ { value: "A-", label: "A-" },
331
+ { value: "B+", label: "B+" },
332
+ { value: "B-", label: "B-" },
333
+ { value: "AB+", label: "AB+" },
334
+ { value: "AB-", label: "AB-" },
335
+ { value: "O+", label: "O+" },
336
+ { value: "O-", label: "O-" }
337
+ ];
338
+
339
+ // src/constants/patient.ts
340
+ var patientFormTitles = {
341
+ create: "Crear paciente",
342
+ edit: "Editar paciente",
343
+ view: "Detalle del paciente"
344
+ };
345
+ var VOLUNTARY_INSURANCE_TAGS = ["arl", "particular"];
346
+
347
+ // src/components/PatientVoluntaryInsuranceForm.tsx
348
+ var import_react2 = require("react");
349
+ var import_core = require("@mantine/core");
350
+ var import_icons_react = require("@tabler/icons-react");
351
+ var import_jsx_runtime2 = require("react/jsx-runtime");
352
+ var PatientVoluntaryInsuranceForm = ({
353
+ index,
354
+ mode,
355
+ form
356
+ }) => {
357
+ const { userAccountId } = useTTNSharedContext();
358
+ const insuranceInfo = form.values.voluntaryInsurance[index];
359
+ const { data: companyTypes } = useCompanyTypes({
360
+ filters: {
361
+ eaccount: userAccountId,
362
+ status: "enabled"
363
+ }
364
+ });
365
+ const { data: companyClients } = useCompanyClients({
366
+ filters: {
367
+ eaccount: userAccountId,
368
+ status: "enabled"
369
+ }
370
+ });
371
+ const { data: contracts } = useContracts({
372
+ enabled: Boolean(insuranceInfo.companyId),
373
+ filters: {
374
+ eaccount: userAccountId,
375
+ cType: "particular",
376
+ client: Number(insuranceInfo.companyId) || void 0,
377
+ status: "enabled"
378
+ }
379
+ });
380
+ const { data: contractPopulations } = useContractPopulations({
381
+ enabled: Boolean(insuranceInfo.plan),
382
+ filters: {
383
+ eaccount: userAccountId,
384
+ contract: Number(insuranceInfo.plan) || void 0,
385
+ status: "enabled"
386
+ }
387
+ });
388
+ const { data: incomeGroups } = useIncomeGroups({
389
+ enabled: Boolean(insuranceInfo.companyId),
390
+ filters: {
391
+ eaccount: userAccountId,
392
+ corpclientId: Number(insuranceInfo.companyId) || void 0
393
+ }
394
+ });
395
+ const companyTypeOptions = (0, import_react2.useMemo)(() => {
396
+ return companyTypes?.map((ct) => ({
397
+ value: String(ct.id),
398
+ label: ct.name
399
+ }));
400
+ }, [companyTypes]);
401
+ const companyClientOptions = (0, import_react2.useMemo)(() => {
402
+ return companyClients?.map((cc) => ({
403
+ value: String(cc.id),
404
+ label: cc.name
405
+ }));
406
+ }, [companyClients]);
407
+ const contractOptions = (0, import_react2.useMemo)(() => {
408
+ return contracts?.map((c) => ({
409
+ value: String(c.id),
410
+ label: c.name
411
+ }));
412
+ }, [contracts]);
413
+ const contractPopulationOptions = (0, import_react2.useMemo)(() => {
414
+ return contractPopulations?.map((cp) => ({
415
+ value: String(cp.idPopulation),
416
+ label: cp.name
417
+ }));
418
+ }, [contractPopulations]);
419
+ const incomeGroupOptions = (0, import_react2.useMemo)(() => {
420
+ return incomeGroups?.map((ig) => ({
421
+ value: String(ig.crtId),
422
+ label: ig.copaymentRateName
423
+ }));
424
+ }, [incomeGroups]);
425
+ const selectedCompanyType = companyTypes?.find((ct) => String(ct.id) === insuranceInfo.companyType);
426
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core.Paper, { withBorder: true, p: "md", mb: "sm", bg: "#d6e0eb", shadow: "none", children: [
427
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core.Flex, { justify: "space-between", align: "center", mb: "sm", children: [
428
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core.Title, { order: 6, c: "secondary-color", children: "Aseguradora voluntaria" }),
429
+ mode !== "view" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
430
+ import_core.ActionIcon,
431
+ {
432
+ variant: "subtle",
433
+ color: "secondary-color",
434
+ onClick: () => form.removeListItem("voluntaryInsurance", index),
435
+ "data-testid": `patient-form-voluntary-insurance-remove-button-${index}`,
436
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_react.IconX, { size: 16 })
437
+ }
438
+ )
439
+ ] }),
440
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core.Grid, { children: [
441
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
442
+ import_core.Select,
443
+ {
444
+ readOnly: mode === "view",
445
+ withAsterisk: mode !== "view",
446
+ label: "Tipo de seguro",
447
+ data: companyTypeOptions,
448
+ ...form.getInputProps(`voluntaryInsurance.${index}.companyType`),
449
+ onChange: (value) => {
450
+ if (value) {
451
+ const companyTypeTag = companyTypes?.find((ct) => String(ct.id) === value)?.tag;
452
+ form.setFieldValue(
453
+ `voluntaryInsurance.${index}.companyTypeTag`,
454
+ companyTypeTag || ""
455
+ );
456
+ }
457
+ form.setFieldValue(`voluntaryInsurance.${index}.companyType`, value || "");
458
+ form.setFieldValue(`voluntaryInsurance.${index}.companyId`, "");
459
+ form.setFieldValue(`voluntaryInsurance.${index}.plan`, "");
460
+ form.setFieldValue(`voluntaryInsurance.${index}.population`, "");
461
+ form.setFieldValue(`voluntaryInsurance.${index}.groupId`, "");
462
+ form.setFieldValue(`voluntaryInsurance.${index}.policyNumber`, "");
463
+ },
464
+ "data-testid": `patient-form-voluntary-insurance-company-type-select-${index}`
465
+ }
466
+ ) }),
467
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
468
+ import_core.Select,
469
+ {
470
+ readOnly: mode === "view",
471
+ withAsterisk: mode !== "view",
472
+ label: "Seguro",
473
+ data: companyClientOptions,
474
+ ...form.getInputProps(`voluntaryInsurance.${index}.companyId`),
475
+ onChange: (value) => {
476
+ form.setFieldValue(`voluntaryInsurance.${index}.companyId`, value || "");
477
+ form.setFieldValue(`voluntaryInsurance.${index}.plan`, "");
478
+ form.setFieldValue(`voluntaryInsurance.${index}.population`, "");
479
+ form.setFieldValue(`voluntaryInsurance.${index}.groupId`, "");
480
+ form.setFieldValue(`voluntaryInsurance.${index}.policyNumber`, "");
481
+ },
482
+ "data-testid": `patient-form-voluntary-insurance-company-select-${index}`
483
+ }
484
+ ) }),
485
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
486
+ import_core.Select,
487
+ {
488
+ readOnly: mode === "view",
489
+ withAsterisk: mode !== "view",
490
+ label: "Plan",
491
+ data: contractOptions,
492
+ ...form.getInputProps(`voluntaryInsurance.${index}.plan`),
493
+ onChange: (value) => {
494
+ form.setFieldValue(`voluntaryInsurance.${index}.plan`, value || "");
495
+ form.setFieldValue(`voluntaryInsurance.${index}.population`, "");
496
+ form.setFieldValue(`voluntaryInsurance.${index}.groupId`, "");
497
+ form.setFieldValue(`voluntaryInsurance.${index}.policyNumber`, "");
498
+ },
499
+ "data-testid": `patient-form-voluntary-insurance-plan-select-${index}`
500
+ }
501
+ ) }),
502
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
503
+ import_core.Select,
504
+ {
505
+ readOnly: mode === "view",
506
+ withAsterisk: mode !== "view",
507
+ label: "Poblaci\xF3n",
508
+ data: contractPopulationOptions,
509
+ ...form.getInputProps(`voluntaryInsurance.${index}.population`),
510
+ "data-testid": `patient-form-voluntary-insurance-population-select-${index}`
511
+ }
512
+ ) }),
513
+ VOLUNTARY_INSURANCE_TAGS.includes(selectedCompanyType?.tag ?? "") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
514
+ import_core.Select,
515
+ {
516
+ readOnly: mode === "view",
517
+ withAsterisk: mode !== "view",
518
+ label: "Grupo de ingreso",
519
+ data: incomeGroupOptions,
520
+ ...form.getInputProps(`voluntaryInsurance.${index}.groupId`),
521
+ "data-testid": `patient-form-voluntary-insurance-group-select-${index}`
522
+ }
523
+ ) }),
524
+ [...VOLUNTARY_INSURANCE_TAGS, "prepaid"].includes(selectedCompanyType?.tag ?? "") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
525
+ import_core.TextInput,
526
+ {
527
+ readOnly: mode === "view",
528
+ label: "No. de p\xF3liza",
529
+ ...form.getInputProps(`voluntaryInsurance.${index}.policyNumber`),
530
+ "data-testid": `patient-form-voluntary-insurance-policy-number-select-${index}`
531
+ }
532
+ ) })
533
+ ] })
534
+ ] });
535
+ };
536
+
537
+ // src/hooks/patient.ts
538
+ var import_react_query2 = require("@tanstack/react-query");
539
+
540
+ // src/services/patient.ts
541
+ var getPatientDetail = async (token, baseURL, filters) => {
542
+ const response = await HTTP_MEDICAL(token, baseURL).get("/patient/", {
543
+ params: filters
544
+ });
545
+ return response.data;
546
+ };
547
+
548
+ // src/hooks/patient.ts
549
+ var usePatientDetail = ({
550
+ enabled = true,
551
+ filters
552
+ }) => {
553
+ const { token, baseUrl } = useTTNSharedContext();
554
+ const query = (0, import_react_query2.useQuery)({
555
+ queryKey: ["patient-detail", filters?.eaccount, filters?.id],
556
+ queryFn: () => getPatientDetail(token, baseUrl, filters),
557
+ enabled
558
+ });
559
+ return { data: query.data?.results, refetch: query.refetch };
560
+ };
561
+
562
+ // src/components/PatientNotes.tsx
563
+ var import_react3 = require("react");
564
+ var import_core2 = require("@mantine/core");
565
+ var import_icons_react2 = require("@tabler/icons-react");
566
+
567
+ // src/hooks/comment.ts
568
+ var import_react_query3 = require("@tanstack/react-query");
569
+
570
+ // src/services/comment.ts
571
+ var getComments = async (token, baseURL, filters) => {
572
+ const response = await HTTP_MEDICAL(token, baseURL).get("/comments/", {
573
+ params: filters
574
+ });
575
+ return response.data;
576
+ };
577
+ var createComment = async (token, baseURL, payload) => {
578
+ const response = await HTTP_MEDICAL(token, baseURL).post(
579
+ "/comments/",
580
+ payload
581
+ );
582
+ return response.data;
583
+ };
584
+ var deleteComment = async (token, baseURL, id) => {
585
+ const response = await HTTP_MEDICAL(token, baseURL).delete(`/comments/`, {
586
+ data: { id }
587
+ });
588
+ return response.data;
589
+ };
590
+
591
+ // src/hooks/comment.ts
592
+ var useComments = ({
593
+ enabled = true,
594
+ filters
595
+ }) => {
596
+ const { token, baseUrl } = useTTNSharedContext();
597
+ const query = (0, import_react_query3.useQuery)({
598
+ queryKey: ["comments", filters?.entity, filters?.id],
599
+ queryFn: () => getComments(token, baseUrl, filters),
600
+ enabled
601
+ });
602
+ return { data: query.data?.results };
603
+ };
604
+ var useCreateComment = () => {
605
+ const { token, baseUrl } = useTTNSharedContext();
606
+ const mutation = (0, import_react_query3.useMutation)({
607
+ mutationFn: (payload) => createComment(token, baseUrl, payload)
608
+ });
609
+ return mutation;
610
+ };
611
+ var useDeleteComment = () => {
612
+ const { token, baseUrl } = useTTNSharedContext();
613
+ const mutation = (0, import_react_query3.useMutation)({
614
+ mutationFn: (id) => deleteComment(token, baseUrl, id)
615
+ });
616
+ return mutation;
617
+ };
618
+
619
+ // src/components/PatientNotes.tsx
620
+ var import_jsx_runtime3 = require("react/jsx-runtime");
621
+ var PatientNotes = ({
622
+ patientId,
623
+ isOpen,
624
+ onClose,
625
+ closeOnSave = true,
626
+ onAttemptRemoveNote
627
+ }) => {
628
+ const { userId, userName } = useTTNSharedContext();
629
+ const [comment, setComment] = (0, import_react3.useState)("");
630
+ const { data: notes } = useComments({
631
+ enabled: isOpen && Boolean(patientId),
632
+ filters: { entity: "userClient", id: patientId }
633
+ });
634
+ const { mutateAsync: createComment2 } = useCreateComment();
635
+ const { mutateAsync: deleteComment2 } = useDeleteComment();
636
+ const handleAddNote = async () => {
637
+ await createComment2({
638
+ entity: "userClient",
639
+ userId: userId ?? 0,
640
+ comment,
641
+ id: patientId ?? 0
642
+ });
643
+ setComment("");
644
+ if (closeOnSave) {
645
+ onClose();
646
+ }
647
+ };
648
+ const handleRemoveNote = async (comment2) => {
649
+ const canDelete = await onAttemptRemoveNote?.(comment2) ?? true;
650
+ if (!canDelete) {
651
+ return;
652
+ }
653
+ await deleteComment2(comment2.id);
654
+ setComment("");
655
+ if (closeOnSave) {
656
+ onClose();
657
+ }
658
+ };
659
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_core2.Drawer.Root, { opened: isOpen, onClose, position: "right", size: "xs", children: [
660
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Drawer.Overlay, {}),
661
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Drawer.Content, { style: { overflow: "hidden" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_core2.Flex, { direction: "column", style: { height: "100%" }, children: [
662
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_core2.Box, { p: "lg", style: { flexShrink: 0 }, children: [
663
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.ActionIcon, { variant: "subtle", "data-testid": "patient-notes-close-button", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_react2.IconX, { style: { width: 30, height: 30 } }) }),
664
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Title, { order: 2, fz: "h2", c: "secondary-color", children: "Notas" })
665
+ ] }),
666
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_core2.ScrollArea, { px: "lg", style: { flexGrow: 1 }, children: [
667
+ notes?.map((note, index) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_core2.Box, { p: "sm", children: [
668
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_core2.Flex, { justify: "space-between", children: [
669
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Text, { c: "secondary-color", children: note.userName }),
670
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
671
+ import_core2.ActionIcon,
672
+ {
673
+ size: "sm",
674
+ variant: "subtle",
675
+ onClick: () => handleRemoveNote(note),
676
+ "data-testid": `patient-note-delete-button-${index}`,
677
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_react2.IconTrash, {})
678
+ }
679
+ )
680
+ ] }),
681
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Text, { c: "dimmed", children: note.comment }),
682
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Text, { c: "dimmed", ta: "end", children: note.date }),
683
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Divider, {})
684
+ ] }, note.id)),
685
+ !notes?.length && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Text, { c: "dimmed", ta: "center", children: "No hay notas disponibles." })
686
+ ] }),
687
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Box, { p: "lg", style: { flexShrink: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_core2.Paper, { withBorder: true, p: "md", bg: "brand-color.0", shadow: "none", children: [
688
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Text, { c: "brand-color", children: userName }),
689
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
690
+ import_core2.Textarea,
691
+ {
692
+ value: comment,
693
+ onChange: (event) => setComment(event.currentTarget.value),
694
+ rows: 4,
695
+ "data-testid": "patient-note-comment-textarea"
696
+ }
697
+ ),
698
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Flex, { justify: "flex-end", mt: "xs", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
699
+ import_core2.ActionIcon,
700
+ {
701
+ disabled: comment.trim().length < 3,
702
+ variant: "subtle",
703
+ c: "brand-color",
704
+ onClick: handleAddNote,
705
+ "data-testid": "patient-note-send-button",
706
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_react2.IconSend2, { style: { width: 16, height: 16 } })
707
+ }
708
+ ) })
709
+ ] }) })
710
+ ] }) })
711
+ ] });
712
+ };
713
+
714
+ // src/components/PatientAdministrativeRisks.tsx
715
+ var import_react4 = require("react");
716
+ var import_core3 = require("@mantine/core");
717
+
718
+ // src/hooks/risk.ts
719
+ var import_react_query4 = require("@tanstack/react-query");
720
+
721
+ // src/services/risk.ts
722
+ var getAssistanceRisks = async (token, baseURL, filters) => {
723
+ const response = await HTTP_MEDICAL(token, baseURL).get(
724
+ "/patient/assistance-risks",
725
+ { params: filters }
726
+ );
727
+ return response.data;
728
+ };
729
+ var getAdministrativeRisks = async (token, baseURL, filters) => {
730
+ const response = await HTTP_MEDICAL(token, baseURL).get(
731
+ "/markups/",
732
+ { params: filters }
733
+ );
734
+ return response.data;
735
+ };
736
+ var updateRisks = async (token, baseURL, payload) => {
737
+ const response = await HTTP_MEDICAL(token, baseURL).put("/patient/risk", payload);
738
+ return response.data;
739
+ };
740
+
741
+ // src/hooks/risk.ts
742
+ var useAssistanceRisks = ({
743
+ enabled = true,
744
+ filters
745
+ }) => {
746
+ const { token, baseUrl } = useTTNSharedContext();
747
+ const query = (0, import_react_query4.useQuery)({
748
+ queryKey: ["assistance-risks", filters?.status],
749
+ queryFn: () => getAssistanceRisks(token, baseUrl, filters),
750
+ enabled
751
+ });
752
+ return { data: query.data?.results };
753
+ };
754
+ var useAdministrativeRisks = ({
755
+ enabled = true,
756
+ filters
757
+ }) => {
758
+ const { token, baseUrl } = useTTNSharedContext();
759
+ const query = (0, import_react_query4.useQuery)({
760
+ queryKey: ["administrative-risks", filters?.status],
761
+ queryFn: () => getAdministrativeRisks(token, baseUrl, filters),
762
+ enabled
763
+ });
764
+ return { data: query.data?.results };
765
+ };
766
+ var useUpdateRisks = () => {
767
+ const { token, baseUrl } = useTTNSharedContext();
768
+ const mutation = (0, import_react_query4.useMutation)({
769
+ mutationFn: (payload) => updateRisks(token, baseUrl, payload)
770
+ });
771
+ return mutation;
772
+ };
773
+
774
+ // src/components/PatientAdministrativeRisks.tsx
775
+ var import_icons_react3 = require("@tabler/icons-react");
776
+ var import_jsx_runtime4 = require("react/jsx-runtime");
777
+ var PatientAdministrativeRisks = ({
778
+ patientId,
779
+ isOpen,
780
+ onClose
781
+ }) => {
782
+ const { userAccountId } = useTTNSharedContext();
783
+ const [riskValue, setRiskValue] = (0, import_react4.useState)(null);
784
+ const [selectedRisks, setSelectedRisks] = (0, import_react4.useState)([]);
785
+ const { data: patientInfo } = usePatientDetail({
786
+ enabled: Boolean(patientId) && isOpen,
787
+ filters: {
788
+ eaccount: userAccountId,
789
+ id: patientId
790
+ }
791
+ });
792
+ const { data: administrativeRisks } = useAdministrativeRisks({
793
+ enabled: Boolean(patientId) && isOpen,
794
+ filters: {
795
+ status: "enabled"
796
+ }
797
+ });
798
+ const { mutateAsync: updateRisks2 } = useUpdateRisks();
799
+ const handleSaveRisks = async () => {
800
+ await updateRisks2({
801
+ eaccount: userAccountId ?? 0,
802
+ idPatient: patientId ?? 0,
803
+ riskList: {
804
+ administrative: selectedRisks
805
+ }
806
+ });
807
+ onClose();
808
+ };
809
+ const handleChangeRisk = (riskId) => {
810
+ if (!riskId) {
811
+ return;
812
+ }
813
+ const selectedRisk = administrativeRisks?.find((risk) => String(risk.id) === riskId);
814
+ if (selectedRisk) {
815
+ const newRisks = [...selectedRisks, selectedRisk];
816
+ setSelectedRisks(newRisks);
817
+ setRiskValue(null);
818
+ }
819
+ };
820
+ const handleRemoveRisk = (riskId) => {
821
+ const newRisks = selectedRisks.filter((risk) => risk.id !== riskId);
822
+ setSelectedRisks(newRisks);
823
+ };
824
+ (0, import_react4.useEffect)(() => {
825
+ if (!patientInfo || !isOpen) {
826
+ return;
827
+ }
828
+ setSelectedRisks(patientInfo.risk.administrative ?? []);
829
+ }, [patientInfo, isOpen]);
830
+ const administrativeRiskOptions = (0, import_react4.useMemo)(() => {
831
+ const options = [];
832
+ for (const risk of administrativeRisks ?? []) {
833
+ if (selectedRisks.some((selected) => selected.id === risk.id)) {
834
+ continue;
835
+ }
836
+ options.push({ value: String(risk.id), label: risk.description });
837
+ }
838
+ return options;
839
+ }, [administrativeRisks, selectedRisks]);
840
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
841
+ import_core3.Modal,
842
+ {
843
+ opened: isOpen,
844
+ onClose,
845
+ title: "Importancias administrativas",
846
+ withCloseButton: false,
847
+ children: [
848
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core3.FocusTrap.InitialFocus, {}),
849
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
850
+ import_core3.Select,
851
+ {
852
+ data: administrativeRiskOptions,
853
+ value: riskValue,
854
+ onChange: handleChangeRisk,
855
+ "data-testid": "patient-administrative-risks-select"
856
+ }
857
+ ),
858
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core3.ScrollArea.Autosize, { mah: 228, mt: "lg", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_core3.Paper, { withBorder: true, mx: "xs", children: [
859
+ selectedRisks.map((risk, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_core3.Flex, { align: "center", justify: "space-between", p: "xs", children: [
860
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_core3.Group, { gap: "sm", align: "center", children: [
861
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
862
+ import_core3.ThemeIcon,
863
+ {
864
+ color: risk.classification === "high" ? "#f39682" : "#83c036",
865
+ variant: "light",
866
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
867
+ import_icons_react3.IconExclamationCircleFilled,
868
+ {
869
+ color: risk.classification === "high" ? "#f39682" : "#83c036",
870
+ style: { width: 20, height: 20 }
871
+ }
872
+ )
873
+ }
874
+ ),
875
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core3.Text, { lineClamp: 2, title: risk.description, children: risk.description })
876
+ ] }),
877
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
878
+ import_core3.ActionIcon,
879
+ {
880
+ variant: "subtle",
881
+ onClick: () => handleRemoveRisk(risk.id),
882
+ "data-testid": `patient-administrative-risks-remove-button-${index}`,
883
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_icons_react3.IconX, { style: { width: 20, height: 20 } })
884
+ }
885
+ )
886
+ ] }, risk.id)),
887
+ selectedRisks.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core3.Text, { c: "dimmed", p: "xs", children: "No hay riesgos administrativos seleccionados." })
888
+ ] }) }),
889
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_core3.Group, { justify: "flex-end", gap: "md", mt: "xl", children: [
890
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
891
+ import_core3.Button,
892
+ {
893
+ variant: "outline",
894
+ onClick: onClose,
895
+ "data-testid": "patient-administrative-risks-cancel-button",
896
+ children: "Cancelar"
897
+ }
898
+ ),
899
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
900
+ import_core3.Button,
901
+ {
902
+ type: "submit",
903
+ onClick: handleSaveRisks,
904
+ "data-testid": "patient-administrative-risks-save-button",
905
+ children: "Guardar"
906
+ }
907
+ )
908
+ ] })
909
+ ]
910
+ }
911
+ );
912
+ };
913
+
914
+ // src/components/PatientAssistanceRisks.tsx
915
+ var import_react5 = require("react");
916
+ var import_core4 = require("@mantine/core");
917
+ var import_icons_react4 = require("@tabler/icons-react");
918
+ var import_jsx_runtime5 = require("react/jsx-runtime");
919
+ var PatientAssistanceRisks = ({
920
+ patientId,
921
+ isOpen,
922
+ onClose
923
+ }) => {
924
+ const { userAccountId } = useTTNSharedContext();
925
+ const [riskValue, setRiskValue] = (0, import_react5.useState)(null);
926
+ const [selectedRisks, setSelectedRisks] = (0, import_react5.useState)([]);
927
+ const { data: patientInfo } = usePatientDetail({
928
+ enabled: Boolean(patientId) && isOpen,
929
+ filters: {
930
+ eaccount: userAccountId,
931
+ id: patientId
932
+ }
933
+ });
934
+ const { data: assistanceRisks } = useAssistanceRisks({
935
+ enabled: Boolean(patientId) && isOpen,
936
+ filters: {
937
+ status: "enabled"
938
+ }
939
+ });
940
+ const { mutateAsync: updateRisks2 } = useUpdateRisks();
941
+ const handleChangeRisk = (riskId) => {
942
+ if (!riskId) {
943
+ return;
944
+ }
945
+ const selectedRisk = assistanceRisks?.find((risk) => String(risk.clinicalDiseaseId) === riskId);
946
+ if (selectedRisk) {
947
+ const newRisks = [...selectedRisks, selectedRisk];
948
+ setSelectedRisks(newRisks);
949
+ setRiskValue(null);
950
+ }
951
+ };
952
+ const handleSaveRisks = async () => {
953
+ await updateRisks2({
954
+ eaccount: userAccountId ?? 0,
955
+ idPatient: patientId ?? 0,
956
+ riskList: {
957
+ assistance: selectedRisks
958
+ }
959
+ });
960
+ onClose();
961
+ };
962
+ const handleRemoveRisk = (riskId) => {
963
+ const newRisks = selectedRisks.filter((risk) => risk.clinicalDiseaseId !== riskId);
964
+ setSelectedRisks(newRisks);
965
+ };
966
+ (0, import_react5.useEffect)(() => {
967
+ if (!patientInfo || !isOpen) {
968
+ return;
969
+ }
970
+ const formattedRisks = (patientInfo.risk.assistance ?? []).map((risk) => ({
971
+ clinicalDiseaseId: risk.id,
972
+ clinicalDiseaseName: risk.name,
973
+ clinicalDiseaseTag: ""
974
+ }));
975
+ setSelectedRisks(formattedRisks);
976
+ }, [patientInfo, isOpen]);
977
+ const assistanceRiskOptions = (0, import_react5.useMemo)(() => {
978
+ const options = [];
979
+ for (const risk of assistanceRisks ?? []) {
980
+ if (selectedRisks.some((selected) => selected.clinicalDiseaseId === risk.clinicalDiseaseId)) {
981
+ continue;
982
+ }
983
+ options.push({ value: String(risk.clinicalDiseaseId), label: risk.clinicalDiseaseName });
984
+ }
985
+ return options;
986
+ }, [assistanceRisks, selectedRisks]);
987
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
988
+ import_core4.Modal,
989
+ {
990
+ opened: isOpen,
991
+ onClose,
992
+ title: "Importancias asistenciales",
993
+ withCloseButton: false,
994
+ children: [
995
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core4.FocusTrap.InitialFocus, {}),
996
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
997
+ import_core4.Select,
998
+ {
999
+ data: assistanceRiskOptions,
1000
+ value: riskValue,
1001
+ onChange: handleChangeRisk,
1002
+ "data-testid": "patient-assistance-risks-select"
1003
+ }
1004
+ ),
1005
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core4.ScrollArea.Autosize, { mah: 228, mt: "lg", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_core4.Paper, { withBorder: true, mx: "xs", children: [
1006
+ selectedRisks.map((risk, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_core4.Flex, { align: "center", justify: "space-between", p: "xs", children: [
1007
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core4.Text, { lineClamp: 2, title: risk.clinicalDiseaseName, children: risk.clinicalDiseaseName }),
1008
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1009
+ import_core4.ActionIcon,
1010
+ {
1011
+ variant: "subtle",
1012
+ onClick: () => handleRemoveRisk(risk.clinicalDiseaseId),
1013
+ "data-testid": `patient-assistance-risks-remove-button-${index}`,
1014
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_icons_react4.IconX, { style: { width: 20, height: 20 } })
1015
+ }
1016
+ )
1017
+ ] }, risk.clinicalDiseaseId)),
1018
+ selectedRisks.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core4.Text, { c: "dimmed", p: "xs", children: "No hay importancias seleccionadas." })
1019
+ ] }) }),
1020
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_core4.Group, { justify: "flex-end", gap: "md", mt: "xl", children: [
1021
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1022
+ import_core4.Button,
1023
+ {
1024
+ variant: "outline",
1025
+ onClick: onClose,
1026
+ "data-testid": "patient-assistance-risks-cancel-button",
1027
+ children: "Cancelar"
1028
+ }
1029
+ ),
1030
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1031
+ import_core4.Button,
1032
+ {
1033
+ type: "submit",
1034
+ onClick: handleSaveRisks,
1035
+ "data-testid": "patient-assistance-risks-save-button",
1036
+ children: "Guardar"
1037
+ }
1038
+ )
1039
+ ] })
1040
+ ]
1041
+ }
1042
+ );
1043
+ };
1044
+
1045
+ // src/hooks/appointment.ts
1046
+ var import_react_query5 = require("@tanstack/react-query");
1047
+
1048
+ // src/services/appointment.ts
1049
+ var getAppointments = async (token, baseURL, filters) => {
1050
+ const response = await HTTP_MEDICAL(token, baseURL).get(
1051
+ "/appointment/",
1052
+ { params: filters }
1053
+ );
1054
+ return response.data;
1055
+ };
1056
+
1057
+ // src/hooks/appointment.ts
1058
+ var useAppointments = ({
1059
+ enabled = true,
1060
+ filters
1061
+ }) => {
1062
+ const { token, baseUrl } = useTTNSharedContext();
1063
+ const query = (0, import_react_query5.useQuery)({
1064
+ queryKey: [
1065
+ "appointments",
1066
+ filters?.idAccount,
1067
+ filters?.page,
1068
+ filters?.perpage,
1069
+ filters?.idPatient
1070
+ ],
1071
+ queryFn: () => getAppointments(token, baseUrl, filters),
1072
+ enabled
1073
+ });
1074
+ return { data: query.data?.results, rowTotal: query.data?.rowTotal };
1075
+ };
1076
+
1077
+ // src/components/PatientAppointmentHistory.tsx
1078
+ var import_core6 = require("@mantine/core");
1079
+ var import_icons_react5 = require("@tabler/icons-react");
1080
+ var import_react6 = require("react");
1081
+
1082
+ // src/components/AppPagination.tsx
1083
+ var import_core5 = require("@mantine/core");
1084
+ var TI = __toESM(require("@tabler/icons-react"), 1);
1085
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1086
+ var SkipPrevIcon = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TI.IconPlayerSkipBackFilled, { style: { width: 12, height: 12 } });
1087
+ var PrevIcon = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TI.IconCaretLeftFilled, { style: { width: 15, height: 15 } });
1088
+ var NextIcon = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TI.IconCaretRightFilled, { style: { width: 15, height: 15 } });
1089
+ var SkipNextIcon = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TI.IconPlayerSkipForwardFilled, { style: { width: 12, height: 12 } });
1090
+ function AppPagination(props) {
1091
+ const theme = (0, import_core5.useMantineTheme)();
1092
+ const total = Math.ceil(Math.ceil(props.total || 0) / 10);
1093
+ const chunkedTotal = props.chunkedTotal;
1094
+ const renderComponent = () => {
1095
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1096
+ import_core5.Group,
1097
+ {
1098
+ w: "100%",
1099
+ py: "xl",
1100
+ align: "center",
1101
+ justify: props.withDetails ? "space-between" : "flex-end",
1102
+ mt: "lg",
1103
+ "data-testid": "apppagination-main-group",
1104
+ children: [
1105
+ props.withDetails && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_core5.Text, { "data-testid": "apppagination-details-text", children: [
1106
+ "P\xE1g. ",
1107
+ Number(props?.value),
1108
+ " de ",
1109
+ chunkedTotal ?? total,
1110
+ " ",
1111
+ props.total ? `(${props.total} encontrados)` : ""
1112
+ ] }),
1113
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1114
+ import_core5.Pagination.Root,
1115
+ {
1116
+ total: chunkedTotal ?? total,
1117
+ value: props.value,
1118
+ onChange: (page) => {
1119
+ props.onChange?.(page);
1120
+ },
1121
+ onFirstPage: () => props.onChange?.(1),
1122
+ onLastPage: () => props.onChange?.(total),
1123
+ onNextPage: () => props.onChange?.(Number(props?.value) + 1),
1124
+ onPreviousPage: () => props.onChange?.(Number(props?.value) - 1),
1125
+ size: "sm",
1126
+ "data-testid": "apppagination-root",
1127
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_core5.Group, { gap: 5, justify: "center", "data-testid": "apppagination-buttons-group", children: [
1128
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1129
+ import_core5.Pagination.First,
1130
+ {
1131
+ icon: SkipPrevIcon,
1132
+ style: {
1133
+ backgroundColor: "#00b4cc",
1134
+ color: theme.white
1135
+ },
1136
+ "data-testid": "apppagination-first"
1137
+ }
1138
+ ),
1139
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1140
+ import_core5.Pagination.Previous,
1141
+ {
1142
+ icon: PrevIcon,
1143
+ style: {
1144
+ backgroundColor: "#00b4cc",
1145
+ color: theme.white
1146
+ },
1147
+ "data-testid": "apppagination-previous"
1148
+ }
1149
+ ),
1150
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_core5.Pagination.Items, { "data-testid": "apppagination-items" }),
1151
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1152
+ import_core5.Pagination.Next,
1153
+ {
1154
+ icon: NextIcon,
1155
+ style: {
1156
+ backgroundColor: "#00b4cc",
1157
+ color: theme.white
1158
+ },
1159
+ "data-testid": "apppagination-next"
1160
+ }
1161
+ ),
1162
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1163
+ import_core5.Pagination.Last,
1164
+ {
1165
+ icon: SkipNextIcon,
1166
+ style: {
1167
+ backgroundColor: "#00b4cc",
1168
+ color: theme.white
1169
+ },
1170
+ "data-testid": "apppagination-last"
1171
+ }
1172
+ )
1173
+ ] })
1174
+ }
1175
+ )
1176
+ ]
1177
+ }
1178
+ );
1179
+ };
1180
+ return renderComponent();
1181
+ }
1182
+
1183
+ // src/components/PatientAppointmentHistory.tsx
1184
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1185
+ var PatientAppointmentHistory = ({ patientId }) => {
1186
+ const { userAccountId } = useTTNSharedContext();
1187
+ const [currentPage, setCurrentPage] = (0, import_react6.useState)(1);
1188
+ const [selectedAppointment, setSelectedAppointment] = (0, import_react6.useState)();
1189
+ const { data: appointments, rowTotal } = useAppointments({
1190
+ enabled: Boolean(patientId),
1191
+ filters: {
1192
+ idPatient: patientId,
1193
+ page: currentPage,
1194
+ perpage: 10,
1195
+ idAccount: userAccountId ?? 0
1196
+ }
1197
+ });
1198
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1199
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Box, { children: [
1200
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Title, { order: 6, c: "brand-color", mb: "xs", children: "Historial de citas" }),
1201
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Table, { children: [
1202
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Thead, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Table.Tr, { children: [
1203
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Th, { ta: "center", children: "Fecha" }),
1204
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Th, { ta: "start", children: " Servicio" }),
1205
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Th, { ta: "center", children: "Estado" }),
1206
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Th, {})
1207
+ ] }) }),
1208
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Table.Tbody, { children: [
1209
+ appointments?.map((appointment) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Table.Tr, { children: [
1210
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Td, { ta: "center", children: appointment.dateApp }),
1211
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Td, { ta: "start", tt: "capitalize", children: appointment.serviceName?.toLowerCase() }),
1212
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Td, { miw: 132, ta: "center", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1213
+ import_core6.Badge,
1214
+ {
1215
+ variant: "light",
1216
+ style: {
1217
+ maxWidth: 150,
1218
+ width: "100%",
1219
+ color: appointment.fontColorStatus,
1220
+ background: appointment.bgColorStatus
1221
+ },
1222
+ children: appointment.status
1223
+ }
1224
+ ) }),
1225
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Td, { ta: "center", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1226
+ import_core6.ActionIcon,
1227
+ {
1228
+ variant: "subtle",
1229
+ onClick: () => setSelectedAppointment(appointment),
1230
+ "data-testid": "patient-appointment-history-view-details-button",
1231
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons_react5.IconSearch, {})
1232
+ }
1233
+ ) })
1234
+ ] }, appointment.id)),
1235
+ !appointments?.length && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Tr, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Table.Td, { ta: "center", colSpan: 4, children: "No hay informaci\xF3n para mostrar." }) })
1236
+ ] })
1237
+ ] }),
1238
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1239
+ AppPagination,
1240
+ {
1241
+ value: currentPage,
1242
+ total: rowTotal,
1243
+ rowTotal,
1244
+ onChange: setCurrentPage
1245
+ }
1246
+ )
1247
+ ] }),
1248
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1249
+ import_core6.Modal.Root,
1250
+ {
1251
+ opened: Boolean(selectedAppointment),
1252
+ onClose: () => setSelectedAppointment(void 0),
1253
+ size: "100%",
1254
+ children: [
1255
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Modal.Overlay, {}),
1256
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Modal.Content, { children: [
1257
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Modal.Header, { style: { alignItems: "flex-start" }, children: [
1258
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Modal.Title, { children: [
1259
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "brand-color", ta: "center", fz: 24, fw: 700, children: "Detalles de la cita" }),
1260
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Text, { c: selectedAppointment?.fontColorStatus, ta: "center", fz: 20, children: [
1261
+ "Estado - ",
1262
+ selectedAppointment?.status
1263
+ ] })
1264
+ ] }),
1265
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Modal.CloseButton, {})
1266
+ ] }),
1267
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Modal.Body, { children: [
1268
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Text, { ta: "center", c: "secondary-color", fz: 16, fw: 700, children: [
1269
+ "Identificador de la cita no. ",
1270
+ selectedAppointment?.id
1271
+ ] }),
1272
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Flex, { gap: "lg", mt: "md", children: [
1273
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Box, { miw: 228, children: [
1274
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1275
+ import_core6.TextInput,
1276
+ {
1277
+ readOnly: true,
1278
+ label: "Identificaci\xF3n del paciente",
1279
+ value: selectedAppointment?.cluDocument ?? "",
1280
+ mb: "xs"
1281
+ }
1282
+ ),
1283
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1284
+ import_core6.TextInput,
1285
+ {
1286
+ readOnly: true,
1287
+ label: "Primer nombre",
1288
+ value: selectedAppointment?.cluFirstName ?? "",
1289
+ mb: "xs"
1290
+ }
1291
+ ),
1292
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1293
+ import_core6.TextInput,
1294
+ {
1295
+ readOnly: true,
1296
+ label: "Primer apellido",
1297
+ value: selectedAppointment?.cluLastName ?? "",
1298
+ mb: "xs"
1299
+ }
1300
+ ),
1301
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1302
+ import_core6.TextInput,
1303
+ {
1304
+ readOnly: true,
1305
+ label: "Fecha de nacimiento",
1306
+ value: selectedAppointment?.cluBirhDate ?? "",
1307
+ mb: "xs"
1308
+ }
1309
+ ),
1310
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1311
+ import_core6.TextInput,
1312
+ {
1313
+ readOnly: true,
1314
+ label: "WhatsApp",
1315
+ value: selectedAppointment?.cluWhatasapp ?? "",
1316
+ mb: "xs"
1317
+ }
1318
+ ),
1319
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1320
+ import_core6.TextInput,
1321
+ {
1322
+ readOnly: true,
1323
+ label: "Correo electr\xF3nico",
1324
+ value: selectedAppointment?.cluEmail ?? ""
1325
+ }
1326
+ )
1327
+ ] }),
1328
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Box, { style: { flexGrow: 1 }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid, { children: [
1329
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid.Col, { span: 6, children: [
1330
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "secondary-color", fw: 700, children: "Informaci\xF3n de la cita" }),
1331
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid, { children: [
1332
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid.Col, { span: 6, children: [
1333
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Sede" }),
1334
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "M\xE9dico" }),
1335
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Servicio" }),
1336
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Fecha" }),
1337
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "No. Historia cl\xEDnica" }),
1338
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Diagn\xF3stico" })
1339
+ ] }),
1340
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid.Col, { span: 6, children: [
1341
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.siteName, children: selectedAppointment?.siteName ?? "-" }),
1342
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.fullNameDoctor, children: selectedAppointment?.fullNameDoctor ?? "-" }),
1343
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.serviceName, children: selectedAppointment?.serviceName ?? "-" }),
1344
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.dateApp, children: selectedAppointment?.dateApp ?? "-" }),
1345
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1346
+ import_core6.Text,
1347
+ {
1348
+ lineClamp: 1,
1349
+ title: String(selectedAppointment?.clinicalHistoryID ?? ""),
1350
+ children: selectedAppointment?.clinicalHistoryID ?? "-"
1351
+ }
1352
+ ),
1353
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.dxName, children: selectedAppointment?.dxName ?? "-" })
1354
+ ] })
1355
+ ] })
1356
+ ] }),
1357
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid.Col, { span: 6, children: [
1358
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "secondary-color", fw: 700, children: "Aseguradora" }),
1359
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid, { children: [
1360
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid.Col, { span: 6, children: [
1361
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Aseguradora" }),
1362
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Contrato" }),
1363
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Poblaci\xF3n" }),
1364
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Grupo de ingreso" }),
1365
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Observaciones" })
1366
+ ] }),
1367
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid.Col, { span: 6, children: [
1368
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.ccName, children: selectedAppointment?.ccName ?? "-" }),
1369
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.contractName, children: selectedAppointment?.contractName ?? "-" }),
1370
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.popName, children: selectedAppointment?.popName ?? "-" }),
1371
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.crtName, children: selectedAppointment?.crtName ?? "-" }),
1372
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { lineClamp: 1, title: selectedAppointment?.appObservations, children: selectedAppointment?.appObservations || "-" })
1373
+ ] })
1374
+ ] })
1375
+ ] }),
1376
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid.Col, { span: 6, children: [
1377
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "secondary-color", fw: 700, children: "Recaudo" }),
1378
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid, { children: [
1379
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid.Col, { span: 6, children: [
1380
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Efectivo" }),
1381
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Total d\xE9bito" }),
1382
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Total" }),
1383
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Asesor" }),
1384
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { c: "dimmed", fw: 700, children: "Fecha" })
1385
+ ] }),
1386
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core6.Grid.Col, { span: 6, children: [
1387
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { children: "-" }),
1388
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { children: "-" }),
1389
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { children: "-" }),
1390
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { children: "-" }),
1391
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { children: "-" }),
1392
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.Text, { children: "-" })
1393
+ ] })
1394
+ ] })
1395
+ ] })
1396
+ ] }) })
1397
+ ] })
1398
+ ] })
1399
+ ] })
1400
+ ]
1401
+ }
1402
+ )
1403
+ ] });
1404
+ };
1405
+
1406
+ // src/components/PatientForm.tsx
1407
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1408
+ var PatientForm = ({
1409
+ defaultMode,
1410
+ patientId,
1411
+ onSavePatient,
1412
+ onSaveError,
1413
+ onBack
1414
+ }) => {
1415
+ const { userAccountId } = useTTNSharedContext();
1416
+ const [mode, setMode] = (0, import_react7.useState)(defaultMode);
1417
+ const [openPatientNotes, setOpenPatientNotes] = (0, import_react7.useState)(false);
1418
+ const [openPatientAssistanceRisks, setOpenPatientAssistanceRisks] = (0, import_react7.useState)(false);
1419
+ const [openPatientAdministrativeRisks, setOpenPatientAdministrativeRisks] = (0, import_react7.useState)(false);
1420
+ const form = (0, import_form.useForm)({
1421
+ mode: "controlled",
1422
+ initialValues: {
1423
+ documentTypeId: "",
1424
+ documentNumber: "",
1425
+ firstName: "",
1426
+ middleName: "",
1427
+ surname: "",
1428
+ secondSurname: "",
1429
+ birthDate: "",
1430
+ age: "",
1431
+ whatsapp: "",
1432
+ gender: "",
1433
+ affiliationTypeId: "",
1434
+ bloodType: "",
1435
+ email: "",
1436
+ provinceId: "",
1437
+ cityId: "",
1438
+ homeAddress: "",
1439
+ neighborhood: "",
1440
+ cellphone: "",
1441
+ homephone: "",
1442
+ emergencyContact: "",
1443
+ maritalStatus: "",
1444
+ occupation: "",
1445
+ use_glasses: "",
1446
+ use_contact_lens: "",
1447
+ isDataPolicyAccepted: false,
1448
+ stratumId: "",
1449
+ educationLevelId: "",
1450
+ ethnicGroupId: "",
1451
+ mandatoryInsurance: {
1452
+ companyId: "",
1453
+ plan: "",
1454
+ population: "",
1455
+ groupId: "",
1456
+ policyNumber: ""
1457
+ },
1458
+ voluntaryInsurance: []
1459
+ }
1460
+ });
1461
+ form.watch("birthDate", ({ value }) => {
1462
+ if (!value) {
1463
+ form.setFieldValue("age", "");
1464
+ return;
1465
+ }
1466
+ const birthDate = (0, import_dayjs.default)(value);
1467
+ const today = (0, import_dayjs.default)();
1468
+ const age = today.diff(birthDate, "year");
1469
+ form.setFieldValue("age", String(age));
1470
+ });
1471
+ const { data: patientInfo, refetch: refetchPatientInfo } = usePatientDetail({
1472
+ enabled: Boolean(patientId) && mode !== "create",
1473
+ filters: {
1474
+ eaccount: userAccountId,
1475
+ id: patientId
1476
+ }
1477
+ });
1478
+ const { data: documentTypes } = useDocumentTypes({});
1479
+ const { data: affiliationTypes } = useAffiliationTypes({
1480
+ filters: { eaccount: userAccountId }
1481
+ });
1482
+ const { data: provinces } = useProvinces({
1483
+ filters: { eaccount: userAccountId }
1484
+ });
1485
+ const { data: cities } = useCities({
1486
+ enabled: Boolean(form.values.provinceId),
1487
+ provinceId: Number(form.values.provinceId) || void 0
1488
+ });
1489
+ const { data: stratums } = useStratums({});
1490
+ const { data: ethnicGroups } = useEthnicGroups({
1491
+ filters: { eaccount: userAccountId }
1492
+ });
1493
+ const { data: educationLevels } = useEducationLevels({
1494
+ filters: { eaccount: userAccountId }
1495
+ });
1496
+ const { data: companyClients } = useCompanyClients({
1497
+ filters: { eaccount: userAccountId }
1498
+ });
1499
+ const { data: contracts } = useContracts({
1500
+ enabled: Boolean(form.values.mandatoryInsurance.companyId),
1501
+ filters: {
1502
+ eaccount: userAccountId,
1503
+ client: Number(form.values.mandatoryInsurance.companyId) || void 0
1504
+ }
1505
+ });
1506
+ const { data: contractPopulations } = useContractPopulations({
1507
+ enabled: Boolean(form.values.mandatoryInsurance.plan),
1508
+ filters: {
1509
+ eaccount: userAccountId,
1510
+ contract: Number(form.values.mandatoryInsurance.plan) || void 0
1511
+ }
1512
+ });
1513
+ const { data: incomeGroups } = useIncomeGroups({
1514
+ enabled: Boolean(form.values.mandatoryInsurance.companyId),
1515
+ filters: {
1516
+ eaccount: userAccountId,
1517
+ corpclientId: Number(form.values.mandatoryInsurance.companyId) || void 0
1518
+ }
1519
+ });
1520
+ const handleSubmit = (values) => {
1521
+ const requiredFields = [
1522
+ {
1523
+ value: values.documentTypeId,
1524
+ message: "El campo Tipo de Documento es obligatorio."
1525
+ },
1526
+ {
1527
+ value: values.documentNumber,
1528
+ message: "El campo N\xFAmero de Documento es obligatorio."
1529
+ },
1530
+ {
1531
+ value: values.firstName,
1532
+ message: "El campo Primer Nombre es obligatorio."
1533
+ },
1534
+ {
1535
+ value: values.surname,
1536
+ message: "El campo Primer Apellido es obligatorio."
1537
+ },
1538
+ {
1539
+ value: values.birthDate,
1540
+ message: "El campo Fecha de Nacimiento es obligatorio."
1541
+ },
1542
+ {
1543
+ value: values.whatsapp,
1544
+ message: "El campo WhatsApp es obligatorio."
1545
+ },
1546
+ {
1547
+ value: values.gender,
1548
+ message: "El campo G\xE9nero es obligatorio."
1549
+ },
1550
+ {
1551
+ value: values.affiliationTypeId,
1552
+ message: "El campo Tipo de afiliado es obligatorio."
1553
+ },
1554
+ {
1555
+ value: values.maritalStatus,
1556
+ message: "El campo Estado civil es obligatorio."
1557
+ },
1558
+ {
1559
+ value: values.provinceId,
1560
+ message: "El campo Departamento es obligatorio."
1561
+ },
1562
+ {
1563
+ value: values.cityId,
1564
+ message: "El campo Municipio es obligatorio."
1565
+ },
1566
+ {
1567
+ value: values.cellphone,
1568
+ message: "El campo Celular es obligatorio."
1569
+ },
1570
+ {
1571
+ value: values.stratumId,
1572
+ message: "El campo Estrato es obligatorio."
1573
+ },
1574
+ {
1575
+ value: values.ethnicGroupId,
1576
+ message: "El campo Pertenencia \xE9tnica es obligatorio."
1577
+ },
1578
+ {
1579
+ value: values.educationLevelId,
1580
+ message: "El campo Nivel educativo es obligatorio."
1581
+ },
1582
+ {
1583
+ value: values.mandatoryInsurance.companyId,
1584
+ message: "Aseguradora obligatoria: El campo Seguro es obligatorio."
1585
+ },
1586
+ {
1587
+ value: values.mandatoryInsurance.plan,
1588
+ message: "Aseguradora obligatoria: El campo Plan es obligatorio."
1589
+ },
1590
+ {
1591
+ value: values.mandatoryInsurance.population,
1592
+ message: "Aseguradora obligatoria: El campo Poblaci\xF3n es obligatorio."
1593
+ },
1594
+ {
1595
+ value: values.mandatoryInsurance.groupId,
1596
+ message: "Aseguradora obligatoria: El campo Grupo de ingreso es obligatorio."
1597
+ }
1598
+ ];
1599
+ for (const field of requiredFields) {
1600
+ if (!field.value) {
1601
+ onSaveError?.(field.message);
1602
+ return;
1603
+ }
1604
+ }
1605
+ const voluntaryRequiredFields = values.voluntaryInsurance.map((insurance, index) => {
1606
+ const fields = [
1607
+ {
1608
+ value: insurance.companyType,
1609
+ message: `Aseguradora voluntaria #${index + 1}: El campo Tipo de seguro es obligatorio.`
1610
+ },
1611
+ {
1612
+ value: insurance.companyId,
1613
+ message: `Aseguradora voluntaria #${index + 1}: El campo Seguro es obligatorio.`
1614
+ },
1615
+ {
1616
+ value: insurance.plan,
1617
+ message: `Aseguradora voluntaria #${index + 1}: El campo Plan es obligatorio.`
1618
+ },
1619
+ {
1620
+ value: insurance.population,
1621
+ message: `Aseguradora voluntaria #${index + 1}: El campo Poblaci\xF3n es obligatorio.`
1622
+ }
1623
+ ];
1624
+ if (VOLUNTARY_INSURANCE_TAGS.includes(insurance.companyTypeTag)) {
1625
+ fields.push({
1626
+ value: insurance.groupId,
1627
+ message: `Aseguradora voluntaria #${index + 1}: El campo Grupo de ingreso es obligatorio.`
1628
+ });
1629
+ }
1630
+ return fields;
1631
+ });
1632
+ for (const insuranceFields of voluntaryRequiredFields) {
1633
+ for (const field of insuranceFields) {
1634
+ if (!field.value) {
1635
+ onSaveError?.(field.message);
1636
+ return;
1637
+ }
1638
+ }
1639
+ }
1640
+ if (!values.isDataPolicyAccepted) {
1641
+ onSaveError?.("Debe aceptar la pol\xEDtica de tratamiento de datos.");
1642
+ return;
1643
+ }
1644
+ onSavePatient?.(createPatientPayload(values), mode);
1645
+ };
1646
+ const handleCancelForm = () => {
1647
+ if (mode === "edit") {
1648
+ setMode("view");
1649
+ refetchPatientInfo();
1650
+ return;
1651
+ }
1652
+ onBack?.();
1653
+ };
1654
+ const handleAddVoluntaryInsurance = () => {
1655
+ form.insertListItem("voluntaryInsurance", {
1656
+ companyTypeTag: "",
1657
+ id: Date.now().toString(),
1658
+ companyType: "",
1659
+ companyId: "",
1660
+ plan: "",
1661
+ population: "",
1662
+ groupId: "",
1663
+ policyNumber: ""
1664
+ });
1665
+ };
1666
+ (0, import_react7.useEffect)(() => {
1667
+ if (!patientInfo || mode === "create") return;
1668
+ const patientForm = createPatientForm(patientInfo);
1669
+ form.setValues(patientForm);
1670
+ }, [patientInfo, mode]);
1671
+ const documentTypeOptions = (0, import_react7.useMemo)(() => {
1672
+ return documentTypes?.map((dt) => ({
1673
+ value: String(dt.id),
1674
+ label: dt.description
1675
+ }));
1676
+ }, [documentTypes]);
1677
+ const affiliationTypeOptions = (0, import_react7.useMemo)(() => {
1678
+ return affiliationTypes?.map((at) => ({
1679
+ value: String(at.affiliationTypeId),
1680
+ label: at.affiliationTypeName
1681
+ }));
1682
+ }, [affiliationTypes]);
1683
+ const provinceOptions = (0, import_react7.useMemo)(() => {
1684
+ return provinces?.map((p) => ({
1685
+ value: String(p.id),
1686
+ label: p.name
1687
+ }));
1688
+ }, [provinces]);
1689
+ const cityOptions = (0, import_react7.useMemo)(() => {
1690
+ return cities?.map((c) => ({
1691
+ value: String(c.id),
1692
+ label: `${c.name} - ${c.geocode}`
1693
+ }));
1694
+ }, [cities]);
1695
+ const stratumOptions = (0, import_react7.useMemo)(() => {
1696
+ return stratums?.map((s) => ({
1697
+ value: String(s.id),
1698
+ label: s.name
1699
+ }));
1700
+ }, [stratums]);
1701
+ const ethnicGroupOptions = (0, import_react7.useMemo)(() => {
1702
+ return ethnicGroups?.map((eg) => ({
1703
+ value: String(eg.id),
1704
+ label: eg.description
1705
+ }));
1706
+ }, [ethnicGroups]);
1707
+ const educationLevelOptions = (0, import_react7.useMemo)(() => {
1708
+ return educationLevels?.map((el) => ({
1709
+ value: String(el.id),
1710
+ label: el.description
1711
+ }));
1712
+ }, [educationLevels]);
1713
+ const companyClientOptions = (0, import_react7.useMemo)(() => {
1714
+ return companyClients?.map((cc) => ({
1715
+ value: String(cc.id),
1716
+ label: cc.name
1717
+ }));
1718
+ }, [companyClients]);
1719
+ const contractOptions = (0, import_react7.useMemo)(() => {
1720
+ return contracts?.map((c) => ({
1721
+ value: String(c.id),
1722
+ label: c.name
1723
+ }));
1724
+ }, [contracts]);
1725
+ const contractPopulationOptions = (0, import_react7.useMemo)(() => {
1726
+ return contractPopulations?.map((cp) => ({
1727
+ value: String(cp.idPopulation),
1728
+ label: cp.name
1729
+ }));
1730
+ }, [contractPopulations]);
1731
+ const incomeGroupOptions = (0, import_react7.useMemo)(() => {
1732
+ return incomeGroups?.map((ig) => ({
1733
+ value: String(ig.crtId),
1734
+ label: ig.copaymentRateName
1735
+ }));
1736
+ }, [incomeGroups]);
1737
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1738
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Flex, { w: "100%", justify: "flex-end", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1739
+ import_core7.ActionIcon,
1740
+ {
1741
+ variant: "subtle",
1742
+ onClick: handleCancelForm,
1743
+ "data-testid": "patient-form-close-button",
1744
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons_react6.IconX, { style: { width: 30, height: 30 } })
1745
+ }
1746
+ ) }),
1747
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Title, { c: "secondary-color", mt: "xs", children: patientFormTitles[mode] }),
1748
+ mode !== "create" && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_core7.Flex, { w: "100%", justify: "flex-end", gap: "xs", my: "xs", children: [
1749
+ mode === "view" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Tooltip, { label: "Editar", withArrow: true, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1750
+ import_core7.ActionIcon,
1751
+ {
1752
+ variant: "subtle",
1753
+ onClick: () => setMode("edit"),
1754
+ "data-testid": "patient-form-edit-button",
1755
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons_react6.IconPencil, { style: { width: 24, height: 24 } })
1756
+ }
1757
+ ) }),
1758
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Tooltip, { label: "Ver notas", withArrow: true, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1759
+ import_core7.ActionIcon,
1760
+ {
1761
+ variant: "subtle",
1762
+ onClick: () => setOpenPatientNotes(true),
1763
+ "data-testid": "patient-form-notes-button",
1764
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons_react6.IconMessage, { style: { width: 24, height: 24 } })
1765
+ }
1766
+ ) }),
1767
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Tooltip, { label: "Riesgo asistencial", withArrow: true, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1768
+ import_core7.ActionIcon,
1769
+ {
1770
+ variant: "subtle",
1771
+ color: "#83c036",
1772
+ onClick: () => setOpenPatientAssistanceRisks(true),
1773
+ "data-testid": "patient-form-assistance-risks-button",
1774
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons_react6.IconExclamationCircleFilled, { style: { width: 24, height: 24 } })
1775
+ }
1776
+ ) }),
1777
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Tooltip, { label: "Riesgo administrativo", withArrow: true, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1778
+ import_core7.ActionIcon,
1779
+ {
1780
+ variant: "subtle",
1781
+ color: "#f39682",
1782
+ onClick: () => setOpenPatientAdministrativeRisks(true),
1783
+ "data-testid": "patient-form-administrative-risks-button",
1784
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons_react6.IconExclamationCircleFilled, { style: { width: 24, height: 24 } })
1785
+ }
1786
+ ) })
1787
+ ] }),
1788
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("form", { onSubmit: form.onSubmit(handleSubmit), children: [
1789
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_core7.Grid, { children: [
1790
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1791
+ import_core7.Select,
1792
+ {
1793
+ readOnly: mode === "view",
1794
+ withAsterisk: mode !== "view",
1795
+ label: "Tipo de Documento",
1796
+ data: documentTypeOptions,
1797
+ ...form.getInputProps("documentTypeId"),
1798
+ "data-testid": "patient-form-document-type-select"
1799
+ }
1800
+ ) }),
1801
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1802
+ import_core7.TextInput,
1803
+ {
1804
+ readOnly: mode === "view",
1805
+ withAsterisk: mode !== "view",
1806
+ label: "N\xFAmero de Documento",
1807
+ ...form.getInputProps("documentNumber"),
1808
+ "data-testid": "patient-form-document-number-input"
1809
+ }
1810
+ ) }),
1811
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1812
+ import_core7.TextInput,
1813
+ {
1814
+ readOnly: mode === "view",
1815
+ withAsterisk: mode !== "view",
1816
+ label: "Primer Nombre",
1817
+ ...form.getInputProps("firstName"),
1818
+ "data-testid": "patient-form-first-name-input"
1819
+ }
1820
+ ) }),
1821
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1822
+ import_core7.TextInput,
1823
+ {
1824
+ readOnly: mode === "view",
1825
+ label: "Segundo Nombre",
1826
+ ...form.getInputProps("middleName"),
1827
+ "data-testid": "patient-form-middle-name-input"
1828
+ }
1829
+ ) }),
1830
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1831
+ import_core7.TextInput,
1832
+ {
1833
+ readOnly: mode === "view",
1834
+ withAsterisk: mode !== "view",
1835
+ label: "Primer Apellido",
1836
+ ...form.getInputProps("surname"),
1837
+ "data-testid": "patient-form-surname-input"
1838
+ }
1839
+ ) }),
1840
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1841
+ import_core7.TextInput,
1842
+ {
1843
+ readOnly: mode === "view",
1844
+ label: "Segundo Apellido",
1845
+ ...form.getInputProps("secondSurname"),
1846
+ "data-testid": "patient-form-second-surname-input"
1847
+ }
1848
+ ) }),
1849
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1850
+ import_core7.TextInput,
1851
+ {
1852
+ readOnly: mode === "view",
1853
+ withAsterisk: mode !== "view",
1854
+ label: "Fecha de Nacimiento",
1855
+ type: "date",
1856
+ ...form.getInputProps("birthDate"),
1857
+ "data-testid": "patient-form-birth-date-input"
1858
+ }
1859
+ ) }),
1860
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1861
+ import_core7.NumberInput,
1862
+ {
1863
+ readOnly: true,
1864
+ label: "Edad",
1865
+ suffix: !form.values.age ? "" : " a\xF1os",
1866
+ ...form.getInputProps("age"),
1867
+ "data-testid": "patient-form-age-input"
1868
+ }
1869
+ ) }),
1870
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1871
+ import_core7.NumberInput,
1872
+ {
1873
+ readOnly: mode === "view",
1874
+ withAsterisk: mode !== "view",
1875
+ label: "WhatsApp",
1876
+ allowNegative: false,
1877
+ allowDecimal: false,
1878
+ ...form.getInputProps("whatsapp"),
1879
+ "data-testid": "patient-form-whatsapp-input"
1880
+ }
1881
+ ) }),
1882
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1883
+ import_core7.Select,
1884
+ {
1885
+ readOnly: mode === "view",
1886
+ withAsterisk: mode !== "view",
1887
+ label: "G\xE9nero",
1888
+ data: genderOptions,
1889
+ ...form.getInputProps("gender"),
1890
+ "data-testid": "patient-form-gender-select"
1891
+ }
1892
+ ) }),
1893
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1894
+ import_core7.Select,
1895
+ {
1896
+ readOnly: mode === "view",
1897
+ withAsterisk: mode !== "view",
1898
+ label: "Tipo de afiliaci\xF3n",
1899
+ data: affiliationTypeOptions,
1900
+ ...form.getInputProps("affiliationTypeId"),
1901
+ "data-testid": "patient-form-affiliation-type-select"
1902
+ }
1903
+ ) }),
1904
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1905
+ import_core7.TextInput,
1906
+ {
1907
+ readOnly: mode === "view",
1908
+ label: "Correo electr\xF3nico",
1909
+ ...form.getInputProps("email"),
1910
+ "data-testid": "patient-form-email-input"
1911
+ }
1912
+ ) }),
1913
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1914
+ import_core7.Select,
1915
+ {
1916
+ readOnly: mode === "view",
1917
+ withAsterisk: mode !== "view",
1918
+ label: "Estado civil",
1919
+ data: maritalStatusOptions,
1920
+ ...form.getInputProps("maritalStatus"),
1921
+ "data-testid": "patient-form-marital-status-select"
1922
+ }
1923
+ ) }),
1924
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 12, mt: "sm", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1925
+ import_core7.Checkbox,
1926
+ {
1927
+ readOnly: mode === "view",
1928
+ label: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_core7.Text, { fz: "sm", children: [
1929
+ "Autorizo el tratamiento de mis datos personales conforme a la",
1930
+ " ",
1931
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1932
+ import_core7.Text,
1933
+ {
1934
+ span: true,
1935
+ c: "brand-color",
1936
+ td: "underline",
1937
+ style: { cursor: "pointer" },
1938
+ "data-testid": "patient-form-data-policy-link",
1939
+ children: "pol\xEDtica de tratamiento de datos."
1940
+ }
1941
+ )
1942
+ ] }),
1943
+ ...form.getInputProps("isDataPolicyAccepted", { type: "checkbox" }),
1944
+ styles: { inner: { marginTop: 2 } },
1945
+ "data-testid": "patient-form-data-policy-checkbox"
1946
+ }
1947
+ ) }),
1948
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { mt: "md", span: 12, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Title, { order: 6, c: "brand-color", children: "Informaci\xF3n complementaria" }) }),
1949
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1950
+ import_core7.Select,
1951
+ {
1952
+ readOnly: mode === "view",
1953
+ withAsterisk: mode !== "view",
1954
+ label: "Departamento",
1955
+ data: provinceOptions,
1956
+ ...form.getInputProps("provinceId"),
1957
+ onChange: (value) => {
1958
+ form.setFieldValue("provinceId", value || "");
1959
+ form.setFieldValue("cityId", "");
1960
+ },
1961
+ "data-testid": "patient-form-province-select"
1962
+ }
1963
+ ) }),
1964
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1965
+ import_core7.Select,
1966
+ {
1967
+ readOnly: mode === "view",
1968
+ withAsterisk: mode !== "view",
1969
+ label: "Municipio",
1970
+ data: cityOptions,
1971
+ ...form.getInputProps("cityId"),
1972
+ "data-testid": "patient-form-city-select"
1973
+ }
1974
+ ) }),
1975
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1976
+ import_core7.TextInput,
1977
+ {
1978
+ readOnly: mode === "view",
1979
+ label: "Direcci\xF3n",
1980
+ ...form.getInputProps("homeAddress"),
1981
+ "data-testid": "patient-form-home-address-input"
1982
+ }
1983
+ ) }),
1984
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1985
+ import_core7.Select,
1986
+ {
1987
+ readOnly: mode === "view",
1988
+ label: "Grupo sangu\xEDneo",
1989
+ data: bloodTypeOptions,
1990
+ ...form.getInputProps("bloodType"),
1991
+ "data-testid": "patient-form-blood-type-select"
1992
+ }
1993
+ ) }),
1994
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1995
+ import_core7.NumberInput,
1996
+ {
1997
+ readOnly: mode === "view",
1998
+ withAsterisk: mode !== "view",
1999
+ label: "Celular",
2000
+ allowNegative: false,
2001
+ allowDecimal: false,
2002
+ decimalScale: 0,
2003
+ ...form.getInputProps("cellphone"),
2004
+ "data-testid": "patient-form-cellphone-input"
2005
+ }
2006
+ ) }),
2007
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2008
+ import_core7.NumberInput,
2009
+ {
2010
+ readOnly: mode === "view",
2011
+ label: "Tel\xE9fono fijo",
2012
+ allowNegative: false,
2013
+ allowDecimal: false,
2014
+ decimalScale: 0,
2015
+ ...form.getInputProps("homephone"),
2016
+ "data-testid": "patient-form-homephone-input"
2017
+ }
2018
+ ) }),
2019
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2020
+ import_core7.Select,
2021
+ {
2022
+ readOnly: mode === "view",
2023
+ label: "Estrato",
2024
+ data: stratumOptions,
2025
+ ...form.getInputProps("stratumId"),
2026
+ "data-testid": "patient-form-stratum-select"
2027
+ }
2028
+ ) }),
2029
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2030
+ import_core7.Select,
2031
+ {
2032
+ readOnly: mode === "view",
2033
+ label: "Pertenencia \xE9tnica",
2034
+ data: ethnicGroupOptions,
2035
+ ...form.getInputProps("ethnicGroupId"),
2036
+ "data-testid": "patient-form-ethnic-group-select"
2037
+ }
2038
+ ) }),
2039
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2040
+ import_core7.Select,
2041
+ {
2042
+ readOnly: mode === "view",
2043
+ label: "Nivel educativo",
2044
+ data: educationLevelOptions,
2045
+ ...form.getInputProps("educationLevelId"),
2046
+ "data-testid": "patient-form-education-level-select"
2047
+ }
2048
+ ) }),
2049
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 12, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_core7.Paper, { withBorder: true, p: "md", bg: "brand-color.0", shadow: "none", children: [
2050
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Title, { order: 6, c: "brand-color", mb: "sm", children: "Aseguradora obligatoria" }),
2051
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_core7.Grid, { children: [
2052
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2053
+ import_core7.Select,
2054
+ {
2055
+ readOnly: mode === "view",
2056
+ withAsterisk: mode !== "view",
2057
+ label: "Seguro",
2058
+ data: companyClientOptions,
2059
+ ...form.getInputProps("mandatoryInsurance.companyId"),
2060
+ onChange: (value) => {
2061
+ form.setFieldValue("mandatoryInsurance.companyId", value || "");
2062
+ form.setFieldValue("mandatoryInsurance.plan", "");
2063
+ form.setFieldValue("mandatoryInsurance.population", "");
2064
+ form.setFieldValue("mandatoryInsurance.groupId", "");
2065
+ form.setFieldValue("mandatoryInsurance.policyNumber", "");
2066
+ },
2067
+ "data-testid": "patient-form-mandatory-insurance-company-select"
2068
+ }
2069
+ ) }),
2070
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2071
+ import_core7.Select,
2072
+ {
2073
+ readOnly: mode === "view",
2074
+ withAsterisk: mode !== "view",
2075
+ label: "Plan",
2076
+ data: contractOptions,
2077
+ ...form.getInputProps("mandatoryInsurance.plan"),
2078
+ onChange: (value) => {
2079
+ form.setFieldValue("mandatoryInsurance.plan", value || "");
2080
+ form.setFieldValue("mandatoryInsurance.population", "");
2081
+ form.setFieldValue("mandatoryInsurance.groupId", "");
2082
+ form.setFieldValue("mandatoryInsurance.policyNumber", "");
2083
+ },
2084
+ "data-testid": "patient-form-mandatory-insurance-plan-select"
2085
+ }
2086
+ ) }),
2087
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2088
+ import_core7.Select,
2089
+ {
2090
+ readOnly: mode === "view",
2091
+ withAsterisk: mode !== "view",
2092
+ label: "Poblaci\xF3n",
2093
+ data: contractPopulationOptions,
2094
+ ...form.getInputProps("mandatoryInsurance.population"),
2095
+ "data-testid": "patient-form-mandatory-insurance-population-select"
2096
+ }
2097
+ ) }),
2098
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2099
+ import_core7.Select,
2100
+ {
2101
+ readOnly: mode === "view",
2102
+ withAsterisk: mode !== "view",
2103
+ label: "Grupo de ingreso",
2104
+ data: incomeGroupOptions,
2105
+ ...form.getInputProps("mandatoryInsurance.groupId"),
2106
+ "data-testid": "patient-form-mandatory-insurance-group-select"
2107
+ }
2108
+ ) }),
2109
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2110
+ import_core7.TextInput,
2111
+ {
2112
+ readOnly: mode === "view",
2113
+ label: "N\xFAmero de p\xF3liza",
2114
+ ...form.getInputProps("mandatoryInsurance.policyNumber"),
2115
+ "data-testid": "patient-form-mandatory-insurance-policy-number-input"
2116
+ }
2117
+ ) })
2118
+ ] })
2119
+ ] }) }),
2120
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_core7.Grid.Col, { span: 12, children: [
2121
+ form.values.voluntaryInsurance.map((insurance, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2122
+ PatientVoluntaryInsuranceForm,
2123
+ {
2124
+ index,
2125
+ mode,
2126
+ form
2127
+ },
2128
+ insurance.id ?? index
2129
+ )),
2130
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Flex, { justify: "flex-end", children: mode !== "view" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2131
+ import_core7.Button,
2132
+ {
2133
+ variant: "outline",
2134
+ color: "secondary",
2135
+ size: "xs",
2136
+ onClick: handleAddVoluntaryInsurance,
2137
+ leftSection: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons_react6.IconPlus, { style: { width: 16, height: 16 } }),
2138
+ "data-testid": "patient-form-add-voluntary-insurance-button",
2139
+ children: "Agregar aseguradora voluntaria"
2140
+ }
2141
+ ) })
2142
+ ] })
2143
+ ] }),
2144
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core7.Flex, { justify: "flex-end", mt: "lg", children: mode !== "view" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2145
+ import_core7.Button,
2146
+ {
2147
+ type: "submit",
2148
+ color: "secondary-color",
2149
+ size: "sm",
2150
+ "data-testid": "patient-form-save-button",
2151
+ children: "Guardar"
2152
+ }
2153
+ ) }),
2154
+ mode === "view" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PatientAppointmentHistory, { patientId })
2155
+ ] }),
2156
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2157
+ PatientNotes,
2158
+ {
2159
+ isOpen: openPatientNotes,
2160
+ onClose: () => setOpenPatientNotes(false),
2161
+ patientId
2162
+ }
2163
+ ),
2164
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2165
+ PatientAssistanceRisks,
2166
+ {
2167
+ isOpen: openPatientAssistanceRisks,
2168
+ onClose: () => setOpenPatientAssistanceRisks(false),
2169
+ patientId
2170
+ }
2171
+ ),
2172
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2173
+ PatientAdministrativeRisks,
2174
+ {
2175
+ isOpen: openPatientAdministrativeRisks,
2176
+ onClose: () => setOpenPatientAdministrativeRisks(false),
2177
+ patientId
2178
+ }
2179
+ )
2180
+ ] });
2181
+ };
2182
+ var createPatientPayload = (values) => {
2183
+ const mandatoryInsurance = {
2184
+ corporateClientId: Number(values.mandatoryInsurance.companyId),
2185
+ contractId: Number(values.mandatoryInsurance.plan),
2186
+ populationId: Number(values.mandatoryInsurance.population),
2187
+ crtId: Number(values.mandatoryInsurance.groupId),
2188
+ policy: values.mandatoryInsurance.policyNumber,
2189
+ isMain: 1
2190
+ };
2191
+ const voluntaryInsurance = values.voluntaryInsurance.map((insurance) => ({
2192
+ companyTypeId: insurance.companyType,
2193
+ corporateClientId: Number(insurance.companyId),
2194
+ contractId: Number(insurance.plan),
2195
+ populationId: Number(insurance.population),
2196
+ crtId: Number(insurance.groupId),
2197
+ policy: insurance.policyNumber,
2198
+ isMain: 0
2199
+ }));
2200
+ return {
2201
+ docTypeId: Number(values.documentTypeId),
2202
+ documentType: Number(values.documentTypeId),
2203
+ document: values.documentNumber,
2204
+ firstName: values.firstName,
2205
+ otherNames: values.middleName ?? "",
2206
+ lastName: values.surname,
2207
+ secondSurname: values.secondSurname ?? "",
2208
+ birthDate: values.birthDate,
2209
+ age: values.age,
2210
+ whatsapp: values.whatsapp,
2211
+ gender: values.gender,
2212
+ affiliationType: Number(values.affiliationTypeId),
2213
+ email: values.email,
2214
+ maritalStatus: values.maritalStatus,
2215
+ provinceId: Number(values.provinceId),
2216
+ cityId: Number(values.cityId),
2217
+ homeAddress: values.homeAddress,
2218
+ bloodType: values.bloodType,
2219
+ cellphone: String(values.cellphone),
2220
+ homephone: values.homephone,
2221
+ emergencyContact: values.emergencyContact,
2222
+ neighborhood: values.neighborhood,
2223
+ ocupation: values.occupation,
2224
+ use_contact_lens: values.use_contact_lens,
2225
+ use_glasses: values.use_glasses,
2226
+ stratumId: Number(values.stratumId),
2227
+ ethnicGroupId: Number(values.ethnicGroupId),
2228
+ educationLevelId: Number(values.educationLevelId),
2229
+ contracts: [mandatoryInsurance, ...voluntaryInsurance]
2230
+ };
2231
+ };
2232
+ var createPatientForm = (info) => {
2233
+ const mandatoryInsurance = info.contracts.find((c) => c.isMain === 1);
2234
+ const voluntaryInsurance = info.contracts.filter((c) => c.isMain === 0);
2235
+ return {
2236
+ documentTypeId: String(info.docTypeId ?? ""),
2237
+ documentNumber: info.document ?? "",
2238
+ firstName: info.firstName ?? "",
2239
+ middleName: info.otherNames ?? "",
2240
+ surname: info.lastName ?? "",
2241
+ secondSurname: info.secondSurname ?? "",
2242
+ birthDate: info.birthDate ?? "",
2243
+ age: info.age ?? "",
2244
+ whatsapp: info.whatsapp ?? "",
2245
+ gender: info.gender ?? "",
2246
+ affiliationTypeId: String(info.affiliationTypeId ?? ""),
2247
+ bloodType: info.bloodType ?? "",
2248
+ email: info.email ?? "",
2249
+ provinceId: String(info.provinceId ?? ""),
2250
+ cityId: String(info.cityId ?? ""),
2251
+ homeAddress: info.homeAddress ?? "",
2252
+ neighborhood: info.neighborhood ?? "",
2253
+ cellphone: info.cellphone ?? "",
2254
+ homephone: info.homephone ?? "",
2255
+ emergencyContact: info.emergencyContact ?? "",
2256
+ maritalStatus: info.maritalStatus ?? "",
2257
+ occupation: info.ocupation ?? "",
2258
+ use_glasses: info.use_glasses ?? "",
2259
+ use_contact_lens: info.use_contact_lens ?? "",
2260
+ isDataPolicyAccepted: info.processing_of_personal_data ?? false,
2261
+ stratumId: String(info.stratum_id ?? ""),
2262
+ educationLevelId: String(info.educationLevel.id ?? ""),
2263
+ ethnicGroupId: String(info.ethnicGroup.id ?? ""),
2264
+ mandatoryInsurance: {
2265
+ companyId: String(mandatoryInsurance?.corporateClientId ?? ""),
2266
+ plan: String(mandatoryInsurance?.contractId ?? ""),
2267
+ population: String(mandatoryInsurance?.populationId ?? ""),
2268
+ groupId: String(mandatoryInsurance?.crtId ?? ""),
2269
+ policyNumber: mandatoryInsurance?.policy ?? ""
2270
+ },
2271
+ voluntaryInsurance: (voluntaryInsurance ?? []).map((insurance) => ({
2272
+ id: Date.now().toString(),
2273
+ companyTypeTag: insurance.companyTypeTag ?? "",
2274
+ companyType: insurance.companyTypeId ?? "",
2275
+ companyId: String(insurance.corporateClientId ?? ""),
2276
+ plan: String(insurance.contractId ?? ""),
2277
+ population: String(insurance.populationId ?? ""),
2278
+ groupId: String(insurance.crtId ?? ""),
2279
+ policyNumber: insurance.policy ?? ""
2280
+ }))
2281
+ };
2282
+ };
2283
+ // Annotate the CommonJS export names for ESM import in node:
2284
+ 0 && (module.exports = {
2285
+ PatientAdministrativeRisks,
2286
+ PatientAppointmentHistory,
2287
+ PatientAssistanceRisks,
2288
+ PatientForm,
2289
+ PatientNotes,
2290
+ TTNSharedProvider,
2291
+ useTTNSharedContext
2292
+ });