From 2cefc0bc17392bb2b4164d3f1e47f9bb95a9e596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=B3pez=20=28Nathan=29?= <105880705+XavierLopez25@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:41:16 -0600 Subject: [PATCH] fix: suspicious error on gyneco (#317) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Jira [Link al issue en Jira](Link%20al%20clickup) ## Descripción Había un error por parte de frontend y backend al momento de enviar las condiciones adicionales del paciente. También, ahora en no patológios se puede editar completamente todo, a petición de las doctoras. ## Tasks - \[x] Asignate a tí mismo dentro de la PR. - \[x] Asegúrate que el nombre de la PR siga el formato de [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). - \[x] Añade una breve descripción de la escencia de tus cambios en tu PR. - \[x] Agrega el link al issue de Jira. - \[x] Asegurate que la PR pase todos los chequeos de CI. - \[x] Ponle las tags correspondientes a tu PR. Backend: PRs que modifican lógica relacionada al backend. Frontend: PRs que modifican lógica relacionada al frontend. Database: PRs que modifican lógica relacionada a la base de datos. Wiki: PRs que editan la wiki. Nix: PRs que modifican el entorno de desarrollo en Nix. CI/CD: PRs relacionadas con la CI/CD pipeline. --------- Co-authored-by: ElrohirGT <45268815+ElrohirGT@users.noreply.github.com> --- sanitas_backend/layers/utils/utils/index.mjs | 20 -- ...pdate-student-gyneco-obstetric-history.mjs | 4 + .../index.mjs | 14 +- .../src/components/Input/Base/base.jsx | 32 +- .../Students/StudentNonPathological/index.jsx | 57 ++- .../History/Students/StudentObGyn/index.jsx | 338 ++++++++++-------- 6 files changed, 236 insertions(+), 229 deletions(-) diff --git a/sanitas_backend/layers/utils/utils/index.mjs b/sanitas_backend/layers/utils/utils/index.mjs index e5766677..bc684a04 100644 --- a/sanitas_backend/layers/utils/utils/index.mjs +++ b/sanitas_backend/layers/utils/utils/index.mjs @@ -961,26 +961,6 @@ export function checkForUnauthorizedChanges(newData, oldData) { }); } -/** - * Checks if the student is trying to update fields that are already filled. - * @param {Object} newData - New data from the request. - * @param {Object} oldData - Existing data from the database. - * @returns {boolean} True if the new data tries to overwrite non-empty fields. - */ -export function checkForUnauthorizedChangesPathological(newData, oldData) { - return Object.keys(newData).some((key) => { - const newInfo = newData[key].data; - const oldInfo = oldData[key]?.data; - if (!oldInfo) return false; // If there was no old data, no unauthorized update is possible. - - return Object.keys(newInfo).some((field) => { - const newValue = newInfo[field]; - const oldValue = oldInfo[field]; - return oldValue && newValue !== oldValue; - }); - }); -} - /** * Determines if a medical record is empty. * @param {MedicalRecord} item - The medical record to evaluate. diff --git a/sanitas_backend/src/handlers/UpdateStudentGynecoObstetricHistory/update-student-gyneco-obstetric-history.mjs b/sanitas_backend/src/handlers/UpdateStudentGynecoObstetricHistory/update-student-gyneco-obstetric-history.mjs index 6e4e6b36..8a191cc7 100644 --- a/sanitas_backend/src/handlers/UpdateStudentGynecoObstetricHistory/update-student-gyneco-obstetric-history.mjs +++ b/sanitas_backend/src/handlers/UpdateStudentGynecoObstetricHistory/update-student-gyneco-obstetric-history.mjs @@ -100,6 +100,10 @@ function requestModifiesDBData(dbData, requestData) { const dbValue = dbData.diagnosedIllnesses.data[key].medication[subKey]; const requestValue = requestData.diagnosedIllnesses?.data[key]?.medication[subKey]; + if (dbValue == null || dbValue === "") { + // The existing database value is empty, so adding data is allowed + return false; + } const comparison = dbValue !== requestValue; logger.debug(`Comparing ${dbValue} !== ${requestValue} => ${comparison}`); diff --git a/sanitas_backend/src/handlers/UpdateStudentNonPatologicalHistory/index.mjs b/sanitas_backend/src/handlers/UpdateStudentNonPatologicalHistory/index.mjs index 19803b2f..637b7794 100644 --- a/sanitas_backend/src/handlers/UpdateStudentNonPatologicalHistory/index.mjs +++ b/sanitas_backend/src/handlers/UpdateStudentNonPatologicalHistory/index.mjs @@ -4,7 +4,6 @@ import { decodeJWT, createResponse, mapToAPINonPathologicalHistory, - checkForUnauthorizedChangesPathological, toSafeEvent, } from "utils/index.mjs"; @@ -73,22 +72,11 @@ export const handler = async (event, context) => { const patientResult = await client.query(getPatientQuery, [patientId]); if (patientResult.rowCount > 0) { const dbData = patientResult.rows[0]; - const oldData = { + const _oldData = { smoker: dbData.fuma_data, drink: dbData.bebidas_alcoholicas_data, drugs: dbData.drogas_data, }; - - if (checkForUnauthorizedChangesPathological(medicalHistory, oldData)) { - logger.error("Request modifies data!"); - const response = responseBuilder - .setStatusCode(403) - .setBody({ error: "Not authorized to update data!" }) - .build(); - - logger.info({ response }, "Responding with:"); - return { response }; - } } const upsertQuery = ` diff --git a/sanitas_frontend/src/components/Input/Base/base.jsx b/sanitas_frontend/src/components/Input/Base/base.jsx index 8b046edc..edd9310a 100644 --- a/sanitas_frontend/src/components/Input/Base/base.jsx +++ b/sanitas_frontend/src/components/Input/Base/base.jsx @@ -49,12 +49,32 @@ export default function BaseInput({ // Bloquear caracteres no numéricos para inputs de tipo 'number' const handleKeyPress = (event) => { - if ( - type === "number" && - !/^[0-9.]+$/.test(event.key) && - event.key !== "Backspace" - ) { - event.preventDefault(); + if (type === "number") { + // Permitir teclas de control como flechas, suprimir, etc. + const allowedKeys = [ + "ArrowUp", + "ArrowDown", + "ArrowLeft", + "ArrowRight", + "Backspace", + "Delete", + "Tab", + "Home", + "End", + ]; + + if ( + !( + ( + /^[0-9.]$/.test(event.key) || + allowedKeys.includes(event.key) || + event.ctrlKey || // Permitir combinaciones de control como Ctrl+C, Ctrl+V + (!event.ctrlKey && event.metaKey) + ) // Para teclas de comando en Mac + ) + ) { + event.preventDefault(); + } } }; diff --git a/sanitas_frontend/src/views/History/Students/StudentNonPathological/index.jsx b/sanitas_frontend/src/views/History/Students/StudentNonPathological/index.jsx index 5d068b5c..7f0fca4e 100644 --- a/sanitas_frontend/src/views/History/Students/StudentNonPathological/index.jsx +++ b/sanitas_frontend/src/views/History/Students/StudentNonPathological/index.jsx @@ -34,7 +34,7 @@ export function StudentNonPathologicalHistory({ // Fetching patient ID from global state const id = useStore((s) => s.selectedPatientId); - //const id = 1; + // const id = 1; // Memoizing resources for blood type and history to avoid refetching unless ID changes or a reload is triggered // biome-ignore lint/correctness/useExhaustiveDependencies: Reload the page @@ -454,7 +454,7 @@ function NonPathologicalView({ } }; - const areAllFieldsPreFilled = () => { + const _areAllFieldsPreFilled = () => { const smokerData = nonPathologicalHistoryResult.result?.medicalHistory.smoker.data; const drinkData = @@ -595,14 +595,12 @@ function NonPathologicalView({ checked={smokingStatus} onChange={() => handleSmokingChange(true)} label="Sí" - disabled={!isSmokingEditable} /> handleSmokingChange(false)} label="No" - disabled={!isSmokingEditable} /> {smokingStatus && ( @@ -624,7 +622,6 @@ function NonPathologicalView({ onChange={(e) => setCigarettesPerDay(e.target.value)} placeholder="Ingrese cuántos cigarrillos al día" min="1" - readOnly={!isSmokingEditable} style={{ ...baseInput }} /> @@ -638,7 +635,6 @@ function NonPathologicalView({ onChange={(e) => setSmokingYears(e.target.value)} placeholder="Ingrese desde hace cuántos años" min="1" - readOnly={!isSmokingEditable} style={{ ...baseInput }} /> @@ -676,14 +672,12 @@ function NonPathologicalView({ checked={alcoholConsumption} onChange={() => handleAlcoholChange(true)} label="Sí" - disabled={!isAlcoholEditable} /> handleAlcoholChange(false)} label="No" - disabled={!isAlcoholEditable} /> {alcoholConsumption && ( @@ -711,7 +705,6 @@ function NonPathologicalView({ onChange={(e) => setDrinksPerMonth(e.target.value)} placeholder="Ingrese cuántas bebidas al mes" min="1" - readOnly={!isAlcoholEditable} style={{ ...baseInput }} /> @@ -748,14 +741,12 @@ function NonPathologicalView({ checked={drugUse} onChange={() => handleDrugUseChange(true)} label="Sí" - disabled={!isDrugUseEditable} /> handleDrugUseChange(false)} label="No" - disabled={!isDrugUseEditable} /> {drugUse && ( @@ -777,7 +768,6 @@ function NonPathologicalView({ onChange={(e) => setDrugType(e.target.value)} placeholder="Ingrese el tipo de droga" min="1" - readOnly={!isDrugUseEditable} style={{ ...baseInput }} /> @@ -788,7 +778,6 @@ function NonPathologicalView({ value={drugFrequency} onChange={(e) => setDrugFrequency(e.target.value)} placeholder="Ingrese la frecuencia del consumo" - readOnly={!isDrugUseEditable} style={{ ...baseInput }} /> @@ -797,29 +786,25 @@ function NonPathologicalView({ )} - {!areAllFieldsPreFilled() && ( - <> -
-
- -
- - )} +
+
+ +
)}
diff --git a/sanitas_frontend/src/views/History/Students/StudentObGyn/index.jsx b/sanitas_frontend/src/views/History/Students/StudentObGyn/index.jsx index bc86c281..6b49c187 100644 --- a/sanitas_frontend/src/views/History/Students/StudentObGyn/index.jsx +++ b/sanitas_frontend/src/views/History/Students/StudentObGyn/index.jsx @@ -32,7 +32,7 @@ export function StudentObGynHistory({ useStore, }) { const id = useStore((s) => s.selectedPatientId); - // const id = 1; + // const id = 1; const [reload, setReload] = useState(false); // Controls reload toggling for refetching data const LoadingView = () => { @@ -1192,22 +1192,30 @@ function ObGynView({ const formattedDiagnosedIllnesses = { version: diagnosedIllnesses?.version || 1, - data: diagnoses.reduce((acc, diagnosis) => { - if (fixedDiagnosesKeys.includes(diagnosis.key)) { - acc[diagnosis.key] = { - medication: { ...diagnosis.details }, - }; - } else { - acc.otherCondition = acc.otherCondition || []; - acc.otherCondition.push({ - medication: { - illness: diagnosis.key, - ...diagnosis.details, - }, - }); - } - return acc; - }, {}), + data: diagnoses.reduce( + (acc, diagnosis) => { + if (fixedDiagnosesKeys.includes(diagnosis.key)) { + acc[diagnosis.key] = { + medication: { ...diagnosis.details }, + }; + } else { + if (!acc.otherCondition) { + acc.otherCondition = []; + } + acc.otherCondition.push({ + medication: { + illness: diagnosis.key, + ...diagnosis.details, + }, + }); + } + return acc; + }, + { + // Inicializar otherCondition como arreglo vacío si no existe + otherCondition: [], + }, + ), }; const handleSaveGynecologicalHistory = async () => { @@ -1250,7 +1258,7 @@ function ObGynView({ data: { hysterectomy: structuredOperations.hysterectomy || {}, sterilizationSurgery: structuredOperations.sterilization || {}, - ovarianCystsSurgery: structuredOperations.ovarianCysts || null, + ovarianCystsSurgery: structuredOperations.ovarianCysts || [], breastMassResection: structuredOperations.breastMassResection || [], }, }, @@ -1443,181 +1451,203 @@ function ObGynView({
-
-

- # Embarazos: -

- -

- {" "} - ={" "} + Para aumentar y disminuir el número de partos, cesáreas y + abortos, puedes utilizar las flechas arriba y abajo de tu + teclado

+
+

+ # Embarazos: +

+ +

- # Partos vaginales + {" "} + ={" "}

- { - const n = Number(e.target.value) || 0; - setP(n < initialP ? initialP : n); - }} - readOnly={!isEditable} - placeholder="# vía vaginal" +
-
-

- {" "} - +{" "} -

-
+ > +

+ # Partos vaginales +

+ { + const n = Number(e.target.value) || 0; + setP(n < initialP ? initialP : n); + }} + readOnly={!isEditable} + placeholder="# vía vaginal" + style={{ + width: "100%", + height: "2.5rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

- # Cesáreas + {" "} + +{" "}

- { - const n = Number(e.target.value) || 0; - setC(n < initialC ? initialC : n); - }} - readOnly={!isEditable} - placeholder="# cesáreas" +
-
-

- {" "} - +{" "} -

-
+ > +

+ # Cesáreas +

+ { + const n = Number(e.target.value) || 0; + setC(n < initialC ? initialC : n); + }} + readOnly={!isEditable} + placeholder="# cesáreas" + style={{ + width: "100%", + height: "2.5rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

- # Abortos: + {" "} + +{" "}

- { - const n = Number(e.target.value); - setA(n < initialA ? initialA : n); - }} - readOnly={!isEditable} - placeholder="# abortos" +
+ > +

+ # Abortos: +

+ { + const n = Number(e.target.value); + setA(n < initialA ? initialA : n); + }} + readOnly={!isEditable} + placeholder="# abortos" + style={{ + width: "100%", + height: "2.5rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +