Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): edit medical file #1684

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/src/scenes/Persons/MedicalFile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import styled from 'styled-components';
import dayjs from 'dayjs';
import { useRecoilState, useRecoilValue } from 'recoil';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { v4 as uuidv4 } from 'uuid';
import ScrollContainer from '../../components/ScrollContainer';
import Button from '../../components/Button';
Expand All @@ -28,6 +27,7 @@ import CommentRow from '../Comments/CommentRow';
import NewCommentInput from '../Comments/NewCommentInput';
import { Alert } from 'react-native';
import { formatBirthDateAndAge } from '../../services/dateDayjs';
import { itemsGroupedByPersonSelector } from '../../recoil/selectors';

const MedicalFile = ({ navigation, person, personDB, onUpdatePerson, updating, editable, onEdit, isUpdateDisabled, backgroundColor, onChange }) => {
const organisation = useRecoilValue(organisationState);
Expand All @@ -39,14 +39,17 @@ const MedicalFile = ({ navigation, person, personDB, onUpdatePerson, updating, e

const allConsultations = useRecoilValue(consultationsState);
const allTreatments = useRecoilValue(treatmentsState);
const [allMedicalFiles, setAllMedicalFiles] = useRecoilState(medicalFileState);
const setAllMedicalFiles = useSetRecoilState(medicalFileState);

const consultations = useMemo(() => (allConsultations || []).filter((c) => c.person === personDB._id), [allConsultations, personDB._id]);

const treatments = useMemo(() => (allTreatments || []).filter((t) => t.person === personDB._id), [allTreatments, personDB._id]);

const medicalFileDB = useMemo(() => (allMedicalFiles || []).find((m) => m.person === personDB._id), [allMedicalFiles, personDB._id]);
const [medicalFile, setMedicalFile] = useState(medicalFileDB);
const populatedPersons = useRecoilValue(itemsGroupedByPersonSelector);
const populatedPerson = useMemo(() => populatedPersons[personDB?._id] || {}, [populatedPersons, personDB._id]);

const medicalFileDB = populatedPerson.medicalFile;
const [medicalFile, setMedicalFile] = useState(populatedPerson.medicalFile);
const [writingComment, setWritingComment] = useState('');

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions dashboard/src/scenes/person/components/EditModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { outOfBoundariesDate } from '../../../services/date';
import SelectTeamMultiple from '../../../components/SelectTeamMultiple';
import { currentTeamState, userState } from '../../../recoil/auth';
import { useRecoilState, useRecoilValue } from 'recoil';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import CustomFieldInput from '../../../components/CustomFieldInput';
import { useMemo, useState } from 'react';
import ButtonCustom from '../../../components/ButtonCustom';
Expand All @@ -31,8 +31,8 @@ export default function EditModal({ person, selectedPanel, onClose, isMedicalFil
const team = useRecoilValue(currentTeamState);
const [persons, setPersons] = useRecoilState(personsState);
const customFieldsMedicalFile = useRecoilValue(customFieldsMedicalFileSelector);
const [allMedicalFiles, setAllMedicalFiles] = useRecoilState(medicalFileState);
const medicalFile = useMemo(() => (allMedicalFiles || []).find((m) => m.person === person._id), [allMedicalFiles, person._id]);
const setAllMedicalFiles = useSetRecoilState(medicalFileState);
const medicalFile = person.medicalFile;

const customFieldsMedicalFileWithLegacyFields = useMemo(() => {
const c = [...customFieldsMedicalFile];
Expand Down
5 changes: 2 additions & 3 deletions dashboard/src/scenes/person/components/MedicalFilePrint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import CustomFieldDisplay from '../../../components/CustomFieldDisplay';
import { sortActionsOrConsultations } from '../../../recoil/actions';
import { arrayOfitemsGroupedByConsultationSelector } from '../../../recoil/selectors';
import { treatmentsState } from '../../../recoil/treatments';
import { medicalFileState, customFieldsMedicalFileSelector } from '../../../recoil/medicalFiles';
import { customFieldsMedicalFileSelector } from '../../../recoil/medicalFiles';
import { useLocalStorage } from '../../../services/useLocalStorage';

export function MedicalFilePrint({ person }) {
const organisation = useRecoilValue(organisationState);
const allConsultations = useRecoilValue(arrayOfitemsGroupedByConsultationSelector);
const allTreatments = useRecoilValue(treatmentsState);
const allMedicalFiles = useRecoilValue(medicalFileState);
const team = useRecoilValue(currentTeamState);

const [consultationTypes] = useLocalStorage('consultation-types', []);
Expand All @@ -39,7 +38,7 @@ export function MedicalFilePrint({ person }) {

const treatments = useMemo(() => (allTreatments || []).filter((t) => t.person === person._id), [allTreatments, person._id]);

const medicalFile = useMemo(() => (allMedicalFiles || []).find((m) => m.person === person._id), [allMedicalFiles, person._id]);
const medicalFile = person.medicalFile;

return (
<div className="printonly">
Expand Down
Loading