From 7d220fb1bc81d751a518903a68a8b262e3beb2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Huchet?= Date: Mon, 28 Mar 2022 11:38:57 +0200 Subject: [PATCH] feat(dashboard,app): only healthcare professional --- api/src/controllers/organisation.js | 1 + app/src/scenes/Persons/FileMedical.js | 4 ++- dashboard/src/components/TableCustomFields.js | 30 +++++++++++++++++-- dashboard/src/scenes/organisation/view.js | 1 + dashboard/src/scenes/person/view.js | 1 + 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/api/src/controllers/organisation.js b/api/src/controllers/organisation.js index cb329b95c..224d0073a 100644 --- a/api/src/controllers/organisation.js +++ b/api/src/controllers/organisation.js @@ -148,6 +148,7 @@ router.put( enabled: z.optional(z.boolean()), required: z.optional(z.boolean()), showInStats: z.optional(z.boolean()), + onlyHealthcareProfessional: z.optional(z.boolean()), options: z.optional(z.array(z.string())), }) .strict(); diff --git a/app/src/scenes/Persons/FileMedical.js b/app/src/scenes/Persons/FileMedical.js index ecc6e060e..66f8451e3 100644 --- a/app/src/scenes/Persons/FileMedical.js +++ b/app/src/scenes/Persons/FileMedical.js @@ -11,10 +11,11 @@ import InputLabelled from '../../components/InputLabelled'; import colors from '../../utils/colors'; import CustomFieldInput from '../../components/CustomFieldInput'; import { customFieldsPersonsMedicalSelector } from '../../recoil/persons'; +import { userState } from '../../recoil/auth'; const FileMedical = ({ navigation, editable, onChange, onUpdatePerson, onEdit, isUpdateDisabled, updating, backgroundColor, person }) => { const customFieldsPersonsMedical = useRecoilValue(customFieldsPersonsMedicalSelector); - + const user = useRecoilValue(userState); const scrollViewRef = useRef(null); const refs = useRef({}); const _scrollToInput = (ref) => { @@ -49,6 +50,7 @@ const FileMedical = ({ navigation, editable, onChange, onUpdatePerson, onEdit, i {(customFieldsPersonsMedical || []) .filter((f) => f) .filter((f) => f.enabled) + .filter((f) => !f.onlyHealthcareProfessional || user.healthcareProfessional) .map((field) => { const { label, name } = field; return ( diff --git a/dashboard/src/components/TableCustomFields.js b/dashboard/src/components/TableCustomFields.js index cdeb5037c..ae500348f 100644 --- a/dashboard/src/components/TableCustomFields.js +++ b/dashboard/src/components/TableCustomFields.js @@ -10,6 +10,7 @@ import useApi from '../services/api'; import ButtonCustom from './ButtonCustom'; import SelectCustom from './SelectCustom'; import Table from './table'; +import QuestionMarkButton from './QuestionMarkButton'; const newField = () => ({ // Todo: I guess could use crypto here. @@ -23,7 +24,7 @@ const newField = () => ({ const getValueFromType = (type) => typeOptions.find((opt) => opt.value === type); -const TableCustomFields = ({ data, customFields }) => { +const TableCustomFields = ({ data, customFields, showHealthcareProfessionnalColumn = false }) => { const [isSubmitting, setIsSubmitting] = useState(false); const [mutableData, setMutableData] = useState(data); const [editingField, setEditingField] = useState(null); @@ -41,6 +42,11 @@ const TableCustomFields = ({ data, customFields }) => { setMutableData(mutableData.map((field) => (field.name !== fieldToUpdate.name ? field : { ...fieldToUpdate, showInStats }))); }; + const onOnlyHealthcareProfessionalChange = (fieldToUpdate) => (event) => { + const onlyHealthcareProfessional = event.target.checked; + setMutableData(mutableData.map((field) => (field.name !== fieldToUpdate.name ? field : { ...fieldToUpdate, onlyHealthcareProfessional }))); + }; + const onSaveField = async (editedField) => { const isUpdate = !!mutableData.find((f) => f.name === editedField.name); const newData = isUpdate ? mutableData.map((field) => (field.name !== editedField.name ? field : editedField)) : [...mutableData, editedField]; @@ -137,12 +143,29 @@ const TableCustomFields = ({ data, customFields }) => { render: (f) => {!['enum', 'multi-choice'].includes(f.type) ? null : (f?.options || []).join(', ')}, }, { title: 'Activé', dataKey: 'enabled', render: (f) => }, + !showHealthcareProfessionnalColumn + ? null + : { + title: ( +
+ Professionnel +
santé + { + alert('Le champ ne sera visible que par les comptes de type "professionnel de santé" dans un onglet dédié.'); + }} + /> +
+ ), + dataKey: 'onlyHealthcareProfessional', + render: (f) => , + }, { title: ( <> Voir dans les
- satistiques + statistiques ), dataKey: 'showInStats', @@ -154,7 +177,8 @@ const TableCustomFields = ({ data, customFields }) => { small: true, render: (f) => onDelete(f)} width={75} color="danger" />, }, - ]} + // Remove null fields + ].filter((e) => e)} /> setIsNewField(true)} width={200} /> diff --git a/dashboard/src/scenes/organisation/view.js b/dashboard/src/scenes/organisation/view.js index c2127f5b0..fc6bed36e 100644 --- a/dashboard/src/scenes/organisation/view.js +++ b/dashboard/src/scenes/organisation/view.js @@ -386,6 +386,7 @@ const View = () => { { if (Array.isArray(organisation.customFieldsPersonsMedical)) return organisation.customFieldsPersonsMedical; diff --git a/dashboard/src/scenes/person/view.js b/dashboard/src/scenes/person/view.js index 1a261fb6a..f43c81b4b 100644 --- a/dashboard/src/scenes/person/view.js +++ b/dashboard/src/scenes/person/view.js @@ -414,6 +414,7 @@ const Summary = ({ person }) => { {customFieldsPersonsMedical .filter((f) => f.enabled) + .filter((f) => !f.onlyHealthcareProfessional || user.healthcareProfessional) .map((field) => ( ))}