From 07223d2ef9a16ee9cf4ea30995d9a38095043c5c Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Thu, 22 Aug 2024 21:45:55 -0600 Subject: [PATCH 01/27] fix: Refactored collaborator endpoint --- .../layers/utils/utils/defaultValues.mjs | 1 + sanitas_backend/layers/utils/utils/index.mjs | 22 ++-- .../update-collaborator.integration.test.mjs | 10 +- .../update-collaborator.mjs | 103 ++++++++---------- 4 files changed, 64 insertions(+), 72 deletions(-) diff --git a/sanitas_backend/layers/utils/utils/defaultValues.mjs b/sanitas_backend/layers/utils/utils/defaultValues.mjs index 8ba7f6dd..058ee458 100644 --- a/sanitas_backend/layers/utils/utils/defaultValues.mjs +++ b/sanitas_backend/layers/utils/utils/defaultValues.mjs @@ -349,3 +349,4 @@ export const genDefaultPsychiatricHistory = () => ({ data: { ill: "", medication: "", dose: "", frecuency: "", ube: false }, }, }); + diff --git a/sanitas_backend/layers/utils/utils/index.mjs b/sanitas_backend/layers/utils/utils/index.mjs index e53fc997..a728d19b 100644 --- a/sanitas_backend/layers/utils/utils/index.mjs +++ b/sanitas_backend/layers/utils/utils/index.mjs @@ -227,7 +227,6 @@ export function mapToAPIStudentInfo(dbStudentInfo) { /** * @typedef {Object} DBCollaborator - * @property {number} id * @property {string} codigo * @property {string} area * @property {number} id_paciente @@ -235,10 +234,9 @@ export function mapToAPIStudentInfo(dbStudentInfo) { /** * @typedef {Object} APICollaborator - * @property {number} id - * @property {string} codigo + * @property {string} code * @property {string} area - * @property {number} patientId + * @property {number} idPatient */ /** @@ -247,16 +245,24 @@ export function mapToAPIStudentInfo(dbStudentInfo) { * @returns {APICollaborator} The collaborator object the API must return. */ export function mapToAPICollaboratorInfo(dbCollaborator) { - const { id, codigo: code, area, id_paciente: patientId } = dbCollaborator; - + const { codigo: code, area, id_paciente: idPatient } = dbCollaborator; return { - id, code, area, - patientId, + idPatient, }; } +/** + * Maps an APICollaborator into a DBCollaborator + * @param {APICollaborator} apiCollaborator + * @returns {DBCollaborator} + */ +export function mapToDBCollaborator(apiCollaborator) { + const {code: codigo, area, idPatient: id_paciente} = apiCollaborator; + return {codigo, area, id_paciente} +} + /** * @typedef {Object} MedicalConditionData * @property {number} version - The version of the data format. diff --git a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs index faa4f3ef..49e1aa3b 100644 --- a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs @@ -1,14 +1,14 @@ -import { describe, expect, it } from "@jest/globals"; +import { describe, expect, test } from "@jest/globals"; import axios from "axios"; import { LOCAL_API_URL } from "../testHelpers.mjs"; const API_URL = `${LOCAL_API_URL}/patient/collaborator/`; -describe("Collaborator Handler", () => { +describe("Collaborator PUT endpoint", () => { const collaboratorId = 2; const fakeCollaboratorId = 9999; - it("should return 403 if no ID is provided", async () => { + test("should return 403 if no ID is provided", async () => { try { await axios.get(API_URL); // Petición GET sin ID } catch (error) { @@ -16,7 +16,7 @@ describe("Collaborator Handler", () => { } }); - it("should return a collaborator", async () => { + test("should return a collaborator", async () => { const response = await axios.get(API_URL + collaboratorId); expect(response).toBeDefined(); @@ -29,7 +29,7 @@ describe("Collaborator Handler", () => { expect(collaborator.patientId).toBe(2); }); - it("should not find a collaborator", async () => { + test("should not find a collaborator", async () => { try { await axios.get(API_URL + fakeCollaboratorId); } catch (error) { diff --git a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs index e91a993b..59f50bb2 100644 --- a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs +++ b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs @@ -1,45 +1,19 @@ import { getPgClient } from "db-conn"; import { logger, withRequest } from "logging"; -import { createResponse } from "utils"; - -// Funciones de mapeo -function mapToAPICollaborator(dbCollaborator) { - const { codigo: code, area, id_paciente: idPatient } = dbCollaborator; - - return { - code, - area, - idPatient, - }; -} - -function mapToDbCollaborator(apiCollaborator) { - const { code: codigo, area, idPatient: id_paciente } = apiCollaborator; - - return { - codigo, - area, - id_paciente, - }; -} +import { createResponse, mapToAPICollaboratorInfo, mapToDBCollaboratorInfo } from "utils/index.mjs"; export const updateCollaboratorHandler = async (event, context) => { withRequest(event, context); - logger.info({ event }, "Event received:"); + const responseBuilder = createResponse().addCORSHeaders("PUT"); if (event.httpMethod !== "PUT") { - throw new Error( - `updateCollaboratorHandler solo acepta el método PUT, intentaste: ${event.httpMethod}`, - ); + return responseBuilder.setStatusCode(405).setBody({error: "Method Not Allowed"}).build(); } - const apiCollaboratorData = JSON.parse(event.body); - logger.info({ apiCollaboratorData }, "Parsed API Collaborator Data:"); - - const collaboratorData = mapToDbCollaborator(apiCollaboratorData); - logger.info({ collaboratorData }, "Mapped DB Collaborator Data:"); - + /** @type {import("utils/index.mjs").APICollaborator} */ + const collaboratorData = JSON.parse(event.body); + logger.info({ collaboratorData }, "Parsed API Collaborator Data:"); logger.info(process.env, "Las variables de entorno son:"); let client; @@ -54,54 +28,65 @@ export const updateCollaboratorHandler = async (event, context) => { "Actualizando datos del colaborador en la base de datos...", ); - if (!collaboratorData.codigo) { - throw new Error("Código es requerido."); + if (!collaboratorData.code) { + logger.error("No code provided!"); + return responseBuilder.setStatusCode(400).setBody({error: "Invalid input: Missing or empty required fields."}).build() + } + + if (!collaboratorData.idPatient) { + logger.error("No patientId provided!"); + return responseBuilder.setStatusCode(400).setBody({error: "Invalid input: Missing or empty required fields."}).build() } const query = ` - UPDATE colaborador - SET - area = COALESCE($2, area), - id_paciente = COALESCE($3, id_paciente) - WHERE codigo = $1 - RETURNING * - `; + INSERT INTO colaborador (id_paciente, codigo, area) + VALUES ($1, $2, $3) + ON CONFLICT (id_paciente) DO UPDATE + SET codigo = COALESCE(EXCLUDED.codigo, colaborador.codigo), + area = COALESCE(EXCLUDED.area, colaborador.area) + RETURNING *; + `; const values = [ - collaboratorData.codigo, + collaboratorData.idPatient || null, + collaboratorData.code, collaboratorData.area || null, - collaboratorData.id_paciente || null, ]; - logger.info({ query, values }, "Consulta SQL y valores:"); - + logger.info({ query, values }, "Inserting/Updating values in DB..."); const result = await client.query(query, values); - logger.info({ result }, "Query result:"); + logger.info("Done inserting/updating!"); if (result.rowCount === 0) { - throw new Error( - "No se encontraron registros con el código proporcionado.", - ); + logger.error("No value was inserted/updated in the DB!"); + return responseBuilder + .setStatusCode(404) + .setBody({ + message: "Failed to insert or update traumatologic history.", + }) + .build(); } const updatedCollaborator = result.rows[0]; - logger.info({ updatedCollaborator }, "Updated Collaborator Data:"); - - const apiUpdatedCollaborator = mapToAPICollaborator(updatedCollaborator); + const apiUpdatedCollaborator = mapToAPICollaboratorInfo(updatedCollaborator); + logger.info({apiUpdatedCollaborator}, "Datos del colaborador actualizados exitosamente."); - logger.info("Datos del colaborador actualizados exitosamente."); - - return createResponse() + return responseBuilder .setStatusCode(200) - .addCORSHeaders() .setBody(apiUpdatedCollaborator) .build(); } catch (error) { - logger.error(error, "Error querying database:"); + logger.error({error}, "Error querying database:"); await client?.end(); - return createResponse() +if (error.code === "23503") { + return responseBuilder + .setStatusCode(404) + .setBody({ error: "Patient not found with the provided ID." }) + .build(); + } + + return responseBuilder .setStatusCode(500) - .addCORSHeaders() .setBody({ error: "Internal Server Error" }) .build(); } From bfd7a768cb7d931d4919a0f4e5a55b701d45fe2c Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Thu, 22 Aug 2024 21:47:01 -0600 Subject: [PATCH 02/27] chore: Formatting and linting --- .../layers/utils/utils/defaultValues.mjs | 1 - sanitas_backend/layers/utils/utils/index.mjs | 14 ++++----- .../update-collaborator.mjs | 29 ++++++++++++++----- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/sanitas_backend/layers/utils/utils/defaultValues.mjs b/sanitas_backend/layers/utils/utils/defaultValues.mjs index 058ee458..8ba7f6dd 100644 --- a/sanitas_backend/layers/utils/utils/defaultValues.mjs +++ b/sanitas_backend/layers/utils/utils/defaultValues.mjs @@ -349,4 +349,3 @@ export const genDefaultPsychiatricHistory = () => ({ data: { ill: "", medication: "", dose: "", frecuency: "", ube: false }, }, }); - diff --git a/sanitas_backend/layers/utils/utils/index.mjs b/sanitas_backend/layers/utils/utils/index.mjs index a728d19b..cd13a128 100644 --- a/sanitas_backend/layers/utils/utils/index.mjs +++ b/sanitas_backend/layers/utils/utils/index.mjs @@ -245,7 +245,7 @@ export function mapToAPIStudentInfo(dbStudentInfo) { * @returns {APICollaborator} The collaborator object the API must return. */ export function mapToAPICollaboratorInfo(dbCollaborator) { - const { codigo: code, area, id_paciente: idPatient } = dbCollaborator; + const { codigo: code, area, id_paciente: idPatient } = dbCollaborator; return { code, area, @@ -254,13 +254,13 @@ export function mapToAPICollaboratorInfo(dbCollaborator) { } /** - * Maps an APICollaborator into a DBCollaborator - * @param {APICollaborator} apiCollaborator - * @returns {DBCollaborator} - */ + * Maps an APICollaborator into a DBCollaborator + * @param {APICollaborator} apiCollaborator + * @returns {DBCollaborator} + */ export function mapToDBCollaborator(apiCollaborator) { - const {code: codigo, area, idPatient: id_paciente} = apiCollaborator; - return {codigo, area, id_paciente} + const { code: codigo, area, idPatient: id_paciente } = apiCollaborator; + return { codigo, area, id_paciente }; } /** diff --git a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs index 59f50bb2..673166ca 100644 --- a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs +++ b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs @@ -1,6 +1,6 @@ import { getPgClient } from "db-conn"; import { logger, withRequest } from "logging"; -import { createResponse, mapToAPICollaboratorInfo, mapToDBCollaboratorInfo } from "utils/index.mjs"; +import { createResponse, mapToAPICollaboratorInfo } from "utils/index.mjs"; export const updateCollaboratorHandler = async (event, context) => { withRequest(event, context); @@ -8,7 +8,10 @@ export const updateCollaboratorHandler = async (event, context) => { const responseBuilder = createResponse().addCORSHeaders("PUT"); if (event.httpMethod !== "PUT") { - return responseBuilder.setStatusCode(405).setBody({error: "Method Not Allowed"}).build(); + return responseBuilder + .setStatusCode(405) + .setBody({ error: "Method Not Allowed" }) + .build(); } /** @type {import("utils/index.mjs").APICollaborator} */ @@ -30,12 +33,18 @@ export const updateCollaboratorHandler = async (event, context) => { if (!collaboratorData.code) { logger.error("No code provided!"); - return responseBuilder.setStatusCode(400).setBody({error: "Invalid input: Missing or empty required fields."}).build() + return responseBuilder + .setStatusCode(400) + .setBody({ error: "Invalid input: Missing or empty required fields." }) + .build(); } if (!collaboratorData.idPatient) { logger.error("No patientId provided!"); - return responseBuilder.setStatusCode(400).setBody({error: "Invalid input: Missing or empty required fields."}).build() + return responseBuilder + .setStatusCode(400) + .setBody({ error: "Invalid input: Missing or empty required fields." }) + .build(); } const query = ` @@ -67,18 +76,22 @@ export const updateCollaboratorHandler = async (event, context) => { } const updatedCollaborator = result.rows[0]; - const apiUpdatedCollaborator = mapToAPICollaboratorInfo(updatedCollaborator); - logger.info({apiUpdatedCollaborator}, "Datos del colaborador actualizados exitosamente."); + const apiUpdatedCollaborator = + mapToAPICollaboratorInfo(updatedCollaborator); + logger.info( + { apiUpdatedCollaborator }, + "Datos del colaborador actualizados exitosamente.", + ); return responseBuilder .setStatusCode(200) .setBody(apiUpdatedCollaborator) .build(); } catch (error) { - logger.error({error}, "Error querying database:"); + logger.error({ error }, "Error querying database:"); await client?.end(); -if (error.code === "23503") { + if (error.code === "23503") { return responseBuilder .setStatusCode(404) .setBody({ error: "Patient not found with the provided ID." }) From 2f71995043588ad500923166c0157cdd3169aa3b Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Thu, 22 Aug 2024 23:31:02 -0600 Subject: [PATCH 03/27] feat: Added security checks to update collaborator data --- .../update-collaborator.integration.test.mjs | 96 ++++++++++++++----- .../update-collaborator.mjs | 48 +++++++++- 2 files changed, 117 insertions(+), 27 deletions(-) diff --git a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs index 49e1aa3b..c503a1ad 100644 --- a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs @@ -1,39 +1,87 @@ import { describe, expect, test } from "@jest/globals"; import axios from "axios"; -import { LOCAL_API_URL } from "../testHelpers.mjs"; +import { + createAuthorizationHeader, + createDoctorJWT, + createInvalidJWT, + createPatientJWT, + LOCAL_API_URL, +} from "../testHelpers.mjs"; const API_URL = `${LOCAL_API_URL}/patient/collaborator/`; -describe("Collaborator PUT endpoint", () => { - const collaboratorId = 2; - const fakeCollaboratorId = 9999; - - test("should return 403 if no ID is provided", async () => { - try { - await axios.get(API_URL); // Petición GET sin ID - } catch (error) { - expect(error.response.status).toBe(403); - } - }); +/** + * Creates a valid payload for this endpoint. + * @param {number} idPatient + * @returns {import("utils/index.mjs").APICollaborator} + */ +function generateValidPayload(idPatient) { + return { + idPatient, + code: "C002", + area: "Computación", + }; +} - test("should return a collaborator", async () => { - const response = await axios.get(API_URL + collaboratorId); +describe("Collaborator PUT endpoint", () => { + test("can update collaborator data", async () => { + const payload = generateValidPayload(1); + const headers = createAuthorizationHeader(createDoctorJWT()); + const response = await axios.put(API_URL, payload, { headers }); - expect(response).toBeDefined(); expect(response.status).toBe(200); const collaborator = response.data; - expect(collaborator).toBeDefined(); - expect(collaborator.code).toBe("C001"); - expect(collaborator.area).toBe("Administración"); - expect(collaborator.patientId).toBe(2); + expect(collaborator.idPatient).toBe(1); + expect(collaborator.code).toBe(payload.code); + expect(collaborator.area).toBe(payload.area); }); - test("should not find a collaborator", async () => { - try { - await axios.get(API_URL + fakeCollaboratorId); - } catch (error) { - expect(error.response.status).toBe(404); + test("fails with nonexistent patient id", async () => { + const payload = generateValidPayload(99999); + payload.code = "CU004"; + const headers = createAuthorizationHeader(createDoctorJWT()); + const response = await axios.put(API_URL, payload, { + headers, + validateStatus: () => true, + }); + + if (response.status !== 200) { + console.log(response.data); } + expect(response.status).toBe(400); + + const responseBody = response.data; + expect(responseBody.error).toEqual( + "Patient not found with the provided ID.", + ); + }); + + test("a patient can't call the endpoint", async () => { + const payload = generateValidPayload(1); + const patientHeaders = createAuthorizationHeader(createPatientJWT()); + + const response = await axios.put(API_URL, payload, { + headers: patientHeaders, + validateStatus: () => true, + }); + + expect(response.status).toBe(401); + expect(response.data).toEqual({ + error: "Unauthorized, you're not a doctor!", + }); + }); + + test("can't be called by a malformed JWT", async () => { + const payload = generateValidPayload(1); + const invalidAuthorization = createAuthorizationHeader(createInvalidJWT()); + + const response = await axios.put(API_URL, payload, { + headers: invalidAuthorization, + validateStatus: () => true, + }); + + expect(response.status).toBe(400); + expect(response.data).toEqual({ error: "JWT couldn't be parsed" }); }); }); diff --git a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs index 673166ca..994d53b7 100644 --- a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs +++ b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs @@ -1,6 +1,10 @@ -import { getPgClient } from "db-conn"; +import { getPgClient, isDoctor } from "db-conn"; import { logger, withRequest } from "logging"; -import { createResponse, mapToAPICollaboratorInfo } from "utils/index.mjs"; +import { + createResponse, + decodeJWT, + mapToAPICollaboratorInfo, +} from "utils/index.mjs"; export const updateCollaboratorHandler = async (event, context) => { withRequest(event, context); @@ -14,6 +18,21 @@ export const updateCollaboratorHandler = async (event, context) => { .build(); } + logger.info({ headers: event.headers }, "Received headers..."); + const jwt = event.headers.Authorization; + + logger.info({ jwt }, "Parsing JWT..."); + const tokenInfo = decodeJWT(jwt); + if (tokenInfo.error) { + logger.error({ error: tokenInfo.error }, "JWT couldn't be parsed!"); + return responseBuilder + .setStatusCode(400) + .setBody({ error: "JWT couldn't be parsed" }) + .build(); + } + const { email } = tokenInfo; + logger.info({ tokenInfo }, "JWT Parsed!"); + /** @type {import("utils/index.mjs").APICollaborator} */ const collaboratorData = JSON.parse(event.body); logger.info({ collaboratorData }, "Parsed API Collaborator Data:"); @@ -25,6 +44,22 @@ export const updateCollaboratorHandler = async (event, context) => { logger.info(url, "Conectando a la base de datos..."); client = getPgClient(url); await client.connect(); + logger.info("Connected!"); + + const itsDoctor = await isDoctor(client, email); + if (itsDoctor.error) { + const msg = "An error occurred while trying to check if user is doctor!"; + logger.error({ error: itsDoctor.error }, msg); + return responseBuilder.setStatusCode(500).setBody({ error: msg }).build(); + } + + if (!itsDoctor) { + const msg = "Unauthorized, you're not a doctor!"; + const body = { error: msg }; + logger.error(body, msg); + return responseBuilder.setStatusCode(401).setBody(body).build(); + } + logger.info(`${email} is a doctor!`); logger.info( collaboratorData, @@ -93,11 +128,18 @@ export const updateCollaboratorHandler = async (event, context) => { if (error.code === "23503") { return responseBuilder - .setStatusCode(404) + .setStatusCode(400) .setBody({ error: "Patient not found with the provided ID." }) .build(); } + if (error.code === "23505") { + return responseBuilder + .setStatusCode(404) + .setBody({ error: "Collaborator code already exists!" }) + .build(); + } + return responseBuilder .setStatusCode(500) .setBody({ error: "Internal Server Error" }) From 59f6d370280ae8d64e95c539dcf8dbd85fc06ebf Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Fri, 23 Aug 2024 11:16:18 -0600 Subject: [PATCH 04/27] fix: update collaborator and student data --- database/tables.sql | 2 +- .../update-collaborator.integration.test.mjs | 25 ++++++- .../update-collaborator.mjs | 8 ++- .../update-patient.integration.test.mjs | 4 +- .../update-student-data.integration.test.mjs | 68 ++++++++----------- .../UpdateStudentData/update-student-data.mjs | 26 +++++-- sanitas_backend/src/handlers/testHelpers.mjs | 9 +++ 7 files changed, 89 insertions(+), 53 deletions(-) diff --git a/database/tables.sql b/database/tables.sql index 39bbce51..7794c3cc 100644 --- a/database/tables.sql +++ b/database/tables.sql @@ -39,7 +39,7 @@ COMMENT ON TABLE DOCTOR IS CREATE TABLE ESTUDIANTE ( - CARNET VARCHAR(20), + CARNET VARCHAR(20) PRIMARY KEY NOT NULL, CARRERA VARCHAR(50), ID_PACIENTE INTEGER NOT NULL UNIQUE, FOREIGN KEY (ID_PACIENTE) REFERENCES PACIENTE (ID) diff --git a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs index c503a1ad..3e81622d 100644 --- a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.integration.test.mjs @@ -46,10 +46,10 @@ describe("Collaborator PUT endpoint", () => { validateStatus: () => true, }); - if (response.status !== 200) { + if (response.status !== 404) { console.log(response.data); } - expect(response.status).toBe(400); + expect(response.status).toBe(404); const responseBody = response.data; expect(responseBody.error).toEqual( @@ -57,6 +57,27 @@ describe("Collaborator PUT endpoint", () => { ); }); + test("Can't repeat collaborator code two times", async () => { + const headers = createAuthorizationHeader(createDoctorJWT()); + const payload = generateValidPayload(1); + payload.code = "C0876"; + + await axios.put(API_URL, payload, { + headers, + }); + + payload.idPatient = 2; + const response = await axios.put(API_URL, payload, { + headers, + validateStatus: () => true, + }); + + expect(response.status).toEqual(400); + expect(response.data).toEqual({ + error: "Collaborator code already exists!", + }); + }); + test("a patient can't call the endpoint", async () => { const payload = generateValidPayload(1); const patientHeaders = createAuthorizationHeader(createPatientJWT()); diff --git a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs index 994d53b7..467b3b03 100644 --- a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs +++ b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs @@ -124,18 +124,17 @@ export const updateCollaboratorHandler = async (event, context) => { .build(); } catch (error) { logger.error({ error }, "Error querying database:"); - await client?.end(); if (error.code === "23503") { return responseBuilder - .setStatusCode(400) + .setStatusCode(404) .setBody({ error: "Patient not found with the provided ID." }) .build(); } if (error.code === "23505") { return responseBuilder - .setStatusCode(404) + .setStatusCode(400) .setBody({ error: "Collaborator code already exists!" }) .build(); } @@ -144,5 +143,8 @@ export const updateCollaboratorHandler = async (event, context) => { .setStatusCode(500) .setBody({ error: "Internal Server Error" }) .build(); + } finally { + client?.end(); + logger.info("Database connection closed!"); } }; diff --git a/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs b/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs index 3a0e9e67..6fc71043 100644 --- a/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs @@ -71,9 +71,7 @@ describe("Update Patient integration tests", () => { // Verificar que el error sea el esperado expect(response.status).toBe(400); - expect(response.data.error).toBe( - "No se encontraron registros con el ID proporcionado.", - ); + expect(response.data.error).toBe("No patient with the given ID found!"); }); test("a patient can't call the endpoint", async () => { diff --git a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs index 1d6bd58c..08b5c6e5 100644 --- a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs @@ -1,7 +1,10 @@ import { beforeEach, describe, expect, test } from "@jest/globals"; import axios from "axios"; import { + createAuthorizationHeader, + createDoctorJWT, createTestPatient, + generateRandomCarnet, generateUniqueCUI, LOCAL_API_URL, updateStudentInfo, @@ -9,6 +12,14 @@ import { const API_URL = `${LOCAL_API_URL}patient/student`; +function generateValidUpdate(patientId) { + return { + patientId, + carnet: generateRandomCarnet(), + career: "Lic. Computación", + }; +} + describe("Update patient student data integration tests", () => { /** @type {number} */ let patientId; @@ -27,61 +38,42 @@ describe("Update patient student data integration tests", () => { }); test("Normal case: Actualizar datos de un paciente existente", async () => { - const payload = { + const payload = generateValidUpdate(patientId); + const received = await updateStudentInfo( patientId, - carnet: "22386", - career: "Lic. Computación", - }; - - const received = await updateStudentInfo(patientId); + payload.carnet, + payload.career, + ); expect(received.patientId).toBe(patientId); expect(received.carnet).toBe(payload.carnet); expect(received.career).toBe(payload.career); }); - test("Actualizar solamente carnet", async () => { - const payload = { - patientId, - carnet: "22386", - }; - - const response = await axios.put(API_URL, payload); + test("Can't repeat student carnet two times", async () => { + const patient2Id = await createTestPatient(); - expect(response.status).toBe(200); + const headers = createAuthorizationHeader(createDoctorJWT()); + const payload = generateValidUpdate(patientId); + await axios.put(API_URL, payload, { headers }); - const { data: received } = response; - expect(received.carnet).toBe(payload.carnet); - expect(received.career).toBeNull(); - }); - - test("Actualizar solamente carrera", async () => { - const payload = { - patientId, - career: "Lic. Química", - }; - - const response = await axios.put(API_URL, payload); - - expect(response.status).toBe(200); + payload.patientId = patient2Id; + const response = await axios.put(API_URL, payload, { + headers, + validateStatus: () => true, + }); - const { data: received } = response; - expect(received.career).toBe(payload.career); - expect(received.carnet).toBeNull(); + expect(response.status).toEqual(400); + expect(response.data.error).toEqual("Student carnet already exists!"); }); test("Falla al no encontrar la ID", async () => { - const payload = { - patientId: 99999999, - carnet: "22386", - career: "22386", - }; - + const payload = generateValidUpdate(99999999); const response = await axios.put(API_URL, payload, { validateStatus: () => true, }); - expect(response.status).toBe(400); + expect(response.status).toBe(404); expect(response.data.error).toBe("No patient with the given ID found!"); }); }); diff --git a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.mjs b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.mjs index 44f23d27..bd0e2abc 100644 --- a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.mjs +++ b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.mjs @@ -1,6 +1,6 @@ import { getPgClient } from "db-conn"; import { logger, withRequest } from "logging"; -import { createResponse, mapToAPIStudentInfo } from "utils"; +import { createResponse, mapToAPIStudentInfo } from "utils/index.mjs"; /** * @param {import('aws-lambda').APIGatewayProxyEvent} event @@ -33,6 +33,14 @@ export const handler = async (event, context) => { .build(); } + if (!carnet) { + logger.error("No student carnet provided!"); + return responseBuilder + .setStatusCode(400) + .setBody({ error: "No student carnet was given!" }) + .build(); + } + let client; try { const url = process.env.POSTGRES_URL; @@ -63,18 +71,24 @@ export const handler = async (event, context) => { .setBody(mapToAPIStudentInfo(studentData)) .build(); } catch (error) { - const invalidIdRegex = /Key \(.*\)=\(.*\) is not present in table ".*"\./; - const isInvalidIdError = invalidIdRegex.test(error.detail); - logger.error({ error, isInvalidIdError }, "Checking error type..."); + logger.error({ error }, "Error querying database:"); - if (isInvalidIdError) { + if (error.code === "23503") { logger.error("A patient with the given ID doesn't exists!"); return responseBuilder - .setStatusCode(400) + .setStatusCode(404) .setBody({ error: "No patient with the given ID found!" }) .build(); } + if (error.code === "23505") { + logger.error("A student with the same carnet already exsits!"); + return responseBuilder + .setStatusCode(400) + .setBody({ error: "Student carnet already exists!" }) + .build(); + } + logger.error(error, "An error occurred!"); return responseBuilder .setStatusCode(500) diff --git a/sanitas_backend/src/handlers/testHelpers.mjs b/sanitas_backend/src/handlers/testHelpers.mjs index 2eef0013..9e46bab5 100644 --- a/sanitas_backend/src/handlers/testHelpers.mjs +++ b/sanitas_backend/src/handlers/testHelpers.mjs @@ -34,6 +34,15 @@ export const generateUniqueCUI = () => { return `${timestamp}${randomNum}`; }; +/** + * @returns {string} The randomly generated student carnet + */ +export const generateRandomCarnet = () => { + const timestamp = Date.now(); + const randomNum = Math.floor(Math.random() * 100); + return `${randomNum}${timestamp}`.slice(0, 10); +}; + /** * Creates an Authorization header for the axios library. * @param {string} jwt - The JWT token to use for authorization. From bacf9b6d50a131660548cede9cb239b07e1f4e91 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Fri, 23 Aug 2024 11:29:24 -0600 Subject: [PATCH 05/27] fix: tests --- .../get-collaborator.integration.test.mjs | 2 +- .../UpdatePatient/update-patient.integration.test.mjs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sanitas_backend/src/handlers/GetGeneralCollaboratorInfo/get-collaborator.integration.test.mjs b/sanitas_backend/src/handlers/GetGeneralCollaboratorInfo/get-collaborator.integration.test.mjs index a6fb9144..9b38aec4 100644 --- a/sanitas_backend/src/handlers/GetGeneralCollaboratorInfo/get-collaborator.integration.test.mjs +++ b/sanitas_backend/src/handlers/GetGeneralCollaboratorInfo/get-collaborator.integration.test.mjs @@ -26,7 +26,7 @@ describe("Collaborator Handler", () => { expect(collaborator).toBeDefined(); expect(collaborator.code).toBe("C001"); expect(collaborator.area).toBe("Administración"); - expect(collaborator.patientId).toBe(2); + expect(collaborator.idPatient).toBe(2); }); it("should return default data", async () => { diff --git a/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs b/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs index 6fc71043..3a0e9e67 100644 --- a/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs @@ -71,7 +71,9 @@ describe("Update Patient integration tests", () => { // Verificar que el error sea el esperado expect(response.status).toBe(400); - expect(response.data.error).toBe("No patient with the given ID found!"); + expect(response.data.error).toBe( + "No se encontraron registros con el ID proporcionado.", + ); }); test("a patient can't call the endpoint", async () => { From adfef55835f8bec1b07ebbf0e6e2250177551932 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Fri, 23 Aug 2024 14:37:49 -0600 Subject: [PATCH 06/27] fix: update patient redundancy --- .../handlers/UpdatePatient/update-patient.mjs | 84 ++++--------------- 1 file changed, 18 insertions(+), 66 deletions(-) diff --git a/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs b/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs index 4346ec16..ad5339aa 100644 --- a/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs +++ b/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs @@ -1,52 +1,6 @@ import { getPgClient, isDoctor } from "db-conn"; import { logger, withRequest } from "logging"; -import { mapToAPIPatient } from "utils"; -import { createResponse, decodeJWT } from "utils/index.mjs"; - -function mapToDbPatient(apiPatient) { - const { - id, - cui, - isWoman: es_mujer, - email: correo, - names: nombres, - lastNames: apellidos, - - contactName1: nombre_contacto1, - contactKinship1: parentesco_contacto1, - contactPhone1: telefono_contacto1, - - contactName2: nombre_contacto2, - contactKinship2: parentesco_contacto2, - contactPhone2: telefono_contacto2, - - bloodType: tipo_sangre, - address: direccion, - insuranceId: id_seguro, - birthdate: fecha_nacimiento, - phone: telefono, - } = apiPatient; - - return { - id, - cui, - es_mujer, - correo, - nombres, - apellidos, - nombre_contacto1, - parentesco_contacto1, - telefono_contacto1, - nombre_contacto2, - parentesco_contacto2, - telefono_contacto2, - tipo_sangre, - direccion, - id_seguro, - fecha_nacimiento, - telefono, - }; -} +import { createResponse, decodeJWT, mapToAPIPatient } from "utils/index.mjs"; // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: The function isn't that complex, it's just really large. export const updatePatientHandler = async (event, context) => { @@ -74,8 +28,8 @@ export const updatePatientHandler = async (event, context) => { const { email } = tokenInfo; logger.info({ tokenInfo }, "JWT Parsed!"); - const apiPatientData = JSON.parse(event.body); - const patientData = mapToDbPatient(apiPatientData); + /** @type {import("utils/index.mjs").APIPatient} */ + const patientData = JSON.parse(event.body); logger.info(process.env, "Las variables de entorno son:"); let client; @@ -138,24 +92,22 @@ export const updatePatientHandler = async (event, context) => { const values = [ patientData.id, - patientData.nombres || null, - patientData.apellidos || null, - patientData.nombre_contacto1 || null, - patientData.parentesco_contacto1 || null, - patientData.telefono_contacto1 || null, - patientData.nombre_contacto2 || null, - patientData.parentesco_contacto2 || null, - patientData.telefono_contacto2 || null, - patientData.tipo_sangre || null, - patientData.direccion || null, - patientData.id_seguro || null, - patientData.fecha_nacimiento - ? new Date(patientData.fecha_nacimiento) - : null, - patientData.telefono || null, + patientData.names || null, + patientData.lastNames || null, + patientData.contactName1 || null, + patientData.contactKinship1 || null, + patientData.contactPhone1 || null, + patientData.contactName2 || null, + patientData.contactKinship2 || null, + patientData.contactPhone2 || null, + patientData.bloodType || null, + patientData.address || null, + patientData.insuranceId || null, + patientData.birthdate ? new Date(patientData.birthdate) : null, + patientData.phone || null, patientData.cui || null, - patientData.correo || null, - patientData.es_mujer !== null ? patientData.es_mujer : null, + patientData.email || null, + patientData.isWoman !== null ? patientData.isWoman : null, ]; logger.info({ query, values }, "Consulta SQL y valores:"); From 6a49a32d61cfaae801e524cd753b21f47a90c2a8 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Fri, 23 Aug 2024 14:55:23 -0600 Subject: [PATCH 07/27] fix: Seguros field --- database/inserts.sql | 4 ++-- database/tables.sql | 11 +++-------- sanitas_backend/layers/utils/utils/index.mjs | 6 +++--- .../src/handlers/UpdatePatient/update-patient.mjs | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/database/inserts.sql b/database/inserts.sql index ad5013e3..df06f355 100644 --- a/database/inserts.sql +++ b/database/inserts.sql @@ -43,7 +43,7 @@ INSERT INTO PACIENTE ( '987650123', 'O+', 'Calle Falsa 123, Ciudad', - 1, + 'El Roble', '1990-01-01', '1234567890' ), @@ -61,7 +61,7 @@ INSERT INTO PACIENTE ( '876540123', 'A-', 'Avenida Siempre Viva 456, Ciudad', - 2, + 'IGSS', '1992-02-02', '2345678901' ); diff --git a/database/tables.sql b/database/tables.sql index 7794c3cc..de4ae498 100644 --- a/database/tables.sql +++ b/database/tables.sql @@ -3,13 +3,6 @@ CREATE TABLE USUARIO ( TIPO VARCHAR(20) NOT NULL ); - -CREATE TABLE SEGURO ( - ID SERIAL PRIMARY KEY NOT NULL, - NOMBRE VARCHAR(50) NOT NULL, - ESTADO_ACTIVO BOOLEAN NOT NULL -); - CREATE TABLE PACIENTE ( ID SERIAL PRIMARY KEY, CUI VARCHAR(24) UNIQUE NOT NULL, @@ -25,11 +18,13 @@ CREATE TABLE PACIENTE ( TELEFONO_CONTACTO2 VARCHAR(20), TIPO_SANGRE VARCHAR(3), DIRECCION VARCHAR(100), - ID_SEGURO INTEGER, + SEGURO VARCHAR(30), FECHA_NACIMIENTO DATE NOT NULL, TELEFONO VARCHAR(20), FOREIGN KEY (ID_SEGURO) REFERENCES SEGURO (ID) ); +COMMENT ON TABLE PACIENTE IS +'This table is used to save general information about a patient.'; CREATE TABLE DOCTOR ( EMAIL VARCHAR(100) NOT NULL PRIMARY KEY diff --git a/sanitas_backend/layers/utils/utils/index.mjs b/sanitas_backend/layers/utils/utils/index.mjs index cd13a128..0af62e9b 100644 --- a/sanitas_backend/layers/utils/utils/index.mjs +++ b/sanitas_backend/layers/utils/utils/index.mjs @@ -57,7 +57,7 @@ export function decodeJWT(jwt) { * * @property {string|null} bloodType * @property {string|null} address - * @property {number | undefined} insuranceId + * @property {string | undefined} insurance * @property {string} birthdate * @property {string|null} phone */ @@ -100,7 +100,7 @@ export function mapToAPIPatient(dbPatient) { tipo_sangre: bloodType, direccion: address, - id_seguro: insuranceId, + seguro: insurance, fecha_nacimiento: birthdate, telefono: phone, } = dbPatient; @@ -123,7 +123,7 @@ export function mapToAPIPatient(dbPatient) { bloodType, address, - insuranceId, + insurance, birthdate, phone, }; diff --git a/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs b/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs index ad5339aa..fe4d657e 100644 --- a/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs +++ b/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs @@ -102,7 +102,7 @@ export const updatePatientHandler = async (event, context) => { patientData.contactPhone2 || null, patientData.bloodType || null, patientData.address || null, - patientData.insuranceId || null, + patientData.insurance || null, patientData.birthdate ? new Date(patientData.birthdate) : null, patientData.phone || null, patientData.cui || null, From 0799342d53aac512e598e9db4da9b5855f6a53cf Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Fri, 23 Aug 2024 16:01:43 -0600 Subject: [PATCH 08/27] fix: backend behaviour and insurance --- database/inserts.sql | 6 +----- database/tables.sql | 3 +-- sanitas_backend/layers/utils/utils/index.mjs | 8 ++++---- .../get-general-patient-info.integration.test.mjs | 2 +- .../UpdatePatient/update-patient.integration.test.mjs | 6 +++--- .../src/handlers/UpdatePatient/update-patient.mjs | 7 ++++--- .../src/views/UpdateGeneralInformationView/index.jsx | 11 ++++++----- .../UpdateGeneralInformationView/index.stories.jsx | 7 +++++++ wiki/mantenimiento/db/README.md | 8 +------- 9 files changed, 28 insertions(+), 30 deletions(-) diff --git a/database/inserts.sql b/database/inserts.sql index df06f355..c2e595d3 100644 --- a/database/inserts.sql +++ b/database/inserts.sql @@ -1,7 +1,3 @@ -INSERT INTO SEGURO (NOMBRE, ESTADO_ACTIVO) VALUES -('Seguro Vida', TRUE), -('Seguro Salud', TRUE); - INSERT INTO USUARIO (EMAIL, TIPO) VALUES ('admin@example.com', 'Administrador'), ('doctor1@example.com', 'Doctor'), @@ -25,7 +21,7 @@ INSERT INTO PACIENTE ( TELEFONO_CONTACTO2, TIPO_SANGRE, DIRECCION, - ID_SEGURO, + SEGURO, FECHA_NACIMIENTO, TELEFONO ) VALUES diff --git a/database/tables.sql b/database/tables.sql index de4ae498..d5a8fa14 100644 --- a/database/tables.sql +++ b/database/tables.sql @@ -20,8 +20,7 @@ CREATE TABLE PACIENTE ( DIRECCION VARCHAR(100), SEGURO VARCHAR(30), FECHA_NACIMIENTO DATE NOT NULL, - TELEFONO VARCHAR(20), - FOREIGN KEY (ID_SEGURO) REFERENCES SEGURO (ID) + TELEFONO VARCHAR(20) ); COMMENT ON TABLE PACIENTE IS 'This table is used to save general information about a patient.'; diff --git a/sanitas_backend/layers/utils/utils/index.mjs b/sanitas_backend/layers/utils/utils/index.mjs index 0af62e9b..dc3cbbd2 100644 --- a/sanitas_backend/layers/utils/utils/index.mjs +++ b/sanitas_backend/layers/utils/utils/index.mjs @@ -33,14 +33,14 @@ export function decodeJWT(jwt) { * * @property {string|null} tipo_sangre * @property {string|null} direccion - * @property {number | null} id_seguro + * @property {string | null} seguro * @property {string} fecha_nacimiento * @property {string|null} telefono */ /** * @typedef {Object} APIPatient - * @property {number} id + * @property {number} patientId * @property {string} cui * @property {boolean} isWoman * @property {string|null} email @@ -83,7 +83,7 @@ export function decodeJWT(jwt) { */ export function mapToAPIPatient(dbPatient) { const { - id, + id: patientId, cui, es_mujer: isWoman, correo: email, @@ -106,7 +106,7 @@ export function mapToAPIPatient(dbPatient) { } = dbPatient; return { - id, + patientId, cui, email, isWoman, diff --git a/sanitas_backend/src/handlers/GetGeneralPatientInfo/get-general-patient-info.integration.test.mjs b/sanitas_backend/src/handlers/GetGeneralPatientInfo/get-general-patient-info.integration.test.mjs index 838fa301..1aa340a2 100644 --- a/sanitas_backend/src/handlers/GetGeneralPatientInfo/get-general-patient-info.integration.test.mjs +++ b/sanitas_backend/src/handlers/GetGeneralPatientInfo/get-general-patient-info.integration.test.mjs @@ -25,7 +25,7 @@ describe("Get patient integration tests", () => { const user = response.data; expect(user).toBeDefined(); - expect(user.id).toBe(patientId); + expect(user.patientId).toBe(patientId); expect(user.cui).toBe(cui); expect(user.isWoman).toBe(false); expect(user.names).toBe("Flabio André"); diff --git a/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs b/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs index 3a0e9e67..2e20d8da 100644 --- a/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdatePatient/update-patient.integration.test.mjs @@ -13,7 +13,7 @@ const API_URL = `${LOCAL_API_URL}/patient/general`; function generateValidUpdate(patientId) { return { - id: patientId, + patientId, names: "Juan Actualizado", lastNames: "Pérez Actualizado", phone: "5556789", @@ -46,7 +46,7 @@ describe("Update Patient integration tests", () => { test("Actualizar datos de un paciente sin proporcionar ningún campo para actualizar", async () => { const patientData = { - id: patientId, + patientId, }; const response = await axios.put(API_URL, patientData, { @@ -60,7 +60,7 @@ describe("Update Patient integration tests", () => { test("Actualizar datos de un paciente con una ID inexistente (debería fallar)", async () => { const patientData = { - id: -1, + patientId: -1, names: "Nombre Nuevo", }; diff --git a/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs b/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs index fe4d657e..c3ec99b3 100644 --- a/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs +++ b/sanitas_backend/src/handlers/UpdatePatient/update-patient.mjs @@ -60,7 +60,7 @@ export const updatePatientHandler = async (event, context) => { "Actualizando datos del paciente en la base de datos...", ); - if (!patientData.id) { + if (!patientData.patientId) { return responseBuilder .setStatusCode(400) .setBody({ error: "ID es requerido" }) @@ -80,7 +80,7 @@ export const updatePatientHandler = async (event, context) => { telefono_contacto2 = COALESCE($9, telefono_contacto2), tipo_sangre = COALESCE($10, tipo_sangre), direccion = COALESCE($11, direccion), - id_seguro = COALESCE($12, id_seguro), + seguro = COALESCE($12, seguro), fecha_nacimiento = COALESCE($13, fecha_nacimiento), telefono = COALESCE($14, telefono), cui = COALESCE($15, cui), @@ -91,7 +91,7 @@ export const updatePatientHandler = async (event, context) => { `; const values = [ - patientData.id, + patientData.patientId, patientData.names || null, patientData.lastNames || null, patientData.contactName1 || null, @@ -115,6 +115,7 @@ export const updatePatientHandler = async (event, context) => { const result = await client.query(query, values); if (result.rowCount === 0) { + logger.error("No se encontraron registros con el ID proporcionado"); return responseBuilder .setStatusCode(400) .setBody({ diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index 1d8b0abd..cdebb083 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -28,7 +28,7 @@ import WrapPromise from "src/utils/promiseWrapper"; * @property {string|null} contactPhone2 * @property {string|null} bloodType * @property {string|null} address - * @property {number | undefined} insuranceId + * @property {string | undefined} insurance * @property {string} birthdate * @property {string|null} phone */ @@ -409,6 +409,7 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { const response = generalInformationResource.read(); + /** @type {[PatientInfo, (data: PatientInfo) => void]} */ const [patientData, setPatientData] = useState({ ...response.result, birthdate: formatDate(response.result?.birthdate), @@ -606,13 +607,13 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { disabled={!editMode} /> - +
- setPatientData({ ...patientData, insuranceId: e.target.value }) + setPatientData({ ...patientData, insurance: e.target.value }) } style={{ width: "18.75rem" }} disabled={!editMode} diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.stories.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.stories.jsx index b56ce385..f0847180 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.stories.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.stories.jsx @@ -19,6 +19,7 @@ export default { const examplePatientData = { id: 6969, + cui: 1234234568712, names: "Johnaaaa", lastNames: "Doee", isWoman: false, @@ -79,6 +80,9 @@ export const WithPatientData = { getGeneralPatientInformation: mockGetGeneralPatientInformation, getStudentPatientInformation: mockGetStudentPatientInformation, getCollaboratorInformation: mockGetCollaboratorInformation, + updateGeneralPatientInformation: async (a) => ({ result: a }), + updateStudentPatientInformation: async (a) => ({ result: a }), + updateCollaboratorInformation: async (a) => ({ result: a }), useStore: correctStore, sidebarConfig: { userInformation: { @@ -97,6 +101,9 @@ export const ErrorState = { getGeneralPatientInformation: mockGetGeneralPatientInformation, getStudentPatientInformation: mockGetStudentPatientInformation, getCollaboratorInformation: mockGetCollaboratorInformation, + updateGeneralPatientInformation: async () => ({ error: "MockError" }), + updateStudentPatientInformation: async () => ({ error: "MockError" }), + updateCollaboratorInformation: async () => ({ error: "MockError" }), useStore: incorrectStore, sidebarConfig: { userInformation: { diff --git a/wiki/mantenimiento/db/README.md b/wiki/mantenimiento/db/README.md index 144d6c36..88d06cb2 100644 --- a/wiki/mantenimiento/db/README.md +++ b/wiki/mantenimiento/db/README.md @@ -23,7 +23,7 @@ erDiagram varchar telefono_contacto2 varchar tipo_sangre varchar direccion - varchar id_seguro + varchar seguro date fecha_nacimiento varchar telefono } @@ -57,12 +57,6 @@ erDiagram serial id_consulta } - SEGURO { - serial id - varchar nombre - boolean estado_activo - } - ESTUDIANTE { varchar carnet varchar carrera From c6bf5bc5be757827e27b5767d8286b44f67dfb60 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Fri, 23 Aug 2024 22:24:00 -0600 Subject: [PATCH 09/27] fix: Removed zombi code --- .../UpdateGeneralInformationView/index.jsx | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index cdebb083..ac4df998 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -320,13 +320,6 @@ function UpdateColaboratorInformationSection({ * @returns {JSX.Element} */ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { - /** @type React.CSSProperties */ - const errorPStyles = { - fontFamily: fonts.textFont, - fontSize: fontSize.textSize, - color: colors.statusDenied, - }; - const GenInputStyle = (labelRow, labelColumn) => { const gridColumn = `${labelColumn} / ${labelColumn + 1}`; const gridRow = `${labelRow} / ${labelRow + 1}`; @@ -403,9 +396,7 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Ignoring complexity for this function const Hijo = () => { const [editMode, setEditMode] = useState(false); - const [updateError, setUpdateError] = useState(""); const [resourceUpdate, setResourceUpdate] = useState(null); - const [isLoading, setIsLoading] = useState(false); const response = generalInformationResource.read(); @@ -427,10 +418,10 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { } if (resourceUpdate !== null) { + setResourceUpdate(null); const response = resourceUpdate.read(); - setIsLoading(false); - setUpdateError(""); if (response.error) { + toast.dismiss(); toast.error( `Lo sentimos! Ha ocurrido un error al actualizar los datos! ${response.error.toString()}`, ); @@ -442,7 +433,6 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { birthdate: formatDate(response.result.birthdate), }); } - setResourceUpdate(null); } const handleUpdatePatient = async () => { @@ -451,8 +441,6 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { return; } setEditMode(false); - setUpdateError(""); - setIsLoading(true); toast.dismiss(); // Clear existing toasts const updateInformationResource = WrapPromise(updateData(patientData)); setResourceUpdate(updateInformationResource); @@ -466,10 +454,6 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { setEditMode(false); }; - if (isLoading) { - return ; - } - return (
-

{updateError}

); }; From 7a385b77316cad661577cc8a69ace9f9c5432838 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Fri, 23 Aug 2024 23:21:31 -0600 Subject: [PATCH 10/27] feat: Added collapsable component --- .../src/components/Collapsable/index.jsx | 51 +++++++++++++++++++ .../components/Collapsable/index.stories.jsx | 13 +++++ 2 files changed, 64 insertions(+) create mode 100644 sanitas_frontend/src/components/Collapsable/index.jsx create mode 100644 sanitas_frontend/src/components/Collapsable/index.stories.jsx diff --git a/sanitas_frontend/src/components/Collapsable/index.jsx b/sanitas_frontend/src/components/Collapsable/index.jsx new file mode 100644 index 00000000..c6c07386 --- /dev/null +++ b/sanitas_frontend/src/components/Collapsable/index.jsx @@ -0,0 +1,51 @@ +import { useState } from "react"; +import { colors, fonts, fontSize } from "src/theme.mjs"; +import upCaret from "@tabler/icons/filled/caret-up.svg"; +import downCaret from "@tabler/icons/filled/caret-down.svg"; + +/** + * @typedef {Object} CollapsableProps + * @property {string} title + * @property {*} children - The components to render inside. + */ + +/** + * @param {CollapsableProps} props + */ +export default function Collapsable({ children, title }) { + const [isCollapsed, setIsCollapsed] = useState(); + + return ( +
+ + {isCollapsed ?
{children}
: null} +
+ ); +} diff --git a/sanitas_frontend/src/components/Collapsable/index.stories.jsx b/sanitas_frontend/src/components/Collapsable/index.stories.jsx new file mode 100644 index 00000000..65200841 --- /dev/null +++ b/sanitas_frontend/src/components/Collapsable/index.stories.jsx @@ -0,0 +1,13 @@ +import Collapsable from "."; + +export default { + title: "Components/Collapsable", + component: Collapsable, +}; + +export const Default = { + args: { + title: "Contacto 1", + children:

Hello

, + }, +}; From 1e5179a2c03aaf9d5376f752c29809c8f1ec0368 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Sat, 24 Aug 2024 18:42:09 -0600 Subject: [PATCH 11/27] fix: Endpoints --- flake.lock | 12 ++-- sanitas_backend/layers/utils/utils/index.mjs | 8 +-- .../get-collaborator.mjs | 4 +- .../get-general-patient-info.mjs | 2 +- .../get-general-student-info.mjs | 6 +- .../update-collaborator.mjs | 2 +- .../update-student-data.integration.test.mjs | 16 ++--- .../UpdateStudentData/update-student-data.mjs | 6 +- sanitas_frontend/src/dataLayer.mjs | 2 +- .../UpdateGeneralInformationView/index.jsx | 62 ++++--------------- 10 files changed, 41 insertions(+), 79 deletions(-) diff --git a/flake.lock b/flake.lock index 6e711b71..aad55ad8 100644 --- a/flake.lock +++ b/flake.lock @@ -41,11 +41,11 @@ "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1723158735, - "narHash": "sha256-+ttPzSzu8eKYuXnmb15qsLClUQV6J5WLj5mzWgsMYYs=", + "lastModified": 1723594027, + "narHash": "sha256-9Ti2LYVyfdiho5RfIkou6U6yhiZnVHAQNmcPzt7Otzs=", "owner": "ElrohirGT", "repo": "devenv", - "rev": "09321a82506f60125ae3fa0353fae6647da7c965", + "rev": "11d0fa9ee755691ff0db2e3199174b1a20f19b6a", "type": "github" }, "original": { @@ -319,11 +319,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1722813957, - "narHash": "sha256-IAoYyYnED7P8zrBFMnmp7ydaJfwTnwcnqxUElC1I26Y=", + "lastModified": 1724224976, + "narHash": "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=", "owner": "nixos", "repo": "nixpkgs", - "rev": "cb9a96f23c491c081b38eab96d22fa958043c9fa", + "rev": "c374d94f1536013ca8e92341b540eba4c22f9c62", "type": "github" }, "original": { diff --git a/sanitas_backend/layers/utils/utils/index.mjs b/sanitas_backend/layers/utils/utils/index.mjs index dc3cbbd2..cb0da613 100644 --- a/sanitas_backend/layers/utils/utils/index.mjs +++ b/sanitas_backend/layers/utils/utils/index.mjs @@ -83,7 +83,7 @@ export function decodeJWT(jwt) { */ export function mapToAPIPatient(dbPatient) { const { - id: patientId, + patientId, cui, es_mujer: isWoman, correo: email, @@ -205,7 +205,7 @@ export function createResponse() { /** * @typedef {Object} APIStudentInfo - * @property {string} patientId + * @property {string} idPatient * @property {string} carnet * @property {string} career */ @@ -216,10 +216,10 @@ export function createResponse() { * @returns {APIStudentInfo} The API formatted student information. */ export function mapToAPIStudentInfo(dbStudentInfo) { - const { id_paciente: patientId, carnet, carrera: career } = dbStudentInfo; + const { id_paciente: idPatient, carnet, carrera: career } = dbStudentInfo; return { - patientId, + idPatient, carnet, career, }; diff --git a/sanitas_backend/src/handlers/GetGeneralCollaboratorInfo/get-collaborator.mjs b/sanitas_backend/src/handlers/GetGeneralCollaboratorInfo/get-collaborator.mjs index 4d62a4a7..5d2bd278 100644 --- a/sanitas_backend/src/handlers/GetGeneralCollaboratorInfo/get-collaborator.mjs +++ b/sanitas_backend/src/handlers/GetGeneralCollaboratorInfo/get-collaborator.mjs @@ -1,6 +1,6 @@ import { getPgClient } from "db-conn"; import { logger, withRequest } from "logging"; -import { createResponse, mapToAPICollaboratorInfo } from "utils"; +import { createResponse, mapToAPICollaboratorInfo } from "utils/index.mjs"; /** * Get the collaborator information endpoint handler. @@ -52,7 +52,7 @@ export const getCollaboratorHandler = async (event, context) => { return createResponse() .setStatusCode(200) .addCORSHeaders() - .setBody({ patientId: id, code: "", area: "" }) + .setBody({ idPatient: id, code: "", area: "" }) .build(); } diff --git a/sanitas_backend/src/handlers/GetGeneralPatientInfo/get-general-patient-info.mjs b/sanitas_backend/src/handlers/GetGeneralPatientInfo/get-general-patient-info.mjs index fa5094e7..2da92891 100644 --- a/sanitas_backend/src/handlers/GetGeneralPatientInfo/get-general-patient-info.mjs +++ b/sanitas_backend/src/handlers/GetGeneralPatientInfo/get-general-patient-info.mjs @@ -1,6 +1,6 @@ import { getPgClient } from "db-conn"; import { logger, withRequest } from "logging"; -import { mapToAPIPatient } from "utils"; +import { mapToAPIPatient } from "utils/index.mjs"; /** * Get the general patient information endpoint handler. diff --git a/sanitas_backend/src/handlers/GetGeneralStudentInfo/get-general-student-info.mjs b/sanitas_backend/src/handlers/GetGeneralStudentInfo/get-general-student-info.mjs index 7e22bd0b..2e818dfa 100644 --- a/sanitas_backend/src/handlers/GetGeneralStudentInfo/get-general-student-info.mjs +++ b/sanitas_backend/src/handlers/GetGeneralStudentInfo/get-general-student-info.mjs @@ -1,6 +1,6 @@ import { getPgClient } from "db-conn"; import { logger, withRequest } from "logging"; -import { createResponse, mapToAPIStudentInfo } from "utils"; +import { createResponse, mapToAPIStudentInfo } from "utils/index.mjs"; /** * Get the student information endpoint handler. @@ -42,9 +42,9 @@ export const handler = async (event, context) => { logger.info(dbResponse, "Query done!"); if (dbResponse.rowCount === 0) { - /** @type {APIStudentInfo} */ + /** @type {import("utils/index.mjs").APIStudentInfo} */ const defaultStudentInfo = { - patientId: id, + idPatient: id, carnet: "", career: "", }; diff --git a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs index 467b3b03..f1027dbe 100644 --- a/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs +++ b/sanitas_backend/src/handlers/UpdateCollaborator/update-collaborator.mjs @@ -75,7 +75,7 @@ export const updateCollaboratorHandler = async (event, context) => { } if (!collaboratorData.idPatient) { - logger.error("No patientId provided!"); + logger.error("No idPatient provided!"); return responseBuilder .setStatusCode(400) .setBody({ error: "Invalid input: Missing or empty required fields." }) diff --git a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs index 08b5c6e5..1a546302 100644 --- a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs @@ -12,9 +12,9 @@ import { const API_URL = `${LOCAL_API_URL}patient/student`; -function generateValidUpdate(patientId) { +function generateValidUpdate(idPatient) { return { - patientId, + idPatient, carnet: generateRandomCarnet(), career: "Lic. Computación", }; @@ -22,7 +22,7 @@ function generateValidUpdate(patientId) { describe("Update patient student data integration tests", () => { /** @type {number} */ - let patientId; + let idPatient; let insertedPatientData; @@ -34,18 +34,18 @@ describe("Update patient student data integration tests", () => { isWoman: true, }; const { cui, names, lastNames, isWoman } = insertedPatientData; - patientId = await createTestPatient(cui, names, lastNames, isWoman); + idPatient = await createTestPatient(cui, names, lastNames, isWoman); }); test("Normal case: Actualizar datos de un paciente existente", async () => { - const payload = generateValidUpdate(patientId); + const payload = generateValidUpdate(idPatient); const received = await updateStudentInfo( - patientId, + idPatient, payload.carnet, payload.career, ); - expect(received.patientId).toBe(patientId); + expect(received.patientId).toBe(idPatient); expect(received.carnet).toBe(payload.carnet); expect(received.career).toBe(payload.career); }); @@ -54,7 +54,7 @@ describe("Update patient student data integration tests", () => { const patient2Id = await createTestPatient(); const headers = createAuthorizationHeader(createDoctorJWT()); - const payload = generateValidUpdate(patientId); + const payload = generateValidUpdate(idPatient); await axios.put(API_URL, payload, { headers }); payload.patientId = patient2Id; diff --git a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.mjs b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.mjs index bd0e2abc..ccfe3073 100644 --- a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.mjs +++ b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.mjs @@ -22,10 +22,10 @@ export const handler = async (event, context) => { const responseBuilder = createResponse().addCORSHeaders("PUT"); logger.info({ body: event.body }, "Parsing request..."); - const { patientId, carnet, career } = JSON.parse(event.body); + const { idPatient, carnet, career } = JSON.parse(event.body); logger.info("Request body parsed!"); - if (!patientId) { + if (!idPatient) { logger.error("No patient ID provided!"); return responseBuilder .setStatusCode(400) @@ -59,7 +59,7 @@ export const handler = async (event, context) => { carrera = COALESCE(EXCLUDED.carrera, estudiante.carrera) RETURNING *; `; - const params = [carnet, career, patientId]; + const params = [carnet, career, idPatient]; logger.info({ sql, params }, "Updating/inserting data on DB..."); const { rows } = await client.query(sql, params); diff --git a/sanitas_frontend/src/dataLayer.mjs b/sanitas_frontend/src/dataLayer.mjs index 97aed171..f3befc8e 100644 --- a/sanitas_frontend/src/dataLayer.mjs +++ b/sanitas_frontend/src/dataLayer.mjs @@ -270,7 +270,7 @@ export const updateGeneralPatientInformation = async (APIPatient) => { /** * @typedef {Object} APIStudentInformation - * @property {number} patientId + * @property {number} idPatient * @property {string} career * @property {string} carnet */ diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index ac4df998..0347896c 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -115,13 +115,6 @@ function UpdateColaboratorInformationSection({ getData, updateData, }) { - /** @type React.CSSProperties */ - const errorPStyles = { - fontFamily: fonts.textFont, - fontSize: fontSize.textSize, - color: colors.statusDenied, - }; - const GenInputStyle = (labelRow, labelColumn) => { const gridColumn = `${labelColumn} / ${labelColumn + 1}`; const gridRow = `${labelRow} / ${labelRow + 1}`; @@ -186,9 +179,7 @@ function UpdateColaboratorInformationSection({ const Hijo = () => { const [editMode, setEditMode] = useState(false); - const [updateError, setUpdateError] = useState(""); const [resourceUpdate, setResourceUpdate] = useState(null); - const [isLoading, setIsLoading] = useState(false); const response = collaboratorInformationResource.read(); @@ -197,11 +188,10 @@ function UpdateColaboratorInformationSection({ }); if (resourceUpdate !== null) { + setResourceUpdate(null); const response = resourceUpdate.read(); - setIsLoading(false); - setUpdateError(""); if (response.error) { - setUpdateError( + toast.error( `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${response.error.toString()}`, ); } else { @@ -209,7 +199,6 @@ function UpdateColaboratorInformationSection({ setPatientData(response.result || {}); toast.success("¡Información actualizada exitosamente!"); } - setResourceUpdate(null); } const handleUpdatePatient = async () => { @@ -220,7 +209,7 @@ function UpdateColaboratorInformationSection({ setPatientData(response.result || {}); toast.success("¡Información actualizada exitosamente!"); } catch (error) { - setUpdateError( + toast.error( `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${error.message}`, ); } @@ -231,10 +220,6 @@ function UpdateColaboratorInformationSection({ setEditMode(false); }; - if (isLoading) { - return ; - } - return (
-

{updateError}

); }; @@ -710,13 +694,6 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { * @param {UpdateStudentInformationSectionProps} props */ function UpdateStudentInformationSection({ patientId, getData, updateData }) { - /** @type React.CSSProperties */ - const errorPStyles = { - fontFamily: fonts.textFont, - fontSize: fontSize.textSize, - color: colors.statusDenied, - }; - const GenInputStyle = (labelRow, labelColumn) => { const gridColumn = `${labelColumn} / ${labelColumn + 1}`; const gridRow = `${labelRow} / ${labelRow + 1}`; @@ -765,9 +742,7 @@ function UpdateStudentInformationSection({ patientId, getData, updateData }) { const Hijo = () => { const [editMode, setEditMode] = useState(false); - const [updateError, setUpdateError] = useState(""); const [resourceUpdate, setResourceUpdate] = useState(null); - const [isLoading, setIsLoading] = useState(false); const response = studentInformationResource.read(); @@ -776,33 +751,25 @@ function UpdateStudentInformationSection({ patientId, getData, updateData }) { }); if (resourceUpdate !== null) { + setResourceUpdate(null); const response = resourceUpdate.read(); - setIsLoading(false); - setUpdateError(""); if (response.error) { - setUpdateError( + toast.dismiss(); + toast.error( `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${response.error.toString()}`, ); } else { setEditMode(false); setPatientData(response.result || {}); + toast.dismiss(); toast.success("¡Información actualizada exitosamente!"); } - setResourceUpdate(null); } const handleUpdatePatient = async () => { toast.info("Guardando datos..."); setEditMode(false); - try { - const response = await updateData(patientData); - setPatientData(response.result || {}); - toast.success("¡Información actualizada exitosamente!"); - } catch (error) { - setUpdateError( - `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${error.message}`, - ); - } + setResourceUpdate(WrapPromise(updateData(patientData))); }; const handleCancelEdit = () => { @@ -810,10 +777,6 @@ function UpdateStudentInformationSection({ patientId, getData, updateData }) { setEditMode(false); }; - if (isLoading) { - return ; - } - return (
Carnet: - setPatientData({ ...patientData, code: e.target.value }) + setPatientData({ ...patientData, carnet: e.target.value }) } placeholder="Carnet" style={{ ...styles.input, ...GenInputStyle(2, 1) }} @@ -857,16 +820,15 @@ function UpdateStudentInformationSection({ patientId, getData, updateData }) { - setPatientData({ ...patientData, area: e.target.value }) + setPatientData({ ...patientData, career: e.target.value }) } placeholder="Carrera" style={{ ...styles.input, ...GenInputStyle(2, 2) }} disabled={!editMode} />
-

{updateError}

); }; From 0f789fe121d2d485661baa23c82cc6b03ae9207a Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Sat, 24 Aug 2024 18:55:53 -0600 Subject: [PATCH 12/27] fix: Changed to default devenv --- flake.lock | 11 +++++------ flake.nix | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index aad55ad8..9464a31b 100644 --- a/flake.lock +++ b/flake.lock @@ -41,16 +41,15 @@ "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1723594027, - "narHash": "sha256-9Ti2LYVyfdiho5RfIkou6U6yhiZnVHAQNmcPzt7Otzs=", - "owner": "ElrohirGT", + "lastModified": 1724504184, + "narHash": "sha256-gP6000c2+zHKJHAxCD3BftvAjmb4CPAZamRAHNxN2MM=", + "owner": "cachix", "repo": "devenv", - "rev": "11d0fa9ee755691ff0db2e3199174b1a20f19b6a", + "rev": "51338b58fd666f448db7486ec145dbe52db9b829", "type": "github" }, "original": { - "owner": "ElrohirGT", - "ref": "feat-add-custom-pg-hba-conf", + "owner": "cachix", "repo": "devenv", "type": "github" } diff --git a/flake.nix b/flake.nix index 3d9606a5..f8570c41 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,7 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; systems.url = "github:nix-systems/default"; devenv = { - url = "github:ElrohirGT/devenv/feat-add-custom-pg-hba-conf"; + url = "github:cachix/devenv"; inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -127,7 +127,7 @@ listen_addresses = postgresHost; port = postgresPort; initialScript = dbInitFile; - customPgHbaFile = ./pg_hba.conf; + hbaConf = builtins.readFile ./pg_hba.conf; settings = { log_connections = true; log_statement = "all"; From 609729f745f3b3260f46c972dc0535c295d09f57 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Sat, 24 Aug 2024 19:33:32 -0600 Subject: [PATCH 13/27] fix: Added temporal nixpkgs version for samcli --- flake.lock | 17 +++++++++++++++++ flake.nix | 17 ++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index 9464a31b..338aa8df 100644 --- a/flake.lock +++ b/flake.lock @@ -389,9 +389,26 @@ "inputs": { "devenv": "devenv", "nixpkgs": "nixpkgs_2", + "samcliPkgs": "samcliPkgs", "systems": "systems_3" } }, + "samcliPkgs": { + "locked": { + "lastModified": 1720403430, + "narHash": "sha256-PUBgB5QpCcgA0PALzGW0gym6NsbrHQW92KVpuixgObU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "42c5e250a8a9162c3e962c78a4c393c5ac369093", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "rev": "42c5e250a8a9162c3e962c78a4c393c5ac369093", + "type": "github" + } + }, "systems": { "locked": { "lastModified": 1681028828, diff --git a/flake.nix b/flake.nix index f8570c41..1ca12b1a 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,7 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + samcliPkgs.url = "github:nixos/nixpkgs/42c5e250a8a9162c3e962c78a4c393c5ac369093"; systems.url = "github:nix-systems/default"; devenv = { url = "github:cachix/devenv"; @@ -20,6 +21,7 @@ nixpkgs, systems, devenv, + samcliPkgs, ... } @ inputs: let forEachSystem = nixpkgs.lib.genAttrs (import systems); @@ -78,6 +80,7 @@ devShells = forEachSystem (system: let pkgs = import nixpkgs {inherit system;}; + samcli = (import samcliPkgs {inherit system;}).aws-sam-cli; requiredPkgs = with pkgs; [ jq ]; @@ -85,9 +88,9 @@ nodejs_20 yarn-berry ]; - backendRequiredPkgs = with pkgs; [ - awscli2 - aws-sam-cli + backendRequiredPkgs = [ + pkgs.awscli2 + samcli ]; strFromDBFile = file: builtins.readFile ./database/${file}; dbInitFile = builtins.concatStringsSep "\n" [(strFromDBFile "init.sql") (strFromDBFile "tables.sql") (strFromDBFile "inserts.sql")]; @@ -103,14 +106,14 @@ inherit pkgs inputs; modules = [ { - packages = with pkgs; + packages = [ # General - nodePackages.jsdoc + pkgs.nodePackages.jsdoc # Database - postgresql - sqlfluff # SQL linter and formatter + pkgs.postgresql + pkgs.sqlfluff # SQL linter and formatter ] ++ requiredPkgs ++ frontendRequiredPkgs From 062c24bcf9228b56d49a5dfd476e84f5fb60edef Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Sat, 24 Aug 2024 19:34:59 -0600 Subject: [PATCH 14/27] fix: Removed redundancy --- .../src/views/UpdateGeneralInformationView/index.jsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index 0347896c..d09cd746 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -202,7 +202,6 @@ function UpdateColaboratorInformationSection({ } const handleUpdatePatient = async () => { - toast.info("Guardando datos..."); setEditMode(false); try { const response = await updateData(patientData); @@ -425,7 +424,6 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { return; } setEditMode(false); - toast.dismiss(); // Clear existing toasts const updateInformationResource = WrapPromise(updateData(patientData)); setResourceUpdate(updateInformationResource); }; @@ -767,7 +765,6 @@ function UpdateStudentInformationSection({ patientId, getData, updateData }) { } const handleUpdatePatient = async () => { - toast.info("Guardando datos..."); setEditMode(false); setResourceUpdate(WrapPromise(updateData(patientData))); }; From 514e071f0277249e120f153bc96e917d8b0fcb0d Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Sat, 24 Aug 2024 19:57:22 -0600 Subject: [PATCH 15/27] feat: Added contact information --- .../src/components/Collapsable/index.jsx | 22 ++- .../UpdateGeneralInformationView/index.jsx | 186 +++++++++++------- 2 files changed, 132 insertions(+), 76 deletions(-) diff --git a/sanitas_frontend/src/components/Collapsable/index.jsx b/sanitas_frontend/src/components/Collapsable/index.jsx index c6c07386..6e3d18c6 100644 --- a/sanitas_frontend/src/components/Collapsable/index.jsx +++ b/sanitas_frontend/src/components/Collapsable/index.jsx @@ -6,14 +6,19 @@ import downCaret from "@tabler/icons/filled/caret-down.svg"; /** * @typedef {Object} CollapsableProps * @property {string} title + * @property {boolean} [isCollapsed=true] Controls whether this component is collapsed or not, by default starts collapsed. * @property {*} children - The components to render inside. */ /** * @param {CollapsableProps} props */ -export default function Collapsable({ children, title }) { - const [isCollapsed, setIsCollapsed] = useState(); +export default function Collapsable({ + children, + title, + isCollapsed: startsCollapsed, +}) { + const [isCollapsed, setIsCollapsed] = useState(startsCollapsed ?? true); return (
@@ -32,11 +37,12 @@ export default function Collapsable({ children, title }) { flexDirection: "row", alignItems: "center", gap: "0.5rem", + width: "100%", }} onClick={() => setIsCollapsed(!isCollapsed)} > Caret simbol{title}

- {isCollapsed ?
{children}
: null} +
+ {children} +
); } diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index d09cd746..4acaefce 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -12,6 +12,7 @@ import Throbber from "src/components/Throbber"; import { colors, fonts, fontSize } from "src/theme.mjs"; import { formatDate } from "src/utils/date"; import WrapPromise from "src/utils/promiseWrapper"; +import Collapsable from "src/components/Collapsable"; /** * @typedef {Object} PatientInfo @@ -375,6 +376,14 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { }, }; + /** @type {React.CSSProperties} */ + const collapsableInnerStyle = { + display: "flex", + flexDirection: "column", + gap: "0.5rem", + padding: "1rem", + }; + const generalInformationResource = WrapPromise(getData(patientId)); // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Ignoring complexity for this function const Hijo = () => { @@ -588,78 +597,111 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) {

Contactos del paciente

-
- - - setPatientData({ ...patientData, contactName1: e.target.value }) - } - style={styles.input} - disabled={!editMode} - /> - - - - setPatientData({ - ...patientData, - contactKinship1: e.target.value, - }) - } - style={styles.input} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, contactPhone1: e.target.value }) - } - style={styles.input} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, contactName2: e.target.value }) - } - style={styles.input} - disabled={!editMode} - /> - - - - setPatientData({ - ...patientData, - contactKinship2: e.target.value, - }) - } - style={styles.input} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, contactPhone2: e.target.value }) - } - style={styles.input} - disabled={!editMode} - /> +
+ +
+ + + setPatientData({ + ...patientData, + contactName1: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> + + + + setPatientData({ + ...patientData, + contactKinship1: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> + + + + setPatientData({ + ...patientData, + contactPhone1: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> +
+
+ +
+ + + setPatientData({ + ...patientData, + contactName2: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> + + + + setPatientData({ + ...patientData, + contactKinship2: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> + + + + setPatientData({ + ...patientData, + contactPhone2: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> +
+
); From 6d5d3636e3bb1903263903d652979e25bc44fe0c Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Sat, 24 Aug 2024 20:09:07 -0600 Subject: [PATCH 16/27] fix: tests --- .../src/views/UpdateGeneralInformationView/index.test.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.test.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.test.jsx index ee307cc6..c6d6c17f 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.test.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.test.jsx @@ -18,7 +18,7 @@ const examplePatientData = { contactPhone2: "987654321", bloodType: "O+", address: "123 Main St", - insuranceId: 12345, + insurance: "El Roble", birthdate: "1980-01-02", phone: "555-1234", }; @@ -83,7 +83,7 @@ describe("UpdateInfoView tests", () => { expect(screen.getByDisplayValue("987654321")).toBeVisible(); expect(screen.getByDisplayValue("O+")).toBeVisible(); expect(screen.getByDisplayValue("123 Main St")).toBeVisible(); - expect(screen.getByDisplayValue("12345")).toBeVisible(); + expect(screen.getByDisplayValue("El Roble")).toBeVisible(); expect(screen.getByDisplayValue("1980-01-02")).toBeVisible(); expect(screen.getByDisplayValue("555-1234")).toBeVisible(); }, From 729fb7a31872e99c9f9e1b6fe47d9c79f7c96d07 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Mon, 26 Aug 2024 08:49:09 -0600 Subject: [PATCH 17/27] fix: integration tests and backend --- sanitas_backend/layers/utils/utils/index.mjs | 2 +- .../get-general-student-info-integration.test.mjs | 2 +- .../update-student-data.integration.test.mjs | 4 ++-- sanitas_backend/src/handlers/testHelpers.mjs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sanitas_backend/layers/utils/utils/index.mjs b/sanitas_backend/layers/utils/utils/index.mjs index cb0da613..7ddff566 100644 --- a/sanitas_backend/layers/utils/utils/index.mjs +++ b/sanitas_backend/layers/utils/utils/index.mjs @@ -83,7 +83,7 @@ export function decodeJWT(jwt) { */ export function mapToAPIPatient(dbPatient) { const { - patientId, + id: patientId, cui, es_mujer: isWoman, correo: email, diff --git a/sanitas_backend/src/handlers/GetGeneralStudentInfo/get-general-student-info-integration.test.mjs b/sanitas_backend/src/handlers/GetGeneralStudentInfo/get-general-student-info-integration.test.mjs index f0d74694..2b7220ee 100644 --- a/sanitas_backend/src/handlers/GetGeneralStudentInfo/get-general-student-info-integration.test.mjs +++ b/sanitas_backend/src/handlers/GetGeneralStudentInfo/get-general-student-info-integration.test.mjs @@ -26,7 +26,7 @@ describe("Student Handler", () => { expect(user).toBeDefined(); expect(user.carnet).toBe("A01234567"); expect(user.career).toBe("Ingeniería en CC y TI"); - expect(user.patientId).toBe(1); + expect(user.idPatient).toBe(1); }); it("should not found a patiend", async () => { diff --git a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs index 1a546302..b82f8a66 100644 --- a/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdateStudentData/update-student-data.integration.test.mjs @@ -45,7 +45,7 @@ describe("Update patient student data integration tests", () => { payload.career, ); - expect(received.patientId).toBe(idPatient); + expect(received.idPatient).toBe(idPatient); expect(received.carnet).toBe(payload.carnet); expect(received.career).toBe(payload.career); }); @@ -57,7 +57,7 @@ describe("Update patient student data integration tests", () => { const payload = generateValidUpdate(idPatient); await axios.put(API_URL, payload, { headers }); - payload.patientId = patient2Id; + payload.idPatient = patient2Id; const response = await axios.put(API_URL, payload, { headers, validateStatus: () => true, diff --git a/sanitas_backend/src/handlers/testHelpers.mjs b/sanitas_backend/src/handlers/testHelpers.mjs index 9e46bab5..829f216b 100644 --- a/sanitas_backend/src/handlers/testHelpers.mjs +++ b/sanitas_backend/src/handlers/testHelpers.mjs @@ -103,7 +103,7 @@ export async function updateStudentInfo( career = "Lic. Computación", ) { const payload = { - patientId: id, + idPatient: id, carnet, career, }; From 34c266af852216d8965c4041d1b88285c3666ef5 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Mon, 26 Aug 2024 08:49:42 -0600 Subject: [PATCH 18/27] fix: UI --- .../src/components/Collapsable/index.jsx | 16 +++++++++------- .../views/UpdateGeneralInformationView/index.jsx | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sanitas_frontend/src/components/Collapsable/index.jsx b/sanitas_frontend/src/components/Collapsable/index.jsx index 6e3d18c6..2ac6cc9f 100644 --- a/sanitas_frontend/src/components/Collapsable/index.jsx +++ b/sanitas_frontend/src/components/Collapsable/index.jsx @@ -5,7 +5,7 @@ import downCaret from "@tabler/icons/filled/caret-down.svg"; /** * @typedef {Object} CollapsableProps - * @property {string} title + * @property {string} [title=""] * @property {boolean} [isCollapsed=true] Controls whether this component is collapsed or not, by default starts collapsed. * @property {*} children - The components to render inside. */ @@ -13,12 +13,14 @@ import downCaret from "@tabler/icons/filled/caret-down.svg"; /** * @param {CollapsableProps} props */ -export default function Collapsable({ - children, - title, - isCollapsed: startsCollapsed, -}) { - const [isCollapsed, setIsCollapsed] = useState(startsCollapsed ?? true); +export default function Collapsable( + { children, title, isCollapsed: startsCollapsed } = { + childre: null, + title: "", + isCollapsed: true, + }, +) { + const [isCollapsed, setIsCollapsed] = useState(startsCollapsed); return (
diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index 4acaefce..9a79d435 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -608,7 +608,7 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { >
@@ -656,7 +656,7 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) {
From 388faafb3deba40e7edf7cfee3cc225622a91596 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Mon, 26 Aug 2024 16:03:12 -0600 Subject: [PATCH 19/27] fix: Big general loading --- .../UpdateGeneralInformationView/index.jsx | 934 ++++++++---------- 1 file changed, 426 insertions(+), 508 deletions(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index 9a79d435..efa77313 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -81,21 +81,25 @@ export default function UpdateInfoView({ width: "99%", }} > - - - + } + > + + + +
); @@ -177,118 +181,87 @@ function UpdateColaboratorInformationSection({ }; const collaboratorInformationResource = WrapPromise(getData(patientId)); + const response = collaboratorInformationResource.read(); - const Hijo = () => { - const [editMode, setEditMode] = useState(false); - const [resourceUpdate, setResourceUpdate] = useState(null); + const [editMode, setEditMode] = useState(false); + const [patientData, setPatientData] = useState({ + ...(response?.result || {}), + }); - const response = collaboratorInformationResource.read(); + const handleUpdatePatient = async () => { + setEditMode(false); + toast.info("Actualizando datos de colaborador..."); - const [patientData, setPatientData] = useState({ - ...(response?.result || {}), - }); - - if (resourceUpdate !== null) { - setResourceUpdate(null); - const response = resourceUpdate.read(); - if (response.error) { - toast.error( - `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${response.error.toString()}`, - ); - } else { - setEditMode(false); - setPatientData(response.result || {}); - toast.success("¡Información actualizada exitosamente!"); - } + const response = await updateData(patientData); + if (response.error) { + toast.error( + `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${response.error.message}`, + ); + return; } - const handleUpdatePatient = async () => { - setEditMode(false); - try { - const response = await updateData(patientData); - setPatientData(response.result || {}); - toast.success("¡Información actualizada exitosamente!"); - } catch (error) { - toast.error( - `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${error.message}`, - ); - } - }; - - const handleCancelEdit = () => { - setPatientData({ ...response?.result }); - setEditMode(false); - }; - - return ( -
-
-

Datos de Colaborador:

- {editMode ? ( -
- - -
- ) : ( - setEditMode(true)} /> - )} -
-
- - - setPatientData({ ...patientData, code: e.target.value }) - } - placeholder="Código" - style={{ ...styles.input, ...GenInputStyle(2, 1) }} - disabled={!editMode} - /> + setPatientData(response.result || {}); + toast.success("¡Información actualizada exitosamente!"); + }; - - - setPatientData({ ...patientData, area: e.target.value }) - } - placeholder="Área" - style={{ ...styles.input, ...GenInputStyle(2, 2) }} - disabled={!editMode} - /> -
-
- ); + const handleCancelEdit = () => { + setPatientData({ ...response?.result }); + setEditMode(false); }; - const LoadingView = () => { - return ( -
+ return ( +
+

Datos de Colaborador:

- + {editMode ? ( +
+ + +
+ ) : ( + setEditMode(true)} /> + )}
- ); - }; +
+ + + setPatientData({ ...patientData, code: e.target.value }) + } + placeholder="Código" + style={{ ...styles.input, ...GenInputStyle(2, 1) }} + disabled={!editMode} + /> - return ( - }> - - + + + setPatientData({ ...patientData, area: e.target.value }) + } + placeholder="Área" + style={{ ...styles.input, ...GenInputStyle(2, 2) }} + disabled={!editMode} + /> +
+
); } @@ -385,341 +358,311 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { }; const generalInformationResource = WrapPromise(getData(patientId)); - // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Ignoring complexity for this function - const Hijo = () => { - const [editMode, setEditMode] = useState(false); - const [resourceUpdate, setResourceUpdate] = useState(null); + const response = generalInformationResource.read(); + const [editMode, setEditMode] = useState(false); - const response = generalInformationResource.read(); + /** @type {[PatientInfo, (data: PatientInfo) => void]} */ + const [patientData, setPatientData] = useState({ + ...response.result, + birthdate: formatDate(response.result?.birthdate), + }); - /** @type {[PatientInfo, (data: PatientInfo) => void]} */ - const [patientData, setPatientData] = useState({ - ...response.result, - birthdate: formatDate(response.result?.birthdate), - }); + if (response.error) { + return ( +
+

+ Error al buscar el paciente. Asegúrese de que el ID es correcto. +

+

{response.error.toString()}

+
+ ); + } + + const handleUpdatePatient = async () => { + if (patientData.cui.length !== 13) { + toast.info("El CUI debe contener exactamente 13 dígitos."); + return; + } + setEditMode(false); + toast.info("Actualizando datos generales..."); + + const response = await updateData(patientData); if (response.error) { - return ( -
-

- Error al buscar el paciente. Asegúrese de que el ID es correcto. -

-

{response.error.toString()}

-
+ toast.error( + `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${response.error.message}`, ); } - if (resourceUpdate !== null) { - setResourceUpdate(null); - const response = resourceUpdate.read(); - if (response.error) { - toast.dismiss(); - toast.error( - `Lo sentimos! Ha ocurrido un error al actualizar los datos! ${response.error.toString()}`, - ); - } else { - toast.dismiss(); - toast.success("¡Información actualizada exitosamente!"); - setPatientData({ - ...response.result, - birthdate: formatDate(response.result.birthdate), - }); - } - } + setPatientData(response.result || {}); + toast.success("¡Información actualizada exitosamente!"); + }; - const handleUpdatePatient = async () => { - if (patientData.cui.length !== 13) { - toast.info("El CUI debe contener exactamente 13 dígitos."); - return; - } - setEditMode(false); - const updateInformationResource = WrapPromise(updateData(patientData)); - setResourceUpdate(updateInformationResource); - }; - - const handleCancelEdit = () => { - setPatientData({ - ...response.result, - birthdate: formatDate(response.result.birthdate), - }); - setEditMode(false); - }; + const handleCancelEdit = () => { + setPatientData({ + ...response.result, + birthdate: formatDate(response.result.birthdate), + }); + setEditMode(false); + }; - return ( -
-
-

Datos Generales:

- {editMode ? ( -
- - -
- ) : ( - setEditMode(true)} /> - )} -
-
- - - setPatientData({ ...patientData, names: e.target.value }) - } - placeholder="Nombres" - style={{ ...styles.input, ...GenInputStyle(2, 1) }} + return ( + +
+

Datos Generales:

+ {editMode ? ( +
+ + +
+ ) : ( + setEditMode(true)} /> + )} +
+
+ + + setPatientData({ ...patientData, names: e.target.value }) + } + placeholder="Nombres" + style={{ ...styles.input, ...GenInputStyle(2, 1) }} + disabled={!editMode} + /> + + + + setPatientData({ ...patientData, lastNames: e.target.value }) + } + style={{ ...styles.input, ...GenInputStyle(2, 2) }} + disabled={!editMode} + /> + + + + setPatientData({ ...patientData, cui: e.target.value }) + } + placeholder="CUI" + style={{ ...styles.input, ...GenInputStyle(4, 1) }} + disabled={!editMode} + /> + + + + setPatientData({ ...patientData, email: e.target.value }) + } + style={{ ...styles.input, ...GenInputStyle(4, 2) }} + disabled={!editMode} + /> + + +
+ setPatientData({ ...patientData, isWoman: true })} disabled={!editMode} /> - - - - setPatientData({ ...patientData, lastNames: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(2, 2) }} + setPatientData({ ...patientData, isWoman: false })} disabled={!editMode} /> +
+ + + + setPatientData({ ...patientData, phone: e.target.value }) + } + style={{ ...styles.input, ...GenInputStyle(6, 2) }} + disabled={!editMode} + /> + + + + setPatientData({ ...patientData, birthdate: e.target.value }) + } + style={{ ...styles.input, ...GenInputStyle(8, 1) }} + disabled={!editMode} + /> +
- +
+ + + setPatientData({ ...patientData, bloodType: e.target.value }) + } + style={{ ...styles.input, ...GenInputStyle(8, 2) }} + disabled={!editMode} + /> + + + + setPatientData({ ...patientData, address: e.target.value }) + } + style={styles.input} + disabled={!editMode} + /> + + +
- setPatientData({ ...patientData, cui: e.target.value }) + setPatientData({ ...patientData, insurance: e.target.value }) } - placeholder="CUI" - style={{ ...styles.input, ...GenInputStyle(4, 1) }} + style={{ width: "18.75rem" }} disabled={!editMode} /> +
+
- - - setPatientData({ ...patientData, email: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(4, 2) }} - disabled={!editMode} - /> +

Contactos del paciente

+
+ +
+ + + setPatientData({ + ...patientData, + contactName1: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> - -
- setPatientData({ ...patientData, isWoman: true })} + + + setPatientData({ + ...patientData, + contactKinship1: e.target.value, + }) + } + style={styles.input} disabled={!editMode} /> - - setPatientData({ ...patientData, isWoman: false }) + + + + setPatientData({ + ...patientData, + contactPhone1: e.target.value, + }) } + style={styles.input} disabled={!editMode} />
+ + +
+ + + setPatientData({ + ...patientData, + contactName2: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> - - - setPatientData({ ...patientData, phone: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(6, 2) }} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, birthdate: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(8, 1) }} - disabled={!editMode} - /> -
- -
- - - setPatientData({ ...patientData, bloodType: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(8, 2) }} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, address: e.target.value }) - } - style={styles.input} - disabled={!editMode} - /> + + + setPatientData({ + ...patientData, + contactKinship2: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> - -
+ - setPatientData({ ...patientData, insurance: e.target.value }) + setPatientData({ + ...patientData, + contactPhone2: e.target.value, + }) } - style={{ width: "18.75rem" }} + style={styles.input} disabled={!editMode} />
-
- -

Contactos del paciente

-
- -
- - - setPatientData({ - ...patientData, - contactName1: e.target.value, - }) - } - style={styles.input} - disabled={!editMode} - /> - - - - setPatientData({ - ...patientData, - contactKinship1: e.target.value, - }) - } - style={styles.input} - disabled={!editMode} - /> - - - - setPatientData({ - ...patientData, - contactPhone1: e.target.value, - }) - } - style={styles.input} - disabled={!editMode} - /> -
-
- -
- - - setPatientData({ - ...patientData, - contactName2: e.target.value, - }) - } - style={styles.input} - disabled={!editMode} - /> - - - - setPatientData({ - ...patientData, - contactKinship2: e.target.value, - }) - } - style={styles.input} - disabled={!editMode} - /> - - - - setPatientData({ - ...patientData, - contactPhone2: e.target.value, - }) - } - style={styles.input} - disabled={!editMode} - /> -
-
-
- - ); - }; - - const LoadingView = () => { - return ( -
-

Datos Generales:

- +
- ); - }; - - return ( - }> - - + ); } @@ -779,111 +722,86 @@ function UpdateStudentInformationSection({ patientId, getData, updateData }) { // Fetch the student information const studentInformationResource = WrapPromise(getData(patientId)); + const response = studentInformationResource.read(); - const Hijo = () => { - const [editMode, setEditMode] = useState(false); - const [resourceUpdate, setResourceUpdate] = useState(null); - - const response = studentInformationResource.read(); + const [editMode, setEditMode] = useState(false); + const [patientData, setPatientData] = useState({ + ...(response?.result || {}), + }); - const [patientData, setPatientData] = useState({ - ...(response?.result || {}), - }); + const handleUpdatePatient = async () => { + setEditMode(false); + toast.info("Actualizando datos de estudiante..."); - if (resourceUpdate !== null) { - setResourceUpdate(null); - const response = resourceUpdate.read(); - if (response.error) { - toast.dismiss(); - toast.error( - `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${response.error.toString()}`, - ); - } else { - setEditMode(false); - setPatientData(response.result || {}); - toast.dismiss(); - toast.success("¡Información actualizada exitosamente!"); - } + const response = await updateData(patientData); + if (response.error) { + toast.error( + `Lo sentimos! Ha ocurrido un error al actualizar los datos!\n${response.error.message}`, + ); + return; } - const handleUpdatePatient = async () => { - setEditMode(false); - setResourceUpdate(WrapPromise(updateData(patientData))); - }; - - const handleCancelEdit = () => { - setPatientData({ ...response?.result }); - setEditMode(false); - }; - - return ( -
-
-

Datos de Estudiante:

- {editMode ? ( -
- - -
- ) : ( - setEditMode(true)} /> - )} -
-
- - - setPatientData({ ...patientData, carnet: e.target.value }) - } - placeholder="Carnet" - style={{ ...styles.input, ...GenInputStyle(2, 1) }} - disabled={!editMode} - /> + setPatientData(response.result || {}); + toast.success("¡Información actualizada exitosamente!"); + }; - - - setPatientData({ ...patientData, career: e.target.value }) - } - placeholder="Carrera" - style={{ ...styles.input, ...GenInputStyle(2, 2) }} - disabled={!editMode} - /> -
-
- ); + const handleCancelEdit = () => { + setPatientData({ ...response?.result }); + setEditMode(false); }; - const LoadingView = () => { - return ( -
+ return ( +
+

Datos de Estudiante:

- + {editMode ? ( +
+ + +
+ ) : ( + setEditMode(true)} /> + )}
- ); - }; +
+ + + setPatientData({ ...patientData, carnet: e.target.value }) + } + placeholder="Carnet" + style={{ ...styles.input, ...GenInputStyle(2, 1) }} + disabled={!editMode} + /> - return ( - }> - - + + + setPatientData({ ...patientData, career: e.target.value }) + } + placeholder="Carrera" + style={{ ...styles.input, ...GenInputStyle(2, 2) }} + disabled={!editMode} + /> +
+
); } From 060e85675bc3c2d0799cd71486e4eea9b41b9a2a Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Mon, 26 Aug 2024 16:15:43 -0600 Subject: [PATCH 20/27] fix: Suspense bug --- .../UpdateGeneralInformationView/index.jsx | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index efa77313..08e0324a 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -61,6 +61,12 @@ export default function UpdateInfoView({ }) { const id = useStore((s) => s.selectedPatientId); + const [generalResource, collaboratorResource, studentResource] = [ + getGeneralPatientInformation(id), + getCollaboratorInformation(id), + getStudentPatientInformation(id), + ].map((s) => WrapPromise(s)); + return (
} > @@ -107,19 +110,14 @@ export default function UpdateInfoView({ /** * @typedef {Object} UpdateColaboratorInformationSectionProps - * @property {number} patientId - * @property {import("src/dataLayer.mjs").GetCollaboratorPatientInformationAPICall} getData + * @property {import("src/utils/promiseWrapper").SuspenseResource<*>} getData * @property {import("src/dataLayer.mjs").UpdateCollaboratorPatientInformationAPICall} updateData */ /** * @param {UpdateColaboratorInformationSectionProps} props */ -function UpdateColaboratorInformationSection({ - patientId, - getData, - updateData, -}) { +function UpdateColaboratorInformationSection({ getData, updateData }) { const GenInputStyle = (labelRow, labelColumn) => { const gridColumn = `${labelColumn} / ${labelColumn + 1}`; const gridRow = `${labelRow} / ${labelRow + 1}`; @@ -180,8 +178,7 @@ function UpdateColaboratorInformationSection({ }, }; - const collaboratorInformationResource = WrapPromise(getData(patientId)); - const response = collaboratorInformationResource.read(); + const response = getData.read(); const [editMode, setEditMode] = useState(false); const [patientData, setPatientData] = useState({ @@ -267,8 +264,7 @@ function UpdateColaboratorInformationSection({ /** * @typedef {Object} UpdateGeneralInformationSectionProps - * @property {number} patientId - * @property {import("src/dataLayer.mjs").GetGeneralPatientInformationAPICall} getData + * @property {import("src/utils/promiseWrapper").SuspenseResource<*>} getData * @property {import("src/dataLayer.mjs").UpdateGeneralPatientInformationAPICall} updateData */ @@ -276,7 +272,7 @@ function UpdateColaboratorInformationSection({ * @param {UpdateGeneralInformationSectionProps} props * @returns {JSX.Element} */ -function UpdateGeneralInformationSection({ patientId, getData, updateData }) { +function UpdateGeneralInformationSection({ getData, updateData }) { const GenInputStyle = (labelRow, labelColumn) => { const gridColumn = `${labelColumn} / ${labelColumn + 1}`; const gridRow = `${labelRow} / ${labelRow + 1}`; @@ -357,8 +353,7 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { padding: "1rem", }; - const generalInformationResource = WrapPromise(getData(patientId)); - const response = generalInformationResource.read(); + const response = getData.read(); const [editMode, setEditMode] = useState(false); /** @type {[PatientInfo, (data: PatientInfo) => void]} */ @@ -668,15 +663,14 @@ function UpdateGeneralInformationSection({ patientId, getData, updateData }) { /** * @typedef {Object} UpdateStudentInformationSectionProps - * @property {number} patientId - * @property {import("src/dataLayer.mjs").GetStudentPatientInformationAPICall} getData + * @property {import("src/utils/promiseWrapper").SuspenseResource<*>} getData * @property {import("src/dataLayer.mjs").UpdateStudentPatientInformationAPICall} updateData */ /** * @param {UpdateStudentInformationSectionProps} props */ -function UpdateStudentInformationSection({ patientId, getData, updateData }) { +function UpdateStudentInformationSection({ getData, updateData }) { const GenInputStyle = (labelRow, labelColumn) => { const gridColumn = `${labelColumn} / ${labelColumn + 1}`; const gridRow = `${labelRow} / ${labelRow + 1}`; @@ -721,8 +715,7 @@ function UpdateStudentInformationSection({ patientId, getData, updateData }) { }; // Fetch the student information - const studentInformationResource = WrapPromise(getData(patientId)); - const response = studentInformationResource.read(); + const response = getData.read(); const [editMode, setEditMode] = useState(false); const [patientData, setPatientData] = useState({ From 14796be8b443295a575b6abd9adad16cf40e285f Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Mon, 26 Aug 2024 17:16:25 -0600 Subject: [PATCH 21/27] fix: tests --- .../src/views/UpdateGeneralInformationView/index.test.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.test.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.test.jsx index c6d6c17f..91c2bdea 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.test.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.test.jsx @@ -169,6 +169,6 @@ describe("UpdateInfoView tests", () => { , ); - expect(screen.getAllByText("Cargando información del paciente...")); + expect(screen.getAllByText("Cargando datos de paciente...")); }); }); From 0d0d69d1de325ead90696139f1241aa181eb16ab Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Tue, 27 Aug 2024 12:45:22 -0600 Subject: [PATCH 22/27] fix: main data styles --- .../UpdateGeneralInformationView/index.jsx | 455 ++++++++++-------- 1 file changed, 258 insertions(+), 197 deletions(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index 08e0324a..8c51b2d4 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -129,7 +129,6 @@ function UpdateColaboratorInformationSection({ getData, updateData }) { form: { padding: "2rem", border: "1px solid #ddd", - borderRadius: "5px", }, label: { fontSize: fontSize.textSize, @@ -401,8 +400,32 @@ function UpdateGeneralInformationSection({ getData, updateData }) { setEditMode(false); }; + /**@type {React.CSSProperties} */ + const inputContainerStyles = { + display: "flex", + flexDirection: "column", + gap: "0.5rem", + }; + /**@type {React.CSSProperties} */ + const inputStyles = { + height: "3rem", + }; + /**@type {React.CSSProperties} */ + const columnStyles = { + padding: "1rem", + display: "flex", + flexDirection: "column", + gap: "1rem", + }; + return ( -
+
+ {/* HEADER */}
setEditMode(true)} /> )}
-
- - - setPatientData({ ...patientData, names: e.target.value }) - } - placeholder="Nombres" - style={{ ...styles.input, ...GenInputStyle(2, 1) }} - disabled={!editMode} - /> - - - setPatientData({ ...patientData, lastNames: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(2, 2) }} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, cui: e.target.value }) - } - placeholder="CUI" - style={{ ...styles.input, ...GenInputStyle(4, 1) }} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, email: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(4, 2) }} - disabled={!editMode} - /> - - -
- setPatientData({ ...patientData, isWoman: true })} - disabled={!editMode} - /> - setPatientData({ ...patientData, isWoman: false })} - disabled={!editMode} - /> -
- - - - setPatientData({ ...patientData, phone: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(6, 2) }} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, birthdate: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(8, 1) }} - disabled={!editMode} - /> -
- -
- - - setPatientData({ ...patientData, bloodType: e.target.value }) - } - style={{ ...styles.input, ...GenInputStyle(8, 2) }} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, address: e.target.value }) - } - style={styles.input} - disabled={!editMode} - /> - - -
- - setPatientData({ ...patientData, insurance: e.target.value }) - } - style={{ width: "18.75rem" }} - disabled={!editMode} - /> -
-
- -

Contactos del paciente

-
- -
- + {/* BODY */} +
+ {/* FIRST COLUMN*/} +
+
+ - setPatientData({ - ...patientData, - contactName1: e.target.value, - }) + setPatientData({ ...patientData, names: e.target.value }) } - style={styles.input} + placeholder="Nombres" + style={inputStyles} disabled={!editMode} /> +
- +
+ + setPatientData({ ...patientData, cui: e.target.value }) + } + placeholder="CUI" + style={inputStyles} + disabled={!editMode} + /> +
+ +
+ +
+ + setPatientData({ ...patientData, isWoman: true }) + } + disabled={!editMode} + /> + + setPatientData({ ...patientData, isWoman: false }) + } + disabled={!editMode} + /> +
+
+ +
+ + + setPatientData({ ...patientData, birthdate: e.target.value }) + } + style={inputStyles} + disabled={!editMode} + /> +
+
+ + - setPatientData({ - ...patientData, - contactKinship1: e.target.value, - }) + setPatientData({ ...patientData, bloodType: e.target.value }) } - style={styles.input} + style={{ + container: { width: "100%" }, + select: { height: "3rem" }, + }} disabled={!editMode} /> +
+
- + {/* SECOND COLUMN*/} +
+
+ - setPatientData({ - ...patientData, - contactPhone1: e.target.value, - }) + setPatientData({ ...patientData, lastNames: e.target.value }) } - style={styles.input} + style={inputStyles} disabled={!editMode} />
- - -
- + +
+ + + setPatientData({ ...patientData, email: e.target.value }) + } + style={inputStyles} + disabled={!editMode} + /> +
+ +
+ - setPatientData({ - ...patientData, - contactName2: e.target.value, - }) + setPatientData({ ...patientData, phone: e.target.value }) } - style={styles.input} + style={inputStyles} disabled={!editMode} /> +
- +
+ - setPatientData({ - ...patientData, - contactKinship2: e.target.value, - }) + setPatientData({ ...patientData, address: e.target.value }) } - style={styles.input} + style={inputStyles} disabled={!editMode} /> +
- +
+ - setPatientData({ - ...patientData, - contactPhone2: e.target.value, - }) + setPatientData({ ...patientData, insurance: e.target.value }) } - style={styles.input} + style={inputStyles} disabled={!editMode} />
- +
- + +
+

Contactos del paciente

+
+ +
+ + + setPatientData({ + ...patientData, + contactName1: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> + + + + setPatientData({ + ...patientData, + contactKinship1: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> + + + + setPatientData({ + ...patientData, + contactPhone1: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> +
+
+ +
+ + + setPatientData({ + ...patientData, + contactName2: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> + + + + setPatientData({ + ...patientData, + contactKinship2: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> + + + + setPatientData({ + ...patientData, + contactPhone2: e.target.value, + }) + } + style={styles.input} + disabled={!editMode} + /> +
+
+
+
+
); } /** * @typedef {Object} UpdateStudentInformationSectionProps - * @property {import("src/utils/promiseWrapper").SuspenseResource<*>} getData + * @property {import("src/utils/promiseWrapper").SuspenseResource <*>} getData * @property {import("src/dataLayer.mjs").UpdateStudentPatientInformationAPICall} updateData */ From 63fde4368ca48d02a5ae962cbec231214ee04e4d Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Tue, 27 Aug 2024 13:01:36 -0600 Subject: [PATCH 23/27] fix: general styles --- .../src/components/Collapsable/index.jsx | 4 +- .../UpdateGeneralInformationView/index.jsx | 42 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/sanitas_frontend/src/components/Collapsable/index.jsx b/sanitas_frontend/src/components/Collapsable/index.jsx index 2ac6cc9f..74ffb2be 100644 --- a/sanitas_frontend/src/components/Collapsable/index.jsx +++ b/sanitas_frontend/src/components/Collapsable/index.jsx @@ -30,7 +30,7 @@ export default function Collapsable( backgroundColor: colors.primaryBackground, color: "white", borderWidth: "0", - borderRadius: "0.2rem", + borderRadius: "0.3rem", padding: "0.5rem 1.2rem", fontFamily: fonts.titleFont, fontSize: fontSize.subtitleSize, @@ -51,7 +51,7 @@ export default function Collapsable( }} /> -

{title}

+

{title}

{/* FIRST COLUMN*/} -
+
-
-

Contactos del paciente

+
+

Contactos del paciente:

- + - + - +
@@ -673,7 +671,7 @@ function UpdateGeneralInformationSection({ getData, updateData }) { isCollapsed={!patientData.contactPhone2} >
- + - + - +
From 19b98bd6f5928e259a399e3ded658d142aaefba4 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Tue, 27 Aug 2024 13:02:30 -0600 Subject: [PATCH 24/27] fix: gapping --- .../src/views/UpdateGeneralInformationView/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index f2e3f020..0772649b 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -413,7 +413,7 @@ function UpdateGeneralInformationSection({ getData, updateData }) { padding: "1rem", display: "flex", flexDirection: "column", - gap: "1rem", + gap: "1.5rem", }; return ( From 9a6a013ce345b76b1431922769169f0f6d615bcb Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Tue, 27 Aug 2024 15:29:38 -0600 Subject: [PATCH 25/27] fix: Section padding --- .../src/components/Collapsable/index.jsx | 4 +++- .../views/UpdateGeneralInformationView/index.jsx | 15 ++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/sanitas_frontend/src/components/Collapsable/index.jsx b/sanitas_frontend/src/components/Collapsable/index.jsx index 74ffb2be..47ed1658 100644 --- a/sanitas_frontend/src/components/Collapsable/index.jsx +++ b/sanitas_frontend/src/components/Collapsable/index.jsx @@ -51,7 +51,9 @@ export default function Collapsable( }} /> -

{title}

+

+ {title} +

@@ -272,13 +272,6 @@ function UpdateColaboratorInformationSection({ getData, updateData }) { * @returns {JSX.Element} */ function UpdateGeneralInformationSection({ getData, updateData }) { - const GenInputStyle = (labelRow, labelColumn) => { - const gridColumn = `${labelColumn} / ${labelColumn + 1}`; - const gridRow = `${labelRow} / ${labelRow + 1}`; - - return { gridColumn, gridRow }; - }; - const dropdownOptions = [ { value: "", label: "Selecciona un tipo de sangre" }, { value: "A+", label: "A+" }, @@ -607,7 +600,7 @@ function UpdateGeneralInformationSection({ getData, updateData }) {
-
+

Contactos del paciente:

From e2264b9b143430c823f8d0df67fc53f20b7596aa Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Tue, 27 Aug 2024 20:42:49 -0600 Subject: [PATCH 26/27] fix: Stiling --- .../UpdateGeneralInformationView/index.jsx | 179 ++++++++++-------- 1 file changed, 104 insertions(+), 75 deletions(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index 87fe3cac..58a80b78 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -118,17 +118,10 @@ export default function UpdateInfoView({ * @param {UpdateColaboratorInformationSectionProps} props */ function UpdateColaboratorInformationSection({ getData, updateData }) { - const GenInputStyle = (labelRow, labelColumn) => { - const gridColumn = `${labelColumn} / ${labelColumn + 1}`; - const gridRow = `${labelRow} / ${labelRow + 1}`; - - return { gridColumn, gridRow }; - }; - const styles = { form: { - padding: "2rem", - border: "1px solid #ddd", + padding: "3rem 2rem", + borderBottom: "1px solid #ddd", }, label: { fontSize: fontSize.textSize, @@ -177,6 +170,12 @@ function UpdateColaboratorInformationSection({ getData, updateData }) { }, }; + /**@type {React.CSSProperties} */ + const inputStyles = { + width: "90%", + height: "3rem", + }; + const response = getData.read(); const [editMode, setEditMode] = useState(false); @@ -228,34 +227,50 @@ function UpdateColaboratorInformationSection({ getData, updateData }) {
- - - setPatientData({ ...patientData, code: e.target.value }) - } - placeholder="Código" - style={{ ...styles.input, ...GenInputStyle(2, 1) }} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, area: e.target.value }) - } - placeholder="Área" - style={{ ...styles.input, ...GenInputStyle(2, 2) }} - disabled={!editMode} - /> +
+ + + setPatientData({ ...patientData, code: e.target.value }) + } + placeholder="Código" + style={inputStyles} + disabled={!editMode} + /> +
+ +
+ + + setPatientData({ ...patientData, area: e.target.value }) + } + placeholder="Área" + style={inputStyles} + disabled={!editMode} + /> +
); @@ -341,6 +356,7 @@ function UpdateGeneralInformationSection({ getData, updateData }) { border: `.1rem solid ${colors.primaryBackground}`, borderRadius: "0 0 5% 5%", transform: "translateY(-1%)", + width: "30vw", }; const response = getData.read(); @@ -400,6 +416,7 @@ function UpdateGeneralInformationSection({ getData, updateData }) { /**@type {React.CSSProperties} */ const inputStyles = { height: "3rem", + width: "90%", }; /**@type {React.CSSProperties} */ const columnStyles = { @@ -523,7 +540,7 @@ function UpdateGeneralInformationSection({ getData, updateData }) { setPatientData({ ...patientData, bloodType: e.target.value }) } style={{ - container: { width: "100%" }, + container: { width: "90%" }, select: { height: "3rem" }, }} disabled={!editMode} @@ -606,9 +623,10 @@ function UpdateGeneralInformationSection({ getData, updateData }) { style={{ display: "flex", flexDirection: "row", + // justifyContent: "space-around", gap: "2rem", width: "100%", - paddingTop: "3rem", + paddingTop: "2rem", }} > { - const gridColumn = `${labelColumn} / ${labelColumn + 1}`; - const gridRow = `${labelRow} / ${labelRow + 1}`; - - return { gridColumn, gridRow }; - }; - const styles = { form: { - padding: "2rem", - border: "1px solid #ddd", + padding: "3rem 2rem", borderRadius: "5px", }, label: { @@ -761,9 +771,6 @@ function UpdateStudentInformationSection({ getData, updateData }) { gap: "20px", paddingTop: "10px", }, - input: { - maxWidth: "18.75rem", - }, }; // Fetch the student information @@ -795,6 +802,12 @@ function UpdateStudentInformationSection({ getData, updateData }) { setEditMode(false); }; + /**@type {React.CSSProperties} */ + const inputStyles = { + width: "90%", + height: "3rem", + }; + return (
- - - setPatientData({ ...patientData, carnet: e.target.value }) - } - placeholder="Carnet" - style={{ ...styles.input, ...GenInputStyle(2, 1) }} - disabled={!editMode} - /> - - - - setPatientData({ ...patientData, career: e.target.value }) - } - placeholder="Carrera" - style={{ ...styles.input, ...GenInputStyle(2, 2) }} - disabled={!editMode} - /> +
+ + + setPatientData({ ...patientData, carnet: e.target.value }) + } + placeholder="Carnet" + style={inputStyles} + disabled={!editMode} + /> +
+ +
+ + + setPatientData({ ...patientData, career: e.target.value }) + } + placeholder="Carrera" + style={inputStyles} + disabled={!editMode} + /> +
); From 61331062bf63e74e0856e8386212c47b2cfd1521 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Tue, 27 Aug 2024 20:45:19 -0600 Subject: [PATCH 27/27] fix: deleted zombi code --- .../src/views/UpdateGeneralInformationView/index.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx index 58a80b78..ca592350 100644 --- a/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx +++ b/sanitas_frontend/src/views/UpdateGeneralInformationView/index.jsx @@ -623,7 +623,6 @@ function UpdateGeneralInformationSection({ getData, updateData }) { style={{ display: "flex", flexDirection: "row", - // justifyContent: "space-around", gap: "2rem", width: "100%", paddingTop: "2rem",