@@ -9,9 +9,7 @@ import { Column, Grid, Loading } from '@carbon/react';
99import * as styles from './styles/ConsultationPad.module.scss' ;
1010import BasicForm from '@components/clinical/basicForm/BasicForm' ;
1111import DiagnosesForm from '@components/clinical/diagnosesForm/DiagnosesForm' ;
12- import { SelectedDiagnosisItemProps } from '@components/clinical/diagnosesForm/SelectedDiagnosisItem' ;
1312import { Concept } from '@types/encounterConcepts' ;
14- import { ConceptSearch } from '@types/concepts' ;
1513import { ConsultationBundle } from '@types/consultationBundle' ;
1614import {
1715 postConsultationBundle ,
@@ -24,9 +22,8 @@ import {
2422 createBundleEntry ,
2523 createConsultationBundle ,
2624} from '@utils/fhir/consultationBundleCreator' ;
27- import { CERTAINITY_CONCEPTS } from '@constants/concepts' ;
2825import { ERROR_TITLES } from '@constants/errors' ;
29- import { Coding } from 'fhir/r4 ' ;
26+ import { useDiagnosisStore } from '@stores/diagnosisStore ' ;
3027
3128interface ConsultationPadProps {
3229 patientUUID : string ;
@@ -38,46 +35,13 @@ const ConsultationPad: React.FC<ConsultationPadProps> = ({
3835 onClose,
3936} ) => {
4037 const [ isSubmitting , setIsSubmitting ] = React . useState ( false ) ;
41- const [ selectedDiagnoses , setSelectedDiagnoses ] = React . useState <
42- SelectedDiagnosisItemProps [ ]
43- > ( [ ] ) ;
4438
4539 const { t } = useTranslation ( ) ;
4640 const { addNotification } = useNotification ( ) ;
4741
48- const handleResultSelection = ( selectedItem : ConceptSearch ) => {
49- // Create new diagnosis with certainty handler
50- const newDiagnosis : SelectedDiagnosisItemProps = {
51- id : selectedItem . conceptUuid ,
52- title : selectedItem . conceptName ,
53- certaintyConcepts : CERTAINITY_CONCEPTS ,
54- selectedCertainty : null ,
55- handleCertaintyChange : ( data ) => {
56- handleCertaintyChange ( selectedItem . conceptUuid , data . selectedItem ) ;
57- } ,
58- } ;
59-
60- setSelectedDiagnoses ( [ ...selectedDiagnoses , newDiagnosis ] ) ;
61- } ;
62-
63- const handleRemoveDiagnosis = ( index : number ) => {
64- setSelectedDiagnoses ( ( prevDiagnoses ) =>
65- prevDiagnoses . filter ( ( _ , i ) => i !== index ) ,
66- ) ;
67- } ;
68-
69- const handleCertaintyChange = (
70- diagnosisId : string ,
71- selectedCertainty : Coding | null | undefined ,
72- ) => {
73- setSelectedDiagnoses ( ( prevDiagnoses ) =>
74- prevDiagnoses . map ( ( diagnosis ) =>
75- diagnosis . id === diagnosisId
76- ? { ...diagnosis , selectedCertainty : selectedCertainty || null }
77- : diagnosis ,
78- ) ,
79- ) ;
80- } ;
42+ // Use the diagnosis store
43+ const { selectedDiagnoses, validateAllDiagnoses, reset } =
44+ useDiagnosisStore ( ) ;
8145
8246 const {
8347 locations,
@@ -158,10 +122,16 @@ const ConsultationPad: React.FC<ConsultationPadProps> = ({
158122
159123 const handleOnPrimaryButtonClick = async ( ) => {
160124 if ( ! isSubmitting && canSubmitConsultation ) {
125+ const isDiagnosesValid = validateAllDiagnoses ( ) ;
126+ if ( ! isDiagnosesValid ) {
127+ return ;
128+ }
129+
161130 try {
162131 setIsSubmitting ( true ) ;
163132 await submitConsultation ( ) ;
164133 setIsSubmitting ( false ) ;
134+ reset ( ) ;
165135 addNotification ( {
166136 title : t ( 'CONSULTATION_SUBMITTED_SUCCESS_TITLE' ) ,
167137 message : t ( 'CONSULTATION_SUBMITTED_SUCCESS_MESSAGE' ) ,
@@ -269,11 +239,7 @@ const ConsultationPad: React.FC<ConsultationPadProps> = ({
269239 locationSelected = { locations [ 0 ] }
270240 defaultDate = { formattedDate . formattedResult }
271241 />
272- < DiagnosesForm
273- handleResultSelection = { handleResultSelection }
274- selectedDiagnoses = { selectedDiagnoses }
275- handleRemoveDiagnosis = { handleRemoveDiagnosis }
276- />
242+ < DiagnosesForm />
277243 </ >
278244 }
279245 />
0 commit comments