@@ -7,76 +7,85 @@ import { createMedicationFromMedicationRequest } from '../../../util/fhir';
77import { standardsBasedGetEtasu } from '../../../util/util' ;
88
99const NotificationsSection = ( ) => {
10- const [ globalState , _ ] = useContext ( SettingsContext ) ;
11- const classes = useStyles ( ) ;
12- const [ etasu , setEtasu ] = useState ( [ ] ) ;
13- const [ medications , setMedications ] = useState ( [ ] ) ;
14- useEffect ( ( ) => {
15- setEtasu ( [ ] ) ;
16- getMedicationRequest ( ) ;
17- } , [ ] ) ;
10+ const [ globalState , _ ] = useContext ( SettingsContext ) ;
11+ const classes = useStyles ( ) ;
12+ const [ etasu , setEtasu ] = useState ( [ ] ) ;
13+ const [ medications , setMedications ] = useState ( [ ] ) ;
14+ useEffect ( ( ) => {
15+ setEtasu ( [ ] ) ;
16+ getMedicationRequest ( ) ;
17+ } , [ ] ) ;
1818
19- useEffect ( ( ) => {
20- getAllEtasu ( ) ;
21- } , [ medications ] ) ;
19+ useEffect ( ( ) => {
20+ getAllEtasu ( ) ;
21+ } , [ medications ] ) ;
2222
23- const getMedicationRequest = ( ) => {
24- const patientsMedications = [ ] ;
25- axios ( {
26- method : 'get' ,
27- url : `${ globalState . baseUrl } /MedicationRequest?subject=Patient/${ globalState . patient . id } `
28- } ) . then ( ( result ) => {
29- result ?. data . entry . forEach ( ( m ) => {
30- const medication = createMedicationFromMedicationRequest ( m . resource ) ;
31- patientsMedications . push ( medication ) ;
32- } )
33- setMedications ( patientsMedications ) ;
34- } , ( error ) => {
35- console . error ( error ) ;
23+ const getMedicationRequest = ( ) => {
24+ const patientsMedications = [ ] ;
25+ axios ( {
26+ method : 'get' ,
27+ url : `${ globalState . baseUrl } /MedicationRequest?subject=Patient/${ globalState . patient . id } `
28+ } ) . then (
29+ result => {
30+ result ?. data . entry . forEach ( m => {
31+ const medication = createMedicationFromMedicationRequest ( m . resource ) ;
32+ patientsMedications . push ( medication ) ;
3633 } ) ;
37- } ;
34+ setMedications ( patientsMedications ) ;
35+ } ,
36+ error => {
37+ console . error ( error ) ;
38+ }
39+ ) ;
40+ } ;
3841
39- const compileResponses = ( newRequest , body ) => {
40- if ( newRequest . contained ) {
41- newRequest . body = body ;
42- setEtasu ( prevState => [ ...prevState , newRequest ] ) ;
43- }
42+ const compileResponses = ( newRequest , body ) => {
43+ if ( newRequest . contained ) {
44+ newRequest . body = body ;
45+ setEtasu ( prevState => [ ...prevState , newRequest ] ) ;
4446 }
47+ } ;
4548
46- const getAllEtasu = ( ) => {
47- medications . forEach ( ( medication ) => {
48- const body = makeBody ( medication ) ;
49- const standardEtasuUrl = `${ globalState . remsAdminServer } /4_0_0/GuidanceResponse/$rems-etasu` ;
50- standardsBasedGetEtasu ( standardEtasuUrl , body , compileResponses ) ;
51- } ) ;
52-
53- }
49+ const getAllEtasu = ( ) => {
50+ medications . forEach ( medication => {
51+ const body = makeBody ( medication ) ;
52+ const standardEtasuUrl = `${ globalState . remsAdminServer } /4_0_0/GuidanceResponse/$rems-etasu` ;
53+ standardsBasedGetEtasu ( standardEtasuUrl , body , compileResponses ) ;
54+ } ) ;
55+ } ;
5456
55- const makeBody = ( medication ) => {
56- return {
57- resourceType : "Parameters" ,
58- parameter : [
59- {
60- name : 'patient' ,
61- resource : globalState . patient
62- } ,
63- {
64- name : 'medication' ,
65- resource : medication
66- }
67- ]
57+ const makeBody = medication => {
58+ return {
59+ resourceType : 'Parameters' ,
60+ parameter : [
61+ {
62+ name : 'patient' ,
63+ resource : globalState . patient
64+ } ,
65+ {
66+ name : 'medication' ,
67+ resource : medication
6868 }
69- }
69+ ]
70+ } ;
71+ } ;
7072
71- return (
72- < div className = { classes . dashboardArea } >
73- < h2 className = { classes . elementHeader } > Notifications</ h2 >
74- { etasu . map ( ( remsCase ) => {
75- const display = remsCase . body . parameter [ 1 ] ?. resource . code . coding [ 0 ] . display ;
76- return < EtasuStatusComponent key = { display } display = { display } remsAdminResponseInit = { remsCase } data = { remsCase . body } />
77- } ) }
78- </ div >
79- ) ;
73+ return (
74+ < div className = { classes . dashboardArea } >
75+ < h2 className = { classes . elementHeader } > Notifications</ h2 >
76+ { etasu . map ( remsCase => {
77+ const display = remsCase . body . parameter [ 1 ] ?. resource . code . coding [ 0 ] . display ;
78+ return (
79+ < EtasuStatusComponent
80+ key = { display }
81+ display = { display }
82+ remsAdminResponseInit = { remsCase }
83+ data = { remsCase . body }
84+ />
85+ ) ;
86+ } ) }
87+ </ div >
88+ ) ;
8089} ;
8190
8291export default memo ( NotificationsSection ) ;
0 commit comments