Skip to content

Commit

Permalink
fix: suspicious error on gyneco (#317)
Browse files Browse the repository at this point in the history
# 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

<!-- Asegúrate de cumplir todas estas tareas antes de hacer la PR. -->

- \[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 <[email protected]>
  • Loading branch information
XavierLopez25 and ElrohirGT authored Nov 16, 2024
1 parent 4e07ea7 commit 2cefc0b
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 229 deletions.
20 changes: 0 additions & 20 deletions sanitas_backend/layers/utils/utils/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
decodeJWT,
createResponse,
mapToAPINonPathologicalHistory,
checkForUnauthorizedChangesPathological,
toSafeEvent,
} from "utils/index.mjs";

Expand Down Expand Up @@ -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 = `
Expand Down
32 changes: 26 additions & 6 deletions sanitas_frontend/src/components/Input/Base/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -454,7 +454,7 @@ function NonPathologicalView({
}
};

const areAllFieldsPreFilled = () => {
const _areAllFieldsPreFilled = () => {
const smokerData =
nonPathologicalHistoryResult.result?.medicalHistory.smoker.data;
const drinkData =
Expand Down Expand Up @@ -595,14 +595,12 @@ function NonPathologicalView({
checked={smokingStatus}
onChange={() => handleSmokingChange(true)}
label="Sí"
disabled={!isSmokingEditable}
/>
<RadioInput
name="smoking"
checked={!smokingStatus}
onChange={() => handleSmokingChange(false)}
label="No"
disabled={!isSmokingEditable}
/>
</div>
{smokingStatus && (
Expand All @@ -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 }}
/>
</div>
Expand All @@ -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 }}
/>
</div>
Expand Down Expand Up @@ -676,14 +672,12 @@ function NonPathologicalView({
checked={alcoholConsumption}
onChange={() => handleAlcoholChange(true)}
label="Sí"
disabled={!isAlcoholEditable}
/>
<RadioInput
name="alcoholConsumption"
checked={!alcoholConsumption}
onChange={() => handleAlcoholChange(false)}
label="No"
disabled={!isAlcoholEditable}
/>
</div>
{alcoholConsumption && (
Expand Down Expand Up @@ -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 }}
/>
</div>
Expand Down Expand Up @@ -748,14 +741,12 @@ function NonPathologicalView({
checked={drugUse}
onChange={() => handleDrugUseChange(true)}
label="Sí"
disabled={!isDrugUseEditable}
/>
<RadioInput
name="drugUse"
checked={!drugUse}
onChange={() => handleDrugUseChange(false)}
label="No"
disabled={!isDrugUseEditable}
/>
</div>
{drugUse && (
Expand All @@ -777,7 +768,6 @@ function NonPathologicalView({
onChange={(e) => setDrugType(e.target.value)}
placeholder="Ingrese el tipo de droga"
min="1"
readOnly={!isDrugUseEditable}
style={{ ...baseInput }}
/>
</div>
Expand All @@ -788,7 +778,6 @@ function NonPathologicalView({
value={drugFrequency}
onChange={(e) => setDrugFrequency(e.target.value)}
placeholder="Ingrese la frecuencia del consumo"
readOnly={!isDrugUseEditable}
style={{ ...baseInput }}
/>
</div>
Expand All @@ -797,29 +786,25 @@ function NonPathologicalView({
)}
</div>

{!areAllFieldsPreFilled() && (
<>
<div
style={{
borderBottom: `0.04rem solid ${colors.darkerGrey}`,
}}
/>
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
padding: "2rem 0 1rem 0",
}}
>
<BaseButton
text="Guardar"
onClick={handleSaveNonPathological}
style={{ width: "30%", height: "3rem" }}
/>
</div>
</>
)}
<div
style={{
borderBottom: `0.04rem solid ${colors.darkerGrey}`,
}}
/>
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
padding: "2rem 0 1rem 0",
}}
>
<BaseButton
text="Guardar"
onClick={handleSaveNonPathological}
style={{ width: "30%", height: "3rem" }}
/>
</div>
</>
)}
</div>
Expand Down
Loading

0 comments on commit 2cefc0b

Please sign in to comment.