From 15c81f9c20e033d870112d815d0349d371e5178d Mon Sep 17 00:00:00 2001 From: DanielDubon Date: Fri, 23 Aug 2024 20:00:50 -0600 Subject: [PATCH 1/6] feat: git init base UI was made(only base UI working PRE BETA) --- .../src/views/History/Psichiatric/index.jsx | 518 ++++++++++-------- 1 file changed, 292 insertions(+), 226 deletions(-) diff --git a/sanitas_frontend/src/views/History/Psichiatric/index.jsx b/sanitas_frontend/src/views/History/Psichiatric/index.jsx index 67523cd8..5e59ef27 100644 --- a/sanitas_frontend/src/views/History/Psichiatric/index.jsx +++ b/sanitas_frontend/src/views/History/Psichiatric/index.jsx @@ -147,8 +147,27 @@ function PsichiatricView({ const [showOtherInput, setShowOtherInput] = useState(false); + const [depressionStatus, setDepressionStatus] = useState(false); + const [anxietyStatus, setAnxietyStatus] = useState(false); + const [medication, setMedication] = useState(""); + const [dose, setDose] = useState(""); + const [frequency, setFrequency] = useState(""); + const [ubeStatus, setUbeStatus] = useState(false); + const psichiatricHistoryResult = psichiatricHistoryResource.read(); + const { + depression = { data: [{ smokes: false, cigarettesPerDay: "", years: "" }] }, + anxiety = { data: [{ drinks: false, drinksPerMonth: "" }] }, + ocd = { data: [{ usesDrugs: false, drugType: "", frequency: "" }] }, + } = psichiatricHistoryResult.result?.medicalHistory || {}; + + const isFirstTime = !( + depression.data.length || + anxiety.data.length || + ocd.data.length + ); + const [isEditable, setIsEditable] = useState(isFirstTime); let errorMessage = ""; if (psichiatricHistoryResult.error) { @@ -344,19 +363,7 @@ function PsichiatricView({ overflowY: "auto", }} > -
- -
- - {errorMessage && ( + {errorMessage ? (
{errorMessage}
- )} - - {noPsichiatricData && !errorMessage ? ( -

- ¡Parece que no hay antecedentes psiquiátricos! Agrega uno en el - botón de arriba. -

) : ( - Object.keys(PsichiatricHistory || {}).map((category) => { - const historyData = PsichiatricHistory[category]?.data; - - // Verifica si hay datos válidos en los campos antes de renderizar la tarjeta - if ( - historyData?.medication || - historyData?.dose || - historyData?.frecuency - ) { - if (!(historyData?.ill === "")) { - return ( - handleOnClickCard(category, historyData)} + <> + {isFirstTime && ( +
+ Por favor, ingrese los datos del paciente. Parece que es su + primera visita aquí. +
+ )} +
+
+

+ ¿Tiene depresion? +

+
+ handleFieldChange("ube", true)} + style={{ label: { fontFamily: fonts.textFont } }} /> - ); - } - - return ( - handleOnClickCard(category, historyData)} + handleFieldChange("ube", false)} + style={{ label: { fontFamily: fonts.textFont } }} + /> +
+
+ {!isFirstTime && + (isEditable ? ( +
+ + { + setIsEditable(false); + }} + /> +
+ ) : ( + setIsEditable(true)} + /> + ))} +
+
+

+ ¿Fuma? +

+
+ handleSmokingChange(true)} + label="Sí" + disabled={!isEditable} /> - ); - } - - return null; // Si no hay datos válidos, no renderiza nada - }) - )} -
+ handleSmokingChange(false)} + label="No" + disabled={!isEditable} + /> +
+ {depressionStatus && ( +
+
+
+

+ ¿Cuántos cigarrillos al día? +

+ setCigarettesPerDay(e.target.value)} + placeholder="Ingrese cuántos cigarrillos al día" + min="1" + readOnly={!isEditable} + style={{ + width: "20rem", + height: "2.5rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +
+
+

+ ¿Desde hace cuántos años? +

+ setSmokingYears(e.target.value)} + placeholder="Ingrese desde hace cuántos años" + min="1" + readOnly={!isEditable} + style={{ + width: "20rem", + height: "2.5rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +
+
+
+ )} + - {addingNew || selectedHistory ? ( -
-

- Seleccione la enfermedad: -

- handleFieldChange("selectedIll", e.target.value)} - style={{ - container: { width: "80%" }, - select: {}, - option: {}, - indicator: {}, - }} - /> - {showOtherInput && ( -
+

- Nombre de la enfermedad: + ¿Consumes bebidas alcohólicas?

- handleFieldChange("ill", e.target.value)} - placeholder="Ingrese el nombre de la enfermedad" +
+ > + handleAlcoholChange(true)} + label="Sí" + disabled={!isEditable} + /> + handleAlcoholChange(false)} + label="No" + disabled={!isEditable} + /> +
+ {anxietyStatus && ( +
+
+
+

+ ¿Cuántas bebidas alcohólicas consumes al mes? +

+ setDrinksPerMonth(e.target.value)} + placeholder="Ingrese cuántas bebidas al mes" + min="1" + readOnly={!isEditable} + style={{ + width: "20rem", + height: "2.5rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +
+
+
+ )}
- )} - -

- Medicamento: -

- handleFieldChange("medication", e.target.value)} - placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" - style={{ - width: "80%", - height: "2.5rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Dosis: -

- handleFieldChange("dose", e.target.value)} - placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" - style={{ - width: "80%", - height: "2.5rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Frecuencia: -

- handleFieldChange("frecuency", e.target.value)} - placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" - style={{ - width: "80%", - height: "2.5rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- ¿Tiene seguimiento en UBE? -

-
- handleFieldChange("ube", true)} - style={{ label: { fontFamily: fonts.textFont } }} - /> - handleFieldChange("ube", false)} - style={{ label: { fontFamily: fonts.textFont } }} - /> -
-
- {addingNew && ( - <> +
+ {isFirstTime && ( +
-
- - +
)} -
-
- ) : null} + + )} +
); } From 0480da54d11f60e0cf21a0976da41dccc64a7f33 Mon Sep 17 00:00:00 2001 From: DanielDubon Date: Sat, 24 Aug 2024 20:06:34 -0600 Subject: [PATCH 2/6] feat: base UI finished, test aren't working --- .../src/views/History/Psichiatric/index.jsx | 1711 +++++++++++++---- 1 file changed, 1383 insertions(+), 328 deletions(-) diff --git a/sanitas_frontend/src/views/History/Psichiatric/index.jsx b/sanitas_frontend/src/views/History/Psichiatric/index.jsx index 5e59ef27..a989cf55 100644 --- a/sanitas_frontend/src/views/History/Psichiatric/index.jsx +++ b/sanitas_frontend/src/views/History/Psichiatric/index.jsx @@ -1,10 +1,12 @@ import { Suspense, useEffect, useState } from "react"; import "react-toastify/dist/ReactToastify.css"; import { toast } from "react-toastify"; +import CheckIcon from "@tabler/icons/outline/check.svg"; +import EditIcon from "@tabler/icons/outline/edit.svg"; +import CancelIcon from "@tabler/icons/outline/x.svg"; import BaseButton from "src/components/Button/Base/index"; import DashboardSidebar from "src/components/DashboardSidebar"; -import DropdownMenu from "src/components/DropdownMenu"; -import InformationCard from "src/components/InformationCard"; +import IconButton from "src/components/Button/Icon"; import { BaseInput, RadioInput } from "src/components/Input/index"; import Throbber from "src/components/Throbber"; import { colors, fonts, fontSize } from "src/theme.mjs"; @@ -142,25 +144,64 @@ function PsichiatricView({ psichiatricHistoryResource, updatePsichiatricHistory, }) { - const [selectedHistory, setSelectedHistory] = useState(null); - const [addingNew, setAddingNew] = useState(false); + const psichiatricHistoryResult = psichiatricHistoryResource.read(); + const psichiatricHistoryData = psichiatricHistoryResult.result || {}; - const [showOtherInput, setShowOtherInput] = useState(false); + const medicalHistory = psichiatricHistoryData?.medicalHistory || { + depression: { data: [] }, + anxiety: { data: [] }, + ocd: { data: [] }, + adhd: { data: [] }, + bipolar: { data: [] }, + other: { data: [] }, + }; - const [depressionStatus, setDepressionStatus] = useState(false); - const [anxietyStatus, setAnxietyStatus] = useState(false); - const [medication, setMedication] = useState(""); - const [dose, setDose] = useState(""); - const [frequency, setFrequency] = useState(""); - const [ubeStatus, setUbeStatus] = useState(false); + const { + depression = { + data: [{ medication: "", dose: "", frequency: "", ube: false }], + }, + anxiety = { + data: [{ medication: "", dose: "", frequency: "", ube: false }], + }, + ocd = { data: [{ medication: "", dose: "", frequency: "", ube: false }] }, + adhd = { data: [{ medication: "", dose: "", frequency: "", ube: false }] }, + bipolar = { + data: [{ medication: "", dose: "", frequency: "", ube: false }], + }, + other = { + data: [ + { illness: "", medication: "", dose: "", frequency: "", ube: false }, + ], + }, + } = medicalHistory; - const psichiatricHistoryResult = psichiatricHistoryResource.read(); + const [depressionStatus, setDepressionStatus] = useState( + depression.data.length > 0, + ); + const [anxietyStatus, setAnxietyStatus] = useState(anxiety.data.length > 0); + const [TOCStatus, setTOCStatus] = useState(ocd.data.length > 0); + const [TDAHStatus, setTDAHStatus] = useState(adhd.data.length > 0); + const [BipolarStatus, setBipolarStatus] = useState(bipolar.data.length > 0); + const [OtherStatus, setOtherStatus] = useState(bipolar.data.length > 0); - const { - depression = { data: [{ smokes: false, cigarettesPerDay: "", years: "" }] }, - anxiety = { data: [{ drinks: false, drinksPerMonth: "" }] }, - ocd = { data: [{ usesDrugs: false, drugType: "", frequency: "" }] }, - } = psichiatricHistoryResult.result?.medicalHistory || {}; + useEffect(() => { + const hasData = (condition) => { + return ( + condition.data.length > 0 && + (condition.data[0].medication || + condition.data[0].dose || + condition.data[0].frequency || + condition.data[0].ube) + ); + }; + + setDepressionStatus(hasData(depression)); + setAnxietyStatus(hasData(anxiety)); + setTOCStatus(hasData(ocd)); + setTDAHStatus(hasData(adhd)); + setBipolarStatus(hasData(bipolar)); + setOtherStatus(other.data.length > 0 && other.data[0].illness); + }, [depression, anxiety, ocd, adhd, bipolar, other]); const isFirstTime = !( depression.data.length || @@ -189,158 +230,396 @@ function PsichiatricView({ } } - const psichiatricHistoryData = psichiatricHistoryResult.result; - - const [PsichiatricHistory, setPsichiatricHistory] = useState( - psichiatricHistoryData?.medicalHistory || {}, - ); - - // No allergic data in API - - const noPsichiatricData = !Object.values(PsichiatricHistory).some( - (category) => category?.data?.medication, - ); + // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Ignoring complexity for this function + const validateInputs = () => { + // Validar Depresión + if (depressionStatus) { + if (!depressionMedication) { + toast.error("Por favor, ingresa el medicamento para la depresión."); + return false; + } + if (!depressionFrequency) { + toast.error("Por favor, ingresa la frecuencia para la depresión."); + return false; + } + } - useEffect(() => {}, []); - - // Event handlers for adding, editing, and saving allergic history records - const handleOpenNewForm = () => { - setShowOtherInput(false); - setSelectedHistory({ - selectedIll: "depression", - medication: "", - ill: "", - dose: "", - frecuency: "", - ube: false, - whichHistory: "", - }); - setAddingNew(true); - }; + // Validar Ansiedad + if (anxietyStatus) { + if (!anxietyMedication) { + toast.error("Por favor, ingresa el medicamento para la ansiedad."); + return false; + } + if (!anxietyFrequency) { + toast.error("Por favor, ingresa la frecuencia para la ansiedad."); + return false; + } + } - // Save the new Allergic record to the database - // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Ignoring complexity for this function - const handleSaveNewHistory = async () => { - setShowOtherInput(false); - if (selectedHistory.selectedIll === "other") { - if (!selectedHistory.ill) { - toast.error("Complete todos los campos requeridos."); - setShowOtherInput(true); - return; + // Validar TOC (Trastorno Obsesivo Compulsivo) + if (TOCStatus) { + if (!TOCMedication) { + toast.error("Por favor, ingresa el medicamento para el TOC."); + return false; + } + if (!TOCFrequency) { + toast.error("Por favor, ingresa la frecuencia para el TOC."); + return false; } } - if ( - !( - selectedHistory.selectedIll && - selectedHistory.medication && - selectedHistory.frecuency - ) - ) { - if (selectedHistory.selectedIll === "other") { - toast.error("Complete todos los campos requeridos."); - setShowOtherInput(true); - return; + + // Validar TDAH (Trastorno por Déficit de Atención e Hiperactividad) + if (TDAHStatus) { + if (!TDAHMedication) { + toast.error("Por favor, ingresa el medicamento para el TDAH."); + return false; + } + if (!TDAHFrequency) { + toast.error("Por favor, ingresa la frecuencia para el TDAH."); + return false; } + } - toast.error("Complete todos los campos requeridos."); - return; + // Validar Trastorno Bipolar + if (BipolarStatus) { + if (!bipolarMedication) { + toast.error( + "Por favor, ingresa el medicamento para el trastorno bipolar.", + ); + return false; + } + if (!bipolarFrequency) { + toast.error( + "Por favor, ingresa la frecuencia para el trastorno bipolar.", + ); + return false; + } } - toast.info("Guardando antecedente psiquiátrico..."); + // Validar Otros + if (OtherStatus) { + if (!otherIllness) { + toast.error("Por favor, ingresa la condición en Otros."); + return false; + } + if (!otherMedication) { + toast.error( + "Por favor, ingresa el medicamento para la condición en Otros.", + ); + return false; + } + if (!otherFrequency) { + toast.error( + "Por favor, ingresa la frecuencia para la condición en Otros.", + ); + return false; + } + } - // Crear el nuevo registro de alergia - const newHistoryData = { - ill: selectedHistory.ill, - medication: selectedHistory.medication, - dose: selectedHistory.dose, - frecuency: selectedHistory.frecuency, - ube: selectedHistory.ube, - }; + // Si todas las validaciones pasan, retornar true + return true; + }; - // Obtener la categoría actual (ej. medicamento, comida, etc.) - const currentCategoryData = - PsichiatricHistory[selectedHistory.selectedIll]?.data || {}; + // Save the new Allergic record to the database - // Si la categoría ya tiene datos, usamos su versión, de lo contrario, establecemos la versión en 1 - const currentVersion = - PsichiatricHistory[selectedHistory.selectedIll]?.version || 1; + const handleSaveNewHistory = async () => { + // Validación de entradas antes de intentar guardar + if (!validateInputs()) return; - // Actualizar la categoría con el nuevo registro - const updatedCategory = { - version: currentVersion, - data: { ...currentCategoryData, ...newHistoryData }, - }; + // Mostrar mensaje de carga + toast.info("Guardando antecedentes psiquiátricos..."); - // Actualizar el historial médico con la nueva categoría - const updatedMedicalHistory = { - ...PsichiatricHistory, - [selectedHistory.selectedIll]: updatedCategory, + // Construir el objeto newHistoryData usando los estados actuales + const newHistoryData = { + depression: { + version: medicalHistory.depression.version || 1, + data: [ + { + medication: depressionMedication, + dose: depressionDose, + frequency: depressionFrequency, + ube: depressionUBE, + }, + ], + }, + anxiety: { + version: medicalHistory.anxiety.version || 1, + data: [ + { + medication: anxietyMedication, + dose: anxietyDose, + frequency: anxietyFrequency, + ube: anxietyUBE, + }, + ], + }, + ocd: { + version: medicalHistory.ocd.version || 1, + data: [ + { + medication: TOCMedication, + dose: TOCDose, + frequency: TOCFrequency, + ube: TOCUBE, + }, + ], + }, + adhd: { + version: medicalHistory.adhd.version || 1, + data: [ + { + medication: TDAHMedication, + dose: TDAHDose, + frequency: TDAHFrequency, + ube: TDAHUBE, + }, + ], + }, + bipolar: { + version: medicalHistory.bipolar.version || 1, + data: [ + { + medication: bipolarMedication, + dose: bipolarDose, + frequency: bipolarFrequency, + ube: bipolarUBE, + }, + ], + }, + other: { + version: medicalHistory.other.version || 1, + data: [ + { + illness: otherIllness, + medication: otherMedication, + dose: otherDose, + frequency: otherFrequency, + ube: otherUBE, + }, + ], + }, }; try { - const response = await updatePsichiatricHistory( - id, - updatedMedicalHistory, - ); - if (!response.error) { - setPsichiatricHistory(updatedMedicalHistory); - setAddingNew(false); - setSelectedHistory(null); - toast.success("Antecedente psiquiátrico guardado con éxito."); + const result = await updatePsichiatricHistory(id, newHistoryData); + if (!result.error) { + toast.success("Antecedentes psiquiátricos guardados con éxito."); + setIsEditable(false); + setDepressionStatus(newHistoryData.depression.data.length > 0); + setAnxietyStatus(newHistoryData.anxiety.data.length > 0); + setTOCStatus(newHistoryData.ocd.data.length > 0); + setTDAHStatus(newHistoryData.adhd.data.length > 0); + setBipolarStatus(newHistoryData.bipolar.data.length > 0); + setOtherStatus(newHistoryData.other.data.length > 0); } else { - toast.error(`Error al guardar: ${response.error}`); + toast.error(`Error al guardar los antecedentes: ${result.error}`); } } catch (error) { toast.error(`Error en la operación: ${error.message}`); } }; - const handleFieldChange = (fieldName, value) => { - setSelectedHistory((prevHistory) => ({ - ...prevHistory, - [fieldName]: value, - })); - - // Handling the "Otros" option to show the additional input - if (fieldName === "selectedIll" && value === "other") { - setShowOtherInput(true); - } else if (fieldName === "selectedIll") { - setShowOtherInput(false); + const [depressionMedication, setDepressionMedication] = useState( + depression.data.length > 0 && depression.data[0].medication != null + ? depression.data[0].medication + : "", + ); + + const [depressionDose, setDepressionDose] = useState( + depression.data.length > 0 && depression.data[0].dose != null + ? depression.data[0].dose + : "", + ); + + const [depressionFrequency, setDepressionFrequency] = useState( + depression.data.length > 0 && depression.data[0].frequency != null + ? depression.data[0].frequency + : "", + ); + + const [depressionUBE, setDepressionUBE] = useState( + depression.data.length > 0 && depression.data[0].ube != null + ? depression.data[0].ube + : false, + ); + + const [anxietyMedication, setAnxietyMedication] = useState( + anxiety.data.length > 0 && anxiety.data[0].medication != null + ? anxiety.data[0].medication + : "", + ); + + const [anxietyDose, setAnxietyDose] = useState( + anxiety.data.length > 0 && anxiety.data[0].dose != null + ? anxiety.data[0].dose + : "", + ); + + const [anxietyFrequency, setAnxietyFrequency] = useState( + anxiety.data.length > 0 && anxiety.data[0].frequency != null + ? anxiety.data[0].frequency + : "", + ); + + const [anxietyUBE, setAnxietyUBE] = useState( + anxiety.data.length > 0 && anxiety.data[0].ube != null + ? anxiety.data[0].ube + : false, + ); + + const [TOCMedication, setTOCMedication] = useState( + ocd.data.length > 0 && ocd.data[0].medication != null + ? ocd.data[0].medication + : "", + ); + + const [TOCDose, setTOCDose] = useState( + ocd.data.length > 0 && ocd.data[0].dose != null ? ocd.data[0].dose : "", + ); + + const [TOCFrequency, setTOCFrequency] = useState( + ocd.data.length > 0 && ocd.data[0].frequency != null + ? ocd.data[0].frequency + : "", + ); + + const [TOCUBE, setTOCUBE] = useState( + ocd.data.length > 0 && ocd.data[0].ube != null ? ocd.data[0].ube : false, + ); + + const [TDAHMedication, setTDAHMedication] = useState( + adhd.data.length > 0 && adhd.data[0].medication != null + ? adhd.data[0].medication + : "", + ); + + const [TDAHDose, setTDAHDose] = useState( + adhd.data.length > 0 && adhd.data[0].dose != null ? adhd.data[0].dose : "", + ); + + const [TDAHFrequency, setTDAHFrequency] = useState( + adhd.data.length > 0 && adhd.data[0].frequency != null + ? adhd.data[0].frequency + : "", + ); + + const [TDAHUBE, setTDAHUBE] = useState( + adhd.data.length > 0 && adhd.data[0].ube != null ? adhd.data[0].ube : false, + ); + + const [bipolarMedication, setBipolarMedication] = useState( + bipolar.data.length > 0 && bipolar.data[0].medication != null + ? bipolar.data[0].medication + : "", + ); + + const [bipolarDose, setBipolarDose] = useState( + bipolar.data.length > 0 && bipolar.data[0].dose != null + ? bipolar.data[0].dose + : "", + ); + + const [bipolarFrequency, setBipolarFrequency] = useState( + bipolar.data.length > 0 && bipolar.data[0].frequency != null + ? bipolar.data[0].frequency + : "", + ); + + const [bipolarUBE, setBipolarUBE] = useState( + bipolar.data.length > 0 && bipolar.data[0].ube != null + ? bipolar.data[0].ube + : false, + ); + + const [otherIllness, setOtherIllness] = useState( + other.data.length > 0 && other.data[0].illness != null + ? other.data[0].illness + : "", + ); + + const [otherMedication, setOtherMedication] = useState( + other.data.length > 0 && other.data[0].medication != null + ? other.data[0].medication + : "", + ); + + const [otherDose, setOtherDose] = useState( + other.data.length > 0 && other.data[0].dose != null + ? other.data[0].dose + : "", + ); + + const [otherFrequency, setOtherFrequency] = useState( + other.data.length > 0 && other.data[0].frequency != null + ? other.data[0].frequency + : "", + ); + + const [otherUBE, setOtherUBE] = useState( + other.data.length > 0 && other.data[0].ube != null + ? other.data[0].ube + : false, + ); + + const handleDepressionChange = (newStatus) => { + setDepressionStatus(newStatus); + if (!newStatus) { + setDepressionMedication(""); // Clear fields when "No" is selected + setDepressionDose(""); + setDepressionFrequency(""); + setDepressionUBE(false); + } + }; + + const handleAnxietyChange = (newStatus) => { + setAnxietyStatus(newStatus); + if (!newStatus) { + setAnxietyMedication(""); + setAnxietyDose(""); + setAnxietyFrequency(""); + setAnxietyUBE(false); } }; - const handleCancel = () => { - setSelectedHistory(null); - setAddingNew(false); + + const handleTOCChange = (newStatus) => { + setTOCStatus(newStatus); + if (!newStatus) { + setTOCMedication(""); + setTOCDose(""); + setTOCFrequency(""); + setTOCUBE(false); + } }; - const handleOnClickCard = (category, historyData) => { - if (category === "other") { - setShowOtherInput(true); - } else { - setShowOtherInput(false); + const handleTDAHChange = (newStatus) => { + setTDAHStatus(newStatus); + if (!newStatus) { + setTDAHMedication(""); + setTDAHDose(""); + setTDAHFrequency(""); + setTDAHUBE(false); } - setSelectedHistory({ selectedIll: category, ...historyData }); }; - const medicalHistoryOptions = [ - { label: "Depresión", value: "depression" }, - { label: "Ansiedad", value: "anxiety" }, - { label: "TOC (Trastorno Obsesivo Compulsivo)", value: "ocd" }, - { - label: "TDAH (Trastorno por Déficit de Atención e Hiperactividad)", - value: "adhd", - }, - { label: "Trastorno Bipolar", value: "bipolar" }, - { label: "Otros", value: "other" }, - ]; - - const categoryTranslations = { - depression: "Depresión", - anxiety: "Ansiedad", - ocd: "TOC (Trastorno Obsesivo Compulsivo)", - adhd: "TDAH (Trastorno por Déficit de Atención e Hiperactividad)", - bipolar: "Trastorno Bipolar", - other: "Otros", + const handleBipolarChange = (newStatus) => { + setBipolarStatus(newStatus); + if (!newStatus) { + setBipolarMedication(""); + setBipolarDose(""); + setBipolarFrequency(""); + setBipolarUBE(false); + } + }; + + const handleOtherChange = (newStatus) => { + setOtherStatus(newStatus); + if (!newStatus) { + setOtherIllness(""); + setOtherMedication(""); + setOtherDose(""); + setOtherFrequency(""); + setOtherUBE(false); + } }; return ( @@ -392,13 +671,41 @@ function PsichiatricView({ primera visita aquí. )} +
+ {!isFirstTime && + (isEditable ? ( +
+ + { + setIsEditable(false); + }} + /> +
+ ) : ( + setIsEditable(true)} + /> + ))} +
@@ -425,144 +732,133 @@ function PsichiatricView({ gap: "1rem", alignItems: "center", paddingLeft: "0.5rem", - paddingBottom: "2rem", + paddingBottom: "0.5rem", }} > handleFieldChange("ube", true)} - style={{ label: { fontFamily: fonts.textFont } }} + name="depression" + checked={depressionStatus} + onChange={() => handleDepressionChange(true)} + label="Sí" + disabled={!isEditable} /> handleDepressionChange(false)} label="No" - name="ube" - checked={selectedHistory?.ube === false} - onChange={() => handleFieldChange("ube", false)} - style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} />
- {!isFirstTime && - (isEditable ? ( -
- - { - setIsEditable(false); - }} - /> -
- ) : ( - setIsEditable(true)} - /> - ))} - -
-

- ¿Fuma? -

-
- handleSmokingChange(true)} - label="Sí" - disabled={!isEditable} - /> - handleSmokingChange(false)} - label="No" - disabled={!isEditable} - /> -
+ {depressionStatus && ( -
+
+

+ Medicamento: +

+ setDepressionMedication(e.target.value)} + placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Dosis: +

+ setDepressionDose(e.target.value)} + placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Frecuencia: +

+ setDepressionFrequency(e.target.value)} + placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ ¿Tiene seguimiento en UBE? +

-
-

- ¿Cuántos cigarrillos al día? -

- setCigarettesPerDay(e.target.value)} - placeholder="Ingrese cuántos cigarrillos al día" - min="1" - readOnly={!isEditable} - style={{ - width: "20rem", - height: "2.5rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -
-
-

- ¿Desde hace cuántos años? -

- setSmokingYears(e.target.value)} - placeholder="Ingrese desde hace cuántos años" - min="1" - readOnly={!isEditable} - style={{ - width: "20rem", - height: "2.5rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -
+ setDepressionUBE(true)} + style={{ label: { fontFamily: fonts.textFont } }} + /> + setDepressionUBE(false)} + style={{ label: { fontFamily: fonts.textFont } }} + />
)} @@ -570,87 +866,846 @@ function PsichiatricView({
-

- ¿Consumes bebidas alcohólicas? -

- handleAlcoholChange(true)} - label="Sí" - disabled={!isEditable} - /> - handleAlcoholChange(false)} - label="No" - disabled={!isEditable} - /> +

+ ¿Tiene ansiedad? +

+
+ handleAnxietyChange(true)} + label="Sí" + disabled={!isEditable} + /> + handleAnxietyChange(false)} + label="No" + disabled={!isEditable} + /> +
+ {anxietyStatus && ( -
-
+

-

-

- ¿Cuántas bebidas alcohólicas consumes al mes? -

- setDrinksPerMonth(e.target.value)} - placeholder="Ingrese cuántas bebidas al mes" - min="1" - readOnly={!isEditable} - style={{ - width: "20rem", - height: "2.5rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -
-
-
- )} -
- -
+ setAnxietyMedication(e.target.value)} + placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Dosis: +

+ setAnxietyDose(e.target.value)} + placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Frecuencia: +

+ setAnxietyFrequency(e.target.value)} + placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ ¿Tiene seguimiento en UBE? +

+
+ setAnxietyUBE(true)} + style={{ label: { fontFamily: fonts.textFont } }} + /> + setAnxietyUBE(false)} + style={{ label: { fontFamily: fonts.textFont } }} + /> +
+
+ )} +
+ +
+
+

+ ¿Tiene trastorno obsesivo compulsivo? +

+
+ handleTOCChange(true)} + label="Sí" + disabled={!isEditable} + /> + handleTOCChange(false)} + label="No" + disabled={!isEditable} + /> +
+
+ + {TOCStatus && ( +
+

+ Medicamento: +

+ setTOCMedication(e.target.value)} + placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Dosis: +

+ setTOCDose(e.target.value)} + placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Frecuencia: +

+ setTOCFrequency(e.target.value)} + placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ ¿Tiene seguimiento en UBE? +

+
+ setTOCUBE(true)} + style={{ label: { fontFamily: fonts.textFont } }} + /> + setTOCUBE(false)} + style={{ label: { fontFamily: fonts.textFont } }} + /> +
+
+ )} +
+ +
+
+

+ ¿Tiene TDAH (Trastorno por Déficit de Atención e + Hiperactivida)? +

+
+ handleTDAHChange(true)} + label="Sí" + disabled={!isEditable} + /> + handleTDAHChange(false)} + label="No" + disabled={!isEditable} + /> +
+
+ + {TDAHStatus && ( +
+

+ Medicamento: +

+ setTDAHMedication(e.target.value)} + placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Dosis: +

+ setTDAHDose(e.target.value)} + placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Frecuencia: +

+ setTDAHFrequency(e.target.value)} + placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ ¿Tiene seguimiento en UBE? +

+
+ setTDAHUBE(true)} + style={{ label: { fontFamily: fonts.textFont } }} + /> + setTDAHUBE(false)} + style={{ label: { fontFamily: fonts.textFont } }} + /> +
+
+ )} +
+ +
+
+

+ ¿Tiene trastorno bipolar? +

+
+ handleBipolarChange(true)} + label="Sí" + disabled={!isEditable} + /> + handleBipolarChange(false)} + label="No" + disabled={!isEditable} + /> +
+
+ + {BipolarStatus && ( +
+

+ Medicamento: +

+ setBipolarMedication(e.target.value)} + placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Dosis: +

+ setBipolarDose(e.target.value)} + placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Frecuencia: +

+ setBipolarFrequency(e.target.value)} + placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ ¿Tiene seguimiento en UBE? +

+
+ setBipolarUBE(true)} + style={{ label: { fontFamily: fonts.textFont } }} + /> + setBipolarUBE(false)} + style={{ label: { fontFamily: fonts.textFont } }} + /> +
+
+ )} +
+ +
+ > +
+

+ ¿Otro? +

+
+ handleOtherChange(true)} + label="Sí" + disabled={!isEditable} + /> + handleOtherChange(false)} + label="No" + disabled={!isEditable} + /> +
+
+ + {OtherStatus && ( +
+

+ ¿Cuál es la condición? +

+ setOtherIllness(e.target.value)} + placeholder="Ingrese la condición" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Medicamento: +

+ setOtherMedication(e.target.value)} + placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Dosis: +

+ setOtherDose(e.target.value)} + placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Frecuencia: +

+ setOtherFrequency(e.target.value)} + placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ ¿Tiene seguimiento en UBE? +

+
+ setOtherUBE(true)} + style={{ label: { fontFamily: fonts.textFont } }} + /> + setOtherUBE(false)} + style={{ label: { fontFamily: fonts.textFont } }} + /> +
+
+ )} +
+ {isFirstTime && (
Date: Sun, 25 Aug 2024 02:58:24 -0600 Subject: [PATCH 3/6] feat: UI UPDATE with add more meds is working everything done, lint pending and UI tests --- .../src/views/History/Psichiatric/index.jsx | 1634 ++++++++++------- 1 file changed, 995 insertions(+), 639 deletions(-) diff --git a/sanitas_frontend/src/views/History/Psichiatric/index.jsx b/sanitas_frontend/src/views/History/Psichiatric/index.jsx index a989cf55..91d2fd8a 100644 --- a/sanitas_frontend/src/views/History/Psichiatric/index.jsx +++ b/sanitas_frontend/src/views/History/Psichiatric/index.jsx @@ -147,6 +147,108 @@ function PsichiatricView({ const psichiatricHistoryResult = psichiatricHistoryResource.read(); const psichiatricHistoryData = psichiatricHistoryResult.result || {}; + const [depressionMedications, setDepressionMedications] = useState([ + { medication: "", dose: "", frequency: "" }, + ]); + + const addDepressionMedication = () => { + setDepressionMedications([ + ...depressionMedications, + { medication: "", dose: "", frequency: "" }, + ]); + }; + + const handleDepressionMedicationChange = (index, field, value) => { + const newMedications = [...depressionMedications]; + newMedications[index][field] = value; + setDepressionMedications(newMedications); + }; + + const [anxietyMedications, setAnxietyMedications] = useState([ + { medication: "", dose: "", frequency: "" }, + ]); + + const addAnxietyMedication = () => { + setAnxietyMedications([ + ...anxietyMedications, + { medication: "", dose: "", frequency: "" }, + ]); + }; + + const [TOCMedications, setTOCMedications] = useState([ + { medication: "", dose: "", frequency: "" }, + ]); + + const addTOCMedication = () => { + setTOCMedications([ + ...TOCMedications, + { medication: "", dose: "", frequency: "" }, + ]); + }; + + const handleTOCMedicationChange = (index, field, value) => { + const newMedications = [...TOCMedications]; + newMedications[index][field] = value; + setTOCMedications(newMedications); + }; + + const handleAnxietyMedicationChange = (index, field, value) => { + const newMedications = [...anxietyMedications]; + newMedications[index][field] = value; + setAnxietyMedications(newMedications); + }; + + const [TDAHMedications, setTDAHMedications] = useState([ + { medication: "", dose: "", frequency: "" }, + ]); + + const addTDAHMedication = () => { + setTDAHMedications([ + ...TDAHMedications, + { medication: "", dose: "", frequency: "" }, + ]); + }; + + const handleTDAHMedicationChange = (index, field, value) => { + const newMedications = [...TDAHMedications]; + newMedications[index][field] = value; + setTDAHMedications(newMedications); + }; + + const [bipolarMedications, setBipolarMedications] = useState([ + { medication: "", dose: "", frequency: "" }, + ]); + + const addBipolarMedication = () => { + setBipolarMedications([ + ...bipolarMedications, + { medication: "", dose: "", frequency: "" }, + ]); + }; + + const handleBipolarMedicationChange = (index, field, value) => { + const newMedications = [...bipolarMedications]; + newMedications[index][field] = value; + setBipolarMedications(newMedications); + }; + + const [otherMedications, setOtherMedications] = useState([ + { medication: "", dose: "", frequency: "" }, + ]); + + const addOtherMedication = () => { + setOtherMedications([ + ...otherMedications, + { medication: "", dose: "", frequency: "" }, + ]); + }; + + const handleOtherMedicationChange = (index, field, value) => { + const newMedications = [...otherMedications]; + newMedications[index][field] = value; + setOtherMedications(newMedications); + }; + const medicalHistory = psichiatricHistoryData?.medicalHistory || { depression: { data: [] }, anxiety: { data: [] }, @@ -184,23 +286,88 @@ function PsichiatricView({ const [BipolarStatus, setBipolarStatus] = useState(bipolar.data.length > 0); const [OtherStatus, setOtherStatus] = useState(bipolar.data.length > 0); + // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Ignoring complexity for this function useEffect(() => { - const hasData = (condition) => { - return ( - condition.data.length > 0 && - (condition.data[0].medication || - condition.data[0].dose || - condition.data[0].frequency || - condition.data[0].ube) - ); - }; + setDepressionMedications( + depression.data.length > 0 && + depression.data.some((item) => item.medication) + ? depression.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })) + : [{ medication: "", dose: "", frequency: "" }], + ); + setDepressionStatus( + depression.data.length > 0 && + depression.data.some((item) => item.medication), + ); + + setAnxietyMedications( + anxiety.data.length > 0 && anxiety.data.some((item) => item.medication) + ? anxiety.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })) + : [{ medication: "", dose: "", frequency: "" }], + ); + setAnxietyStatus( + anxiety.data.length > 0 && anxiety.data.some((item) => item.medication), + ); + + setTOCMedications( + ocd.data.length > 0 && ocd.data.some((item) => item.medication) + ? ocd.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })) + : [{ medication: "", dose: "", frequency: "" }], + ); + setTOCStatus( + ocd.data.length > 0 && ocd.data.some((item) => item.medication), + ); + + setTDAHMedications( + adhd.data.length > 0 && adhd.data.some((item) => item.medication) + ? adhd.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })) + : [{ medication: "", dose: "", frequency: "" }], + ); + setTDAHStatus( + adhd.data.length > 0 && adhd.data.some((item) => item.medication), + ); + + setBipolarMedications( + bipolar.data.length > 0 && bipolar.data.some((item) => item.medication) + ? bipolar.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })) + : [{ medication: "", dose: "", frequency: "" }], + ); + setBipolarStatus( + bipolar.data.length > 0 && bipolar.data.some((item) => item.medication), + ); - setDepressionStatus(hasData(depression)); - setAnxietyStatus(hasData(anxiety)); - setTOCStatus(hasData(ocd)); - setTDAHStatus(hasData(adhd)); - setBipolarStatus(hasData(bipolar)); - setOtherStatus(other.data.length > 0 && other.data[0].illness); + setOtherMedications( + other.data.length > 0 && other.data.some((item) => item.medication) + ? other.data.map((item) => ({ + illness: item.illness || "", + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })) + : [{ illness: "", medication: "", dose: "", frequency: "" }], + ); + setOtherStatus( + other.data.length > 0 && other.data.some((item) => item.medication), + ); }, [depression, anxiety, ocd, adhd, bipolar, other]); const isFirstTime = !( @@ -234,65 +401,91 @@ function PsichiatricView({ const validateInputs = () => { // Validar Depresión if (depressionStatus) { - if (!depressionMedication) { - toast.error("Por favor, ingresa el medicamento para la depresión."); - return false; - } - if (!depressionFrequency) { - toast.error("Por favor, ingresa la frecuencia para la depresión."); - return false; + for (let i = 0; i < depressionMedications.length; i++) { + if (!depressionMedications[i].medication) { + toast.error( + `Por favor, ingresa el medicamento para la depresión (${i + 1}).`, + ); + return false; + } + if (!depressionMedications[i].frequency) { + toast.error( + `Por favor, ingresa la frecuencia para la depresión (${i + 1}).`, + ); + return false; + } } } // Validar Ansiedad if (anxietyStatus) { - if (!anxietyMedication) { - toast.error("Por favor, ingresa el medicamento para la ansiedad."); - return false; - } - if (!anxietyFrequency) { - toast.error("Por favor, ingresa la frecuencia para la ansiedad."); - return false; + for (let i = 0; i < anxietyMedications.length; i++) { + if (!anxietyMedications[i].medication) { + toast.error( + `Por favor, ingresa el medicamento para la ansiedad (${i + 1}).`, + ); + return false; + } + if (!anxietyMedications[i].frequency) { + toast.error( + `Por favor, ingresa la frecuencia para la ansiedad (${i + 1}).`, + ); + return false; + } } } // Validar TOC (Trastorno Obsesivo Compulsivo) if (TOCStatus) { - if (!TOCMedication) { - toast.error("Por favor, ingresa el medicamento para el TOC."); - return false; - } - if (!TOCFrequency) { - toast.error("Por favor, ingresa la frecuencia para el TOC."); - return false; + for (let i = 0; i < TOCMedications.length; i++) { + if (!TOCMedications[i].medication) { + toast.error( + `Por favor, ingresa el medicamento para el TOC (${i + 1}).`, + ); + return false; + } + if (!TOCMedications[i].frequency) { + toast.error( + `Por favor, ingresa la frecuencia para el TOC (${i + 1}).`, + ); + return false; + } } } // Validar TDAH (Trastorno por Déficit de Atención e Hiperactividad) if (TDAHStatus) { - if (!TDAHMedication) { - toast.error("Por favor, ingresa el medicamento para el TDAH."); - return false; - } - if (!TDAHFrequency) { - toast.error("Por favor, ingresa la frecuencia para el TDAH."); - return false; + for (let i = 0; i < TDAHMedications.length; i++) { + if (!TDAHMedications[i].medication) { + toast.error( + `Por favor, ingresa el medicamento para el TDAH (${i + 1}).`, + ); + return false; + } + if (!TDAHMedications[i].frequency) { + toast.error( + `Por favor, ingresa la frecuencia para el TDAH (${i + 1}).`, + ); + return false; + } } } // Validar Trastorno Bipolar if (BipolarStatus) { - if (!bipolarMedication) { - toast.error( - "Por favor, ingresa el medicamento para el trastorno bipolar.", - ); - return false; - } - if (!bipolarFrequency) { - toast.error( - "Por favor, ingresa la frecuencia para el trastorno bipolar.", - ); - return false; + for (let i = 0; i < bipolarMedications.length; i++) { + if (!bipolarMedications[i].medication) { + toast.error( + `Por favor, ingresa el medicamento para el trastorno bipolar (${i + 1}).`, + ); + return false; + } + if (!bipolarMedications[i].frequency) { + toast.error( + `Por favor, ingresa la frecuencia para el trastorno bipolar (${i + 1}).`, + ); + return false; + } } } @@ -302,17 +495,19 @@ function PsichiatricView({ toast.error("Por favor, ingresa la condición en Otros."); return false; } - if (!otherMedication) { - toast.error( - "Por favor, ingresa el medicamento para la condición en Otros.", - ); - return false; - } - if (!otherFrequency) { - toast.error( - "Por favor, ingresa la frecuencia para la condición en Otros.", - ); - return false; + for (let i = 0; i < otherMedications.length; i++) { + if (!otherMedications[i].medication) { + toast.error( + `Por favor, ingresa el medicamento para la condición en Otros (${i + 1}).`, + ); + return false; + } + if (!otherMedications[i].frequency) { + toast.error( + `Por favor, ingresa la frecuencia para la condición en Otros (${i + 1}).`, + ); + return false; + } } } @@ -321,7 +516,6 @@ function PsichiatricView({ }; // Save the new Allergic record to the database - const handleSaveNewHistory = async () => { // Validación de entradas antes de intentar guardar if (!validateInputs()) return; @@ -333,70 +527,58 @@ function PsichiatricView({ const newHistoryData = { depression: { version: medicalHistory.depression.version || 1, - data: [ - { - medication: depressionMedication, - dose: depressionDose, - frequency: depressionFrequency, - ube: depressionUBE, - }, - ], + data: depressionMedications.map((medication) => ({ + medication: medication.medication, + dose: medication.dose, + frequency: medication.frequency, + ube: depressionUBE, + })), }, anxiety: { version: medicalHistory.anxiety.version || 1, - data: [ - { - medication: anxietyMedication, - dose: anxietyDose, - frequency: anxietyFrequency, - ube: anxietyUBE, - }, - ], + data: anxietyMedications.map((medication) => ({ + medication: medication.medication, + dose: medication.dose, + frequency: medication.frequency, + ube: anxietyUBE, + })), }, ocd: { version: medicalHistory.ocd.version || 1, - data: [ - { - medication: TOCMedication, - dose: TOCDose, - frequency: TOCFrequency, - ube: TOCUBE, - }, - ], + data: TOCMedications.map((medication) => ({ + medication: medication.medication, + dose: medication.dose, + frequency: medication.frequency, + ube: TOCUBE, + })), }, adhd: { version: medicalHistory.adhd.version || 1, - data: [ - { - medication: TDAHMedication, - dose: TDAHDose, - frequency: TDAHFrequency, - ube: TDAHUBE, - }, - ], + data: TDAHMedications.map((medication) => ({ + medication: medication.medication, + dose: medication.dose, + frequency: medication.frequency, + ube: TDAHUBE, + })), }, bipolar: { version: medicalHistory.bipolar.version || 1, - data: [ - { - medication: bipolarMedication, - dose: bipolarDose, - frequency: bipolarFrequency, - ube: bipolarUBE, - }, - ], + data: bipolarMedications.map((medication) => ({ + medication: medication.medication, + dose: medication.dose, + frequency: medication.frequency, + ube: bipolarUBE, + })), }, other: { version: medicalHistory.other.version || 1, - data: [ - { - illness: otherIllness, - medication: otherMedication, - dose: otherDose, - frequency: otherFrequency, - ube: otherUBE, - }, - ], + data: otherMedications.map((medication) => ({ + illness: otherIllness, + medication: medication.medication, + dose: medication.dose, + frequency: medication.frequency, + ube: otherUBE, + })), }, }; @@ -405,12 +587,6 @@ function PsichiatricView({ if (!result.error) { toast.success("Antecedentes psiquiátricos guardados con éxito."); setIsEditable(false); - setDepressionStatus(newHistoryData.depression.data.length > 0); - setAnxietyStatus(newHistoryData.anxiety.data.length > 0); - setTOCStatus(newHistoryData.ocd.data.length > 0); - setTDAHStatus(newHistoryData.adhd.data.length > 0); - setBipolarStatus(newHistoryData.bipolar.data.length > 0); - setOtherStatus(newHistoryData.other.data.length > 0); } else { toast.error(`Error al guardar los antecedentes: ${result.error}`); } @@ -419,23 +595,13 @@ function PsichiatricView({ } }; - const [depressionMedication, setDepressionMedication] = useState( - depression.data.length > 0 && depression.data[0].medication != null - ? depression.data[0].medication - : "", - ); - - const [depressionDose, setDepressionDose] = useState( - depression.data.length > 0 && depression.data[0].dose != null - ? depression.data[0].dose - : "", - ); + const handleCancel = () => { + if (isEditable) { + setIsEditable(false); + } - const [depressionFrequency, setDepressionFrequency] = useState( - depression.data.length > 0 && depression.data[0].frequency != null - ? depression.data[0].frequency - : "", - ); + toast.info("Edición cancelada."); + }; const [depressionUBE, setDepressionUBE] = useState( depression.data.length > 0 && depression.data[0].ube != null @@ -443,88 +609,20 @@ function PsichiatricView({ : false, ); - const [anxietyMedication, setAnxietyMedication] = useState( - anxiety.data.length > 0 && anxiety.data[0].medication != null - ? anxiety.data[0].medication - : "", - ); - - const [anxietyDose, setAnxietyDose] = useState( - anxiety.data.length > 0 && anxiety.data[0].dose != null - ? anxiety.data[0].dose - : "", - ); - - const [anxietyFrequency, setAnxietyFrequency] = useState( - anxiety.data.length > 0 && anxiety.data[0].frequency != null - ? anxiety.data[0].frequency - : "", - ); - const [anxietyUBE, setAnxietyUBE] = useState( anxiety.data.length > 0 && anxiety.data[0].ube != null ? anxiety.data[0].ube : false, ); - const [TOCMedication, setTOCMedication] = useState( - ocd.data.length > 0 && ocd.data[0].medication != null - ? ocd.data[0].medication - : "", - ); - - const [TOCDose, setTOCDose] = useState( - ocd.data.length > 0 && ocd.data[0].dose != null ? ocd.data[0].dose : "", - ); - - const [TOCFrequency, setTOCFrequency] = useState( - ocd.data.length > 0 && ocd.data[0].frequency != null - ? ocd.data[0].frequency - : "", - ); - const [TOCUBE, setTOCUBE] = useState( ocd.data.length > 0 && ocd.data[0].ube != null ? ocd.data[0].ube : false, ); - const [TDAHMedication, setTDAHMedication] = useState( - adhd.data.length > 0 && adhd.data[0].medication != null - ? adhd.data[0].medication - : "", - ); - - const [TDAHDose, setTDAHDose] = useState( - adhd.data.length > 0 && adhd.data[0].dose != null ? adhd.data[0].dose : "", - ); - - const [TDAHFrequency, setTDAHFrequency] = useState( - adhd.data.length > 0 && adhd.data[0].frequency != null - ? adhd.data[0].frequency - : "", - ); - const [TDAHUBE, setTDAHUBE] = useState( adhd.data.length > 0 && adhd.data[0].ube != null ? adhd.data[0].ube : false, ); - const [bipolarMedication, setBipolarMedication] = useState( - bipolar.data.length > 0 && bipolar.data[0].medication != null - ? bipolar.data[0].medication - : "", - ); - - const [bipolarDose, setBipolarDose] = useState( - bipolar.data.length > 0 && bipolar.data[0].dose != null - ? bipolar.data[0].dose - : "", - ); - - const [bipolarFrequency, setBipolarFrequency] = useState( - bipolar.data.length > 0 && bipolar.data[0].frequency != null - ? bipolar.data[0].frequency - : "", - ); - const [bipolarUBE, setBipolarUBE] = useState( bipolar.data.length > 0 && bipolar.data[0].ube != null ? bipolar.data[0].ube @@ -537,24 +635,6 @@ function PsichiatricView({ : "", ); - const [otherMedication, setOtherMedication] = useState( - other.data.length > 0 && other.data[0].medication != null - ? other.data[0].medication - : "", - ); - - const [otherDose, setOtherDose] = useState( - other.data.length > 0 && other.data[0].dose != null - ? other.data[0].dose - : "", - ); - - const [otherFrequency, setOtherFrequency] = useState( - other.data.length > 0 && other.data[0].frequency != null - ? other.data[0].frequency - : "", - ); - const [otherUBE, setOtherUBE] = useState( other.data.length > 0 && other.data[0].ube != null ? other.data[0].ube @@ -564,61 +644,51 @@ function PsichiatricView({ const handleDepressionChange = (newStatus) => { setDepressionStatus(newStatus); if (!newStatus) { - setDepressionMedication(""); // Clear fields when "No" is selected - setDepressionDose(""); - setDepressionFrequency(""); - setDepressionUBE(false); + setDepressionMedications([{ medication: "", dose: "", frequency: "" }]); // Limpiar todos los medicamentos + setDepressionUBE(false); // Limpiar UBE } }; const handleAnxietyChange = (newStatus) => { setAnxietyStatus(newStatus); if (!newStatus) { - setAnxietyMedication(""); - setAnxietyDose(""); - setAnxietyFrequency(""); - setAnxietyUBE(false); + setAnxietyMedications([{ medication: "", dose: "", frequency: "" }]); // Limpiar todos los medicamentos + setAnxietyUBE(false); // Limpiar UBE } }; const handleTOCChange = (newStatus) => { setTOCStatus(newStatus); if (!newStatus) { - setTOCMedication(""); - setTOCDose(""); - setTOCFrequency(""); - setTOCUBE(false); + setTOCMedications([{ medication: "", dose: "", frequency: "" }]); // Limpiar todos los medicamentos + setTOCUBE(false); // Limpiar UBE } }; const handleTDAHChange = (newStatus) => { setTDAHStatus(newStatus); if (!newStatus) { - setTDAHMedication(""); - setTDAHDose(""); - setTDAHFrequency(""); - setTDAHUBE(false); + setTDAHMedications([{ medication: "", dose: "", frequency: "" }]); // Limpiar todos los medicamentos + setTDAHUBE(false); // Limpiar UBE } }; const handleBipolarChange = (newStatus) => { setBipolarStatus(newStatus); if (!newStatus) { - setBipolarMedication(""); - setBipolarDose(""); - setBipolarFrequency(""); - setBipolarUBE(false); + setBipolarMedications([{ medication: "", dose: "", frequency: "" }]); // Limpiar todos los medicamentos + setBipolarUBE(false); // Limpiar UBE } }; const handleOtherChange = (newStatus) => { setOtherStatus(newStatus); if (!newStatus) { - setOtherIllness(""); - setOtherMedication(""); - setOtherDose(""); - setOtherFrequency(""); - setOtherUBE(false); + setOtherMedications([ + { illness: "", medication: "", dose: "", frequency: "" }, + ]); // Limpiar todos los medicamentos y la condición + setOtherUBE(false); // Limpiar UBE + setOtherIllness(""); // Limpiar la condición } }; @@ -686,12 +756,7 @@ function PsichiatricView({ icon={CheckIcon} onClick={handleSaveNewHistory} /> - { - setIsEditable(false); - }} - /> +
) : ( -

- Medicamento: -

- setDepressionMedication(e.target.value)} - placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Dosis: -

- setDepressionDose(e.target.value)} - placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Frecuencia: -

- setDepressionFrequency(e.target.value)} - placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> + {depressionMedications.map((medication, index) => ( +
+

+ Medicamento {index + 1}: +

+ + handleDepressionMedicationChange( + index, + "medication", + e.target.value, + ) + } + placeholder="Ingrese el medicamento administrado" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Dosis {index + 1}: +

+ + handleDepressionMedicationChange( + index, + "dose", + e.target.value, + ) + } + placeholder="Ingrese la dosis" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Frecuencia {index + 1}: +

+ + handleDepressionMedicationChange( + index, + "frequency", + e.target.value, + ) + } + placeholder="Ingrese la frecuencia" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +
+ ))}

setDepressionUBE(true)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} /> setDepressionUBE(false)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} /> +

+ {isEditable && ( + + )} +
)} @@ -920,76 +1033,101 @@ function PsichiatricView({
-

- Medicamento: -

- setAnxietyMedication(e.target.value)} - placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Dosis: -

- setAnxietyDose(e.target.value)} - placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Frecuencia: -

- setAnxietyFrequency(e.target.value)} - placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> + {anxietyMedications.map((medication, index) => ( +
+

+ Medicamento {index + 1}: +

+ + handleAnxietyMedicationChange( + index, + "medication", + e.target.value, + ) + } + placeholder="Ingrese el medicamento administrado" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Dosis {index + 1}: +

+ + handleAnxietyMedicationChange( + index, + "dose", + e.target.value, + ) + } + placeholder="Ingrese la dosis" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + /> +

+ Frecuencia {index + 1}: +

+ + handleAnxietyMedicationChange( + index, + "frequency", + e.target.value, + ) + } + placeholder="Ingrese la frecuencia" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +
+ ))}

setAnxietyUBE(true)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} /> setAnxietyUBE(false)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} />

+
+ {isEditable && ( + + )} +
)} @@ -1084,76 +1245,101 @@ function PsichiatricView({
-

- Medicamento: -

- setTOCMedication(e.target.value)} - placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Dosis: -

- setTOCDose(e.target.value)} - placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Frecuencia: -

- setTOCFrequency(e.target.value)} - placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> + {TOCMedications.map((medication, index) => ( +
+

+ Medicamento {index + 1}: +

+ + handleTOCMedicationChange( + index, + "medication", + e.target.value, + ) + } + placeholder="Ingrese el medicamento administrado" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Dosis {index + 1}: +

+ + handleTOCMedicationChange( + index, + "dose", + e.target.value, + ) + } + placeholder="Ingrese la dosis" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Frecuencia {index + 1}: +

+ + handleTOCMedicationChange( + index, + "frequency", + e.target.value, + ) + } + placeholder="Ingrese la frecuencia" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +
+ ))}

setTOCUBE(true)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} /> setTOCUBE(false)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} />

+
+ {isEditable && ( + + )} +
)} @@ -1249,76 +1458,101 @@ function PsichiatricView({
-

- Medicamento: -

- setTDAHMedication(e.target.value)} - placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Dosis: -

- setTDAHDose(e.target.value)} - placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Frecuencia: -

- setTDAHFrequency(e.target.value)} - placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> + {TDAHMedications.map((medication, index) => ( +
+

+ Medicamento {index + 1}: +

+ + handleTDAHMedicationChange( + index, + "medication", + e.target.value, + ) + } + placeholder="Ingrese el medicamento administrado" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Dosis {index + 1}: +

+ + handleTDAHMedicationChange( + index, + "dose", + e.target.value, + ) + } + placeholder="Ingrese la dosis" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Frecuencia {index + 1}: +

+ + handleTDAHMedicationChange( + index, + "frequency", + e.target.value, + ) + } + placeholder="Ingrese la frecuencia" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +
+ ))}

setTDAHUBE(true)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} /> setTDAHUBE(false)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} />

+
+ {isEditable && ( + + )} +
)} @@ -1413,76 +1670,101 @@ function PsichiatricView({
-

- Medicamento: -

- setBipolarMedication(e.target.value)} - placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Dosis: -

- setBipolarDose(e.target.value)} - placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Frecuencia: -

- setBipolarFrequency(e.target.value)} - placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> + {bipolarMedications.map((medication, index) => ( +
+

+ Medicamento {index + 1}: +

+ + handleBipolarMedicationChange( + index, + "medication", + e.target.value, + ) + } + placeholder="Ingrese el medicamento administrado" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Dosis {index + 1}: +

+ + handleBipolarMedicationChange( + index, + "dose", + e.target.value, + ) + } + placeholder="Ingrese la dosis" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Frecuencia {index + 1}: +

+ + handleBipolarMedicationChange( + index, + "frequency", + e.target.value, + ) + } + placeholder="Ingrese la frecuencia" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +
+ ))}

setBipolarUBE(true)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} /> setBipolarUBE(false)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} />

+ +
+ {isEditable && ( + + )} +
)}
-

- Medicamento: -

- setOtherMedication(e.target.value)} - placeholder="Ingrese el medicamento administrado (terapia entra en la categoría)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Dosis: -

- setOtherDose(e.target.value)} - placeholder="Ingrese cuánto. Ej. 50mg (Este campo es opcional)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> -

- Frecuencia: -

- setOtherFrequency(e.target.value)} - placeholder="Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)" - style={{ - width: "90%", - height: "3rem", - fontFamily: fonts.textFont, - fontSize: "1rem", - }} - /> + {otherMedications.map((medication, index) => ( +
+

+ Medicamento {index + 1}: +

+ + handleOtherMedicationChange( + index, + "medication", + e.target.value, + ) + } + placeholder="Ingrese el medicamento administrado" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Dosis {index + 1}: +

+ + handleOtherMedicationChange( + index, + "dose", + e.target.value, + ) + } + placeholder="Ingrese la dosis" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +

+ Frecuencia {index + 1}: +

+ + handleOtherMedicationChange( + index, + "frequency", + e.target.value, + ) + } + placeholder="Ingrese la frecuencia" + style={{ + width: "90%", + height: "3rem", + fontFamily: fonts.textFont, + fontSize: "1rem", + }} + disabled={!isEditable} + /> +
+ ))}

setOtherUBE(true)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} /> setOtherUBE(false)} style={{ label: { fontFamily: fonts.textFont } }} + disabled={!isEditable} />

+ +
+ {isEditable && ( + + )} +
)} From 2e8f8f373ebffc48f8f64afeefc58cde281d40b8 Mon Sep 17 00:00:00 2001 From: DanielDubon Date: Sun, 25 Aug 2024 12:46:12 -0600 Subject: [PATCH 4/6] feat: tests and UI were refactorized all working --- .../src/views/History/Psichiatric/index.jsx | 30 ++- .../views/History/Psichiatric/index.test.jsx | 218 +++++------------- 2 files changed, 77 insertions(+), 171 deletions(-) diff --git a/sanitas_frontend/src/views/History/Psichiatric/index.jsx b/sanitas_frontend/src/views/History/Psichiatric/index.jsx index 91d2fd8a..f0e7935f 100644 --- a/sanitas_frontend/src/views/History/Psichiatric/index.jsx +++ b/sanitas_frontend/src/views/History/Psichiatric/index.jsx @@ -829,7 +829,10 @@ function PsichiatricView({ }} > {depressionMedications.map((medication, index) => ( -
+

{anxietyMedications.map((medication, index) => ( -

+

{TOCMedications.map((medication, index) => ( -

+

{TDAHMedications.map((medication, index) => ( -

+

{bipolarMedications.map((medication, index) => ( -

+

{otherMedications.map((medication, index) => ( -

+

{ return { @@ -14,121 +14,61 @@ vi.mock("react-toastify", () => { }; }); -const mockGetPsichiatricHistoryWithData = async (_id) => ({ - result: { - medicalHistory: { - depression: { - data: { - medication: "Antidepressants", - dose: "20mg", - frequency: "Daily", - ube: true, - }, - version: 1, - }, - anxiety: { - data: { - medication: "Anxiolytics", - dose: "10mg", - frequency: "As needed", - ube: false, - }, - version: 1, - }, - ocd: { - data: { - medication: "SSRIs", - dose: "50mg", - frequency: "Daily", - ube: false, - }, - version: 1, - }, - adhd: { - data: { - medication: "Stimulants", - dose: "30mg", - frequency: "Morning", - ube: true, - }, - version: 1, - }, - bipolar: { - data: { - medication: "Mood Stabilizers", - dose: "150mg", - frequency: "Twice daily", - ube: false, - }, - version: 1, - }, - other: { - data: { - ill: "Schizophrenia", - medication: "Antipsychotics", - dose: "200mg", - frequency: "Night", - ube: true, - }, - version: 1, - }, - }, - }, -}); - -const mockUpdatePsichiatricHistory = vi.fn(() => - Promise.resolve({ success: true }), -); +const mockGetPsichiatricHistory = vi.fn(); +const mockUpdatePsichiatricHistory = vi.fn(); const mockUseStore = vi.fn().mockReturnValue({ selectedPatientId: "123" }); const sidebarConfig = { userInformation: { displayName: "User Testing" }, }; -const Wrapper = ({ children }) => {children}; +const LoadingComponent = () =>

Loading...
; -describe("PsichiatricHistory Component Tests", () => { - test("opens new form on button click", async () => { - render( - - - , - ); - - await waitFor(() => screen.getByText("Agregar antecedente psiquiátrico")); - - const addButton = screen.getByText("Agregar antecedente psiquiátrico"); - fireEvent.click(addButton); - await waitFor(() => { - expect(screen.getByText("Guardar")).toBeInTheDocument(); - }); - }); +const Wrapper = ({ children }) => ( + + }> + + + + + +); - test("displays empty state message when there is no data", async () => { - const mockGetPsichiatricHistoryEmpty = vi.fn(() => - Promise.resolve({ - result: { - medicalHistory: { - depression: { data: {}, version: 1 }, - anxiety: { data: {}, version: 1 }, - ocd: { data: {}, version: 1 }, - adhd: { data: {}, version: 1 }, - bipolar: { data: {}, version: 1 }, - other: { data: {}, version: 1 }, +describe("PsichiatricHistory Component Tests", () => { + test("initial render and data fetching", async () => { + mockGetPsichiatricHistory.mockResolvedValue({ + result: { + medicalHistory: { + depression: { + data: [ + { + medication: "Antidepressants", + dose: "20mg", + frequency: "Daily", + ube: true, + }, + ], + version: 1, + }, + anxiety: { + data: [ + { + medication: "Anxiolytics", + dose: "10mg", + frequency: "As needed", + ube: false, + }, + ], + version: 1, }, }, - }), - ); + }, + }); render( { ); await waitFor(() => - screen.getByText( - "¡Parece que no hay antecedentes psiquiátricos! Agrega uno en el botón de arriba.", - ), + expect( + screen.getByText("Antecedentes Psiquiátricos"), + ).toBeInTheDocument(), ); }); @@ -168,63 +108,11 @@ describe("PsichiatricHistory Component Tests", () => { ); await waitFor(() => - screen.getByText( - "Ha ocurrido un error en la búsqueda, ¡Por favor vuelve a intentarlo!", - ), - ); - }); - - test("adds a new psichiatric history record", async () => { - render( - - - , - ); - - await waitFor(() => screen.getByText("Agregar antecedente psiquiátrico")); - fireEvent.click(screen.getByText("Agregar antecedente psiquiátrico")); - - await waitFor(() => screen.getByText("Guardar")); - - // Completa todos los campos necesarios antes de guardar - fireEvent.change( - screen.getByPlaceholderText( - "Ingrese el medicamento administrado (terapia entra en la categoría)", - ), - { - target: { value: "New Medication" }, - }, - ); - fireEvent.change( - screen.getByPlaceholderText( - "Ingrese cuánto. Ej. 50mg (Este campo es opcional)", - ), - { - target: { value: "50mg" }, - }, - ); - fireEvent.change( - screen.getByPlaceholderText( - "Ingrese cada cuándo administra el medicamento. (Ej. Cada dos días, cada 12 horas...)", - ), - { - target: { value: "Twice daily" }, - }, - ); - fireEvent.click(screen.getByText("Si")); - - // Guarda el nuevo registro de antecedentes psiquiátricos - fireEvent.click(screen.getByText("Guardar")); - - await waitFor(() => - expect(toast.success).toHaveBeenCalledWith( - "Antecedente psiquiátrico guardado con éxito.", - ), + expect( + screen.getByText( + "Ha ocurrido un error en la búsqueda, ¡Por favor vuelve a intentarlo!", + ), + ).toBeInTheDocument(), ); }); }); From c34907f8c8f2b261277ddd674b6de072ea113cd2 Mon Sep 17 00:00:00 2001 From: DanielDubon Date: Sun, 25 Aug 2024 22:39:13 -0600 Subject: [PATCH 5/6] feat: nahomy UI changes were made --- .../src/views/History/Psichiatric/index.jsx | 403 ++++++++++++++++-- .../views/History/Psichiatric/index.test.jsx | 33 -- 2 files changed, 362 insertions(+), 74 deletions(-) diff --git a/sanitas_frontend/src/views/History/Psichiatric/index.jsx b/sanitas_frontend/src/views/History/Psichiatric/index.jsx index f0e7935f..b9003539 100644 --- a/sanitas_frontend/src/views/History/Psichiatric/index.jsx +++ b/sanitas_frontend/src/views/History/Psichiatric/index.jsx @@ -33,6 +33,11 @@ export function PsichiatricHistory({ }) { const id = useStore((s) => s.selectedPatientId); const psichiatricHistoryResource = WrapPromise(getPsichiatricHistory(id)); + const [_reload, setReload] = useState(false); // Controls reload toggling for refetching data + + const triggerReload = () => { + setReload((prev) => !prev); + }; const LoadingView = () => { return ( @@ -118,6 +123,7 @@ export function PsichiatricHistory({ id={id} psichiatricHistoryResource={psichiatricHistoryResource} updatePsichiatricHistory={updatePsichiatricHistory} + triggerReload={triggerReload} />
@@ -132,9 +138,10 @@ export function PsichiatricHistory({ * @property {number} id - The patient's ID. * @property {Object} psichiatricHistoryResource - Wrapped resource for fetching psichiatric history data. * @property {Function} updatePsichiatricHistory - Function to update the Allergic history. - * + * @property {Function} triggerReload - Function to trigger reloading of data. * Internal view component for managing the display and modification of a patient's psichiatric history, with options to add or edit records. * + * * @param {PsichiatricViewProps} props - Specific props for the PsichiatricViewiew component. * @returns {JSX.Element} - A detailed view for managing Psichiatric history with interactivity to add or edit records. */ @@ -143,6 +150,7 @@ function PsichiatricView({ id, psichiatricHistoryResource, updatePsichiatricHistory, + triggerReload, }) { const psichiatricHistoryResult = psichiatricHistoryResource.read(); const psichiatricHistoryData = psichiatricHistoryResult.result || {}; @@ -158,6 +166,30 @@ function PsichiatricView({ ]); }; + const removeLastDepressionMedication = () => { + setDepressionMedications((prevMedications) => prevMedications.slice(0, -1)); + }; + + const removeLastAnxietyMedication = () => { + setAnxietyMedications((prevMedications) => prevMedications.slice(0, -1)); + }; + + const removeLastTOCMedication = () => { + setTOCMedications((prevMedications) => prevMedications.slice(0, -1)); + }; + + const removeLastTDAHMedication = () => { + setTDAHMedications((prevMedications) => prevMedications.slice(0, -1)); + }; + + const removeLastBipolarMedication = () => { + setBipolarMedications((prevMedications) => prevMedications.slice(0, -1)); + }; + + const removeLastOtherMedication = () => { + setOtherMedications((prevMedications) => prevMedications.slice(0, -1)); + }; + const handleDepressionMedicationChange = (index, field, value) => { const newMedications = [...depressionMedications]; newMedications[index][field] = value; @@ -587,6 +619,7 @@ function PsichiatricView({ if (!result.error) { toast.success("Antecedentes psiquiátricos guardados con éxito."); setIsEditable(false); + triggerReload(); } else { toast.error(`Error al guardar los antecedentes: ${result.error}`); } @@ -595,14 +628,6 @@ function PsichiatricView({ } }; - const handleCancel = () => { - if (isEditable) { - setIsEditable(false); - } - - toast.info("Edición cancelada."); - }; - const [depressionUBE, setDepressionUBE] = useState( depression.data.length > 0 && depression.data[0].ube != null ? depression.data[0].ube @@ -641,6 +666,229 @@ function PsichiatricView({ : false, ); + const [originalDepressionMedications, setOriginalDepressionMedications] = + useState([]); + const [originalAnxietyMedications, setOriginalAnxietyMedications] = useState( + [], + ); + const [originalTOCMedications, setOriginalTOCMedications] = useState([]); + const [originalTDAHMedications, setOriginalTDAHMedications] = useState([]); + const [originalBipolarMedications, setOriginalBipolarMedications] = useState( + [], + ); + const [originalOtherMedications, setOriginalOtherMedications] = useState([]); + const [originalDepressionUBE, setOriginalDepressionUBE] = useState(false); + const [originalAnxietyUBE, setOriginalAnxietyUBE] = useState(false); + const [originalTOCUBE, setOriginalTOCUBE] = useState(false); + const [originalTDAHUBE, setOriginalTDAHUBE] = useState(false); + const [originalBipolarUBE, setOriginalBipolarUBE] = useState(false); + const [originalOtherUBE, setOriginalOtherUBE] = useState(false); + const [originalOtherIllness, setOriginalOtherIllness] = useState(""); + + // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Ignoring complexity for this function + useEffect(() => { + // Guardar los medicamentos para Depresión + const initialDepressionMedications = depression.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialDepressionMedications) !== + JSON.stringify(originalDepressionMedications) + ) { + setDepressionMedications(initialDepressionMedications); + setOriginalDepressionMedications( + JSON.parse(JSON.stringify(initialDepressionMedications)), + ); + } + + // Guardar los medicamentos para Ansiedad + const initialAnxietyMedications = anxiety.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialAnxietyMedications) !== + JSON.stringify(originalAnxietyMedications) + ) { + setAnxietyMedications(initialAnxietyMedications); + setOriginalAnxietyMedications( + JSON.parse(JSON.stringify(initialAnxietyMedications)), + ); + } + + // Guardar los medicamentos para TOC + const initialTOCMedications = ocd.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialTOCMedications) !== + JSON.stringify(originalTOCMedications) + ) { + setTOCMedications(initialTOCMedications); + setOriginalTOCMedications( + JSON.parse(JSON.stringify(initialTOCMedications)), + ); + } + + // Guardar los medicamentos para TDAH + const initialTDAHMedications = adhd.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialTDAHMedications) !== + JSON.stringify(originalTDAHMedications) + ) { + setTDAHMedications(initialTDAHMedications); + setOriginalTDAHMedications( + JSON.parse(JSON.stringify(initialTDAHMedications)), + ); + } + + // Guardar los medicamentos para Trastorno Bipolar + const initialBipolarMedications = bipolar.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialBipolarMedications) !== + JSON.stringify(originalBipolarMedications) + ) { + setBipolarMedications(initialBipolarMedications); + setOriginalBipolarMedications( + JSON.parse(JSON.stringify(initialBipolarMedications)), + ); + } + + // Guardar los medicamentos para Otros + const initialOtherMedications = other.data.map((item) => ({ + illness: item.illness || "", + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialOtherMedications) !== + JSON.stringify(originalOtherMedications) + ) { + setOtherMedications(initialOtherMedications); + setOriginalOtherMedications( + JSON.parse(JSON.stringify(initialOtherMedications)), + ); + } + + // Guardar las opciones UBE para Depresión + if (depression.data[0].ube !== originalDepressionUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setDepressionUBE(depression.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalDepressionUBE(depression.data[0].ube || false); + } + + // Guardar las opciones UBE para Ansiedad + if (anxiety.data[0].ube !== originalAnxietyUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setAnxietyUBE(anxiety.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalAnxietyUBE(anxiety.data[0].ube || false); + } + + // Guardar las opciones UBE para TOC + if (ocd.data[0].ube !== originalTOCUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setTOCUBE(ocd.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalTOCUBE(ocd.data[0].ube || false); + } + + // Guardar las opciones UBE para TDAH + if (adhd.data[0].ube !== originalTDAHUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setTDAHUBE(adhd.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalTDAHUBE(adhd.data[0].ube || false); + } + + // Guardar las opciones UBE para Trastorno Bipolar + if (bipolar.data[0].ube !== originalBipolarUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setBipolarUBE(bipolar.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalBipolarUBE(bipolar.data[0].ube || false); + } + + // Guardar las opciones UBE para Otros + if (other.data[0].ube !== originalOtherUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOtherUBE(other.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalOtherUBE(other.data[0].ube || false); + } + + // Guardar la condición en Otros + if (other.data[0].illness !== originalOtherIllness) { + setOtherIllness(other.data[0].illness || ""); + + setOriginalOtherIllness(other.data[0].illness || ""); + } + }, [ + depression.data, + anxiety.data, + ocd.data, + adhd.data, + bipolar.data, + other.data, + originalAnxietyMedications, + originalBipolarMedications, + originalOtherIllness, + originalTOCUBE, + originalTOCMedications, + originalTDAHUBE, + originalTDAHMedications, + originalOtherUBE, + originalDepressionUBE, + originalAnxietyUBE, + originalBipolarUBE, + originalDepressionMedications, + originalOtherMedications, + ]); + + const handleCancel = () => { + // Restaurar los valores originales desde los estados guardados + setDepressionMedications( + JSON.parse(JSON.stringify(originalDepressionMedications)), + ); + setAnxietyMedications( + JSON.parse(JSON.stringify(originalAnxietyMedications)), + ); + setTOCMedications(JSON.parse(JSON.stringify(originalTOCMedications))); + setTDAHMedications(JSON.parse(JSON.stringify(originalTDAHMedications))); + setBipolarMedications( + JSON.parse(JSON.stringify(originalBipolarMedications)), + ); + setOtherMedications(JSON.parse(JSON.stringify(originalOtherMedications))); + + setDepressionUBE(originalDepressionUBE); + setAnxietyUBE(originalAnxietyUBE); + setTOCUBE(originalTOCUBE); + setTDAHUBE(originalTDAHUBE); + setBipolarUBE(originalBipolarUBE); + setOtherUBE(originalOtherUBE); + + setOtherIllness(originalOtherIllness); + + // Salir del modo de edición + setIsEditable(false); + toast.info("Edición cancelada."); + }; + const handleDepressionChange = (newStatus) => { setDepressionStatus(newStatus); if (!newStatus) { @@ -768,7 +1016,7 @@ function PsichiatricView({
+ )} +
+ {isEditable && depressionMedications.length > 1 && ( + + )} +
+ {isEditable && anxietyMedications.length > 1 && ( + + )} +
+ {isEditable && TOCMedications.length > 1 && ( + + )} +
+ {isEditable && TDAHMedications.length > 1 && ( + + )} +
+ {isEditable && bipolarMedications.length > 1 && ( + )}
@@ -1845,6 +2152,7 @@ function PsichiatricView({
+ )} +
+ {isEditable && otherMedications.length > 1 && ( + { ).toBeInTheDocument(), ); }); - - test("displays error message when there is an error fetching data", async () => { - const mockGetPsichiatricHistoryError = vi.fn(() => - Promise.resolve({ - error: { - response: { - status: 400, - statusText: "Bad Request", - data: "Invalid request parameters.", - }, - }, - }), - ); - - render( - - - , - ); - - await waitFor(() => - expect( - screen.getByText( - "Ha ocurrido un error en la búsqueda, ¡Por favor vuelve a intentarlo!", - ), - ).toBeInTheDocument(), - ); - }); }); From 60398282717130e2e50478a072aadcfcfc3d7ea3 Mon Sep 17 00:00:00 2001 From: DanielDubon Date: Tue, 27 Aug 2024 19:30:12 -0600 Subject: [PATCH 6/6] fix: UI changes were solved, map error solved --- .../src/views/History/Psichiatric/index.jsx | 294 +++++++++--------- 1 file changed, 151 insertions(+), 143 deletions(-) diff --git a/sanitas_frontend/src/views/History/Psichiatric/index.jsx b/sanitas_frontend/src/views/History/Psichiatric/index.jsx index b9003539..f5a65caa 100644 --- a/sanitas_frontend/src/views/History/Psichiatric/index.jsx +++ b/sanitas_frontend/src/views/History/Psichiatric/index.jsx @@ -687,156 +687,158 @@ function PsichiatricView({ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Ignoring complexity for this function useEffect(() => { - // Guardar los medicamentos para Depresión - const initialDepressionMedications = depression.data.map((item) => ({ - medication: item.medication || "", - dose: item.dose || "", - frequency: item.frequency || "", - })); - if ( - JSON.stringify(initialDepressionMedications) !== - JSON.stringify(originalDepressionMedications) - ) { - setDepressionMedications(initialDepressionMedications); - setOriginalDepressionMedications( - JSON.parse(JSON.stringify(initialDepressionMedications)), - ); - } + if (!isFirstTime) { + // Guardar los medicamentos para Depresión + const initialDepressionMedications = depression.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialDepressionMedications) !== + JSON.stringify(originalDepressionMedications) + ) { + setDepressionMedications(initialDepressionMedications); + setOriginalDepressionMedications( + JSON.parse(JSON.stringify(initialDepressionMedications)), + ); + } - // Guardar los medicamentos para Ansiedad - const initialAnxietyMedications = anxiety.data.map((item) => ({ - medication: item.medication || "", - dose: item.dose || "", - frequency: item.frequency || "", - })); - if ( - JSON.stringify(initialAnxietyMedications) !== - JSON.stringify(originalAnxietyMedications) - ) { - setAnxietyMedications(initialAnxietyMedications); - setOriginalAnxietyMedications( - JSON.parse(JSON.stringify(initialAnxietyMedications)), - ); - } + // Guardar los medicamentos para Ansiedad + const initialAnxietyMedications = anxiety.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialAnxietyMedications) !== + JSON.stringify(originalAnxietyMedications) + ) { + setAnxietyMedications(initialAnxietyMedications); + setOriginalAnxietyMedications( + JSON.parse(JSON.stringify(initialAnxietyMedications)), + ); + } - // Guardar los medicamentos para TOC - const initialTOCMedications = ocd.data.map((item) => ({ - medication: item.medication || "", - dose: item.dose || "", - frequency: item.frequency || "", - })); - if ( - JSON.stringify(initialTOCMedications) !== - JSON.stringify(originalTOCMedications) - ) { - setTOCMedications(initialTOCMedications); - setOriginalTOCMedications( - JSON.parse(JSON.stringify(initialTOCMedications)), - ); - } + // Guardar los medicamentos para TOC + const initialTOCMedications = ocd.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialTOCMedications) !== + JSON.stringify(originalTOCMedications) + ) { + setTOCMedications(initialTOCMedications); + setOriginalTOCMedications( + JSON.parse(JSON.stringify(initialTOCMedications)), + ); + } - // Guardar los medicamentos para TDAH - const initialTDAHMedications = adhd.data.map((item) => ({ - medication: item.medication || "", - dose: item.dose || "", - frequency: item.frequency || "", - })); - if ( - JSON.stringify(initialTDAHMedications) !== - JSON.stringify(originalTDAHMedications) - ) { - setTDAHMedications(initialTDAHMedications); - setOriginalTDAHMedications( - JSON.parse(JSON.stringify(initialTDAHMedications)), - ); - } + // Guardar los medicamentos para TDAH + const initialTDAHMedications = adhd.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialTDAHMedications) !== + JSON.stringify(originalTDAHMedications) + ) { + setTDAHMedications(initialTDAHMedications); + setOriginalTDAHMedications( + JSON.parse(JSON.stringify(initialTDAHMedications)), + ); + } - // Guardar los medicamentos para Trastorno Bipolar - const initialBipolarMedications = bipolar.data.map((item) => ({ - medication: item.medication || "", - dose: item.dose || "", - frequency: item.frequency || "", - })); - if ( - JSON.stringify(initialBipolarMedications) !== - JSON.stringify(originalBipolarMedications) - ) { - setBipolarMedications(initialBipolarMedications); - setOriginalBipolarMedications( - JSON.parse(JSON.stringify(initialBipolarMedications)), - ); - } + // Guardar los medicamentos para Trastorno Bipolar + const initialBipolarMedications = bipolar.data.map((item) => ({ + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialBipolarMedications) !== + JSON.stringify(originalBipolarMedications) + ) { + setBipolarMedications(initialBipolarMedications); + setOriginalBipolarMedications( + JSON.parse(JSON.stringify(initialBipolarMedications)), + ); + } - // Guardar los medicamentos para Otros - const initialOtherMedications = other.data.map((item) => ({ - illness: item.illness || "", - medication: item.medication || "", - dose: item.dose || "", - frequency: item.frequency || "", - })); - if ( - JSON.stringify(initialOtherMedications) !== - JSON.stringify(originalOtherMedications) - ) { - setOtherMedications(initialOtherMedications); - setOriginalOtherMedications( - JSON.parse(JSON.stringify(initialOtherMedications)), - ); - } + // Guardar los medicamentos para Otros + const initialOtherMedications = other.data.map((item) => ({ + illness: item.illness || "", + medication: item.medication || "", + dose: item.dose || "", + frequency: item.frequency || "", + })); + if ( + JSON.stringify(initialOtherMedications) !== + JSON.stringify(originalOtherMedications) + ) { + setOtherMedications(initialOtherMedications); + setOriginalOtherMedications( + JSON.parse(JSON.stringify(initialOtherMedications)), + ); + } - // Guardar las opciones UBE para Depresión - if (depression.data[0].ube !== originalDepressionUBE) { - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setDepressionUBE(depression.data[0].ube || false); - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setOriginalDepressionUBE(depression.data[0].ube || false); - } + // Guardar las opciones UBE para Depresión + if (depression.data[0].ube !== originalDepressionUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setDepressionUBE(depression.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalDepressionUBE(depression.data[0].ube || false); + } - // Guardar las opciones UBE para Ansiedad - if (anxiety.data[0].ube !== originalAnxietyUBE) { - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setAnxietyUBE(anxiety.data[0].ube || false); - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setOriginalAnxietyUBE(anxiety.data[0].ube || false); - } + // Guardar las opciones UBE para Ansiedad + if (anxiety.data[0].ube !== originalAnxietyUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setAnxietyUBE(anxiety.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalAnxietyUBE(anxiety.data[0].ube || false); + } - // Guardar las opciones UBE para TOC - if (ocd.data[0].ube !== originalTOCUBE) { - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setTOCUBE(ocd.data[0].ube || false); - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setOriginalTOCUBE(ocd.data[0].ube || false); - } + // Guardar las opciones UBE para TOC + if (ocd.data[0].ube !== originalTOCUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setTOCUBE(ocd.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalTOCUBE(ocd.data[0].ube || false); + } - // Guardar las opciones UBE para TDAH - if (adhd.data[0].ube !== originalTDAHUBE) { - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setTDAHUBE(adhd.data[0].ube || false); - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setOriginalTDAHUBE(adhd.data[0].ube || false); - } + // Guardar las opciones UBE para TDAH + if (adhd.data[0].ube !== originalTDAHUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setTDAHUBE(adhd.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalTDAHUBE(adhd.data[0].ube || false); + } - // Guardar las opciones UBE para Trastorno Bipolar - if (bipolar.data[0].ube !== originalBipolarUBE) { - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setBipolarUBE(bipolar.data[0].ube || false); - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setOriginalBipolarUBE(bipolar.data[0].ube || false); - } + // Guardar las opciones UBE para Trastorno Bipolar + if (bipolar.data[0].ube !== originalBipolarUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setBipolarUBE(bipolar.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalBipolarUBE(bipolar.data[0].ube || false); + } - // Guardar las opciones UBE para Otros - if (other.data[0].ube !== originalOtherUBE) { - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setOtherUBE(other.data[0].ube || false); - // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line - setOriginalOtherUBE(other.data[0].ube || false); - } + // Guardar las opciones UBE para Otros + if (other.data[0].ube !== originalOtherUBE) { + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOtherUBE(other.data[0].ube || false); + // biome-ignore lint/complexity/useSimplifiedLogicExpression: Ignoring simplified logic suggestion for this line + setOriginalOtherUBE(other.data[0].ube || false); + } - // Guardar la condición en Otros - if (other.data[0].illness !== originalOtherIllness) { - setOtherIllness(other.data[0].illness || ""); + // Guardar la condición en Otros + if (other.data[0].illness !== originalOtherIllness) { + setOtherIllness(other.data[0].illness || ""); - setOriginalOtherIllness(other.data[0].illness || ""); + setOriginalOtherIllness(other.data[0].illness || ""); + } } }, [ depression.data, @@ -858,6 +860,7 @@ function PsichiatricView({ originalBipolarUBE, originalDepressionMedications, originalOtherMedications, + isFirstTime, ]); const handleCancel = () => { @@ -1084,9 +1087,10 @@ function PsichiatricView({

Medicamento {index + 1}: @@ -1311,9 +1315,10 @@ function PsichiatricView({

Medicamento {index + 1}: @@ -1538,9 +1543,10 @@ function PsichiatricView({

Medicamento {index + 1}: @@ -1766,7 +1772,7 @@ function PsichiatricView({

Medicamento {index + 1}: @@ -2243,9 +2250,10 @@ function PsichiatricView({

Medicamento {index + 1}: