From 505955196c78fab9ec891701111fde6fb9bda5da Mon Sep 17 00:00:00 2001 From: Joyce Quach Date: Tue, 20 Feb 2024 16:16:33 -0500 Subject: [PATCH 1/6] Rename method to camelcase --- src/containers/RequestBuilder.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/containers/RequestBuilder.js b/src/containers/RequestBuilder.js index 7d4c3d5c..465663b3 100644 --- a/src/containers/RequestBuilder.js +++ b/src/containers/RequestBuilder.js @@ -43,7 +43,7 @@ export default class RequestBuilder extends Component { }; this.updateStateElement = this.updateStateElement.bind(this); - this.submit_info = this.submit_info.bind(this); + this.submitInfo = this.submitInfo.bind(this); this.consoleLog = this.consoleLog.bind(this); this.takeSuggestion = this.takeSuggestion.bind(this); this.requestBox = React.createRef(); @@ -102,7 +102,7 @@ export default class RequestBuilder extends Component { return controller; }; - submit_info(prefetch, request, patient, hook) { + submitInfo(prefetch, request, patient, hook) { this.setState({ loading: true }); this.consoleLog('Initiating form submission', types.info); this.setState({ patient }); @@ -293,7 +293,7 @@ export default class RequestBuilder extends Component { Date: Wed, 21 Feb 2024 23:37:23 -0500 Subject: [PATCH 2/6] Move MedicationDispense fetching up to parent component --- .../MedicationStatus/MedicationStatus.jsx | 22 +++------------- src/containers/RequestBuilder.js | 25 ++++++++++++++++--- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/components/MedicationStatus/MedicationStatus.jsx b/src/components/MedicationStatus/MedicationStatus.jsx index 745148de..d023bdc8 100644 --- a/src/components/MedicationStatus/MedicationStatus.jsx +++ b/src/components/MedicationStatus/MedicationStatus.jsx @@ -1,30 +1,14 @@ -import axios from 'axios'; import { MedicationStatusButton } from './MedicationStatusButton.jsx'; import { MedicationStatusModal } from './MedicationStatusModal.jsx'; import { useState, useEffect } from 'react'; import { Card } from '@mui/material'; export const MedicationStatus = props => { - const { ehrUrl, request } = props; - const [medicationDispense, setMedicationDispense] = useState(null); + const { ehrUrl, request, medicationDispense, getMedicationStatus, lastCheckedMedicationTime } = + props; const [showMedicationStatus, setShowMedicationStatus] = useState(false); - const [lastCheckedMedicationTime, setLastCheckedMedicationTime] = useState(null); - useEffect(() => getMedicationStatus(), [request.id]); - - const getMedicationStatus = () => { - setLastCheckedMedicationTime(Date.now()); - - axios.get(`${ehrUrl}/MedicationDispense?prescription=${request.id}`).then( - response => { - const bundle = response.data; - setMedicationDispense(bundle.entry?.[0].resource); - }, - error => { - console.log('Was not able to get medication status', error); - } - ); - }; + useEffect(() => getMedicationStatus(), [request.id, ehrUrl]); const handleCloseMedicationStatus = () => { setShowMedicationStatus(false); diff --git a/src/containers/RequestBuilder.js b/src/containers/RequestBuilder.js index 465663b3..fdc6959d 100644 --- a/src/containers/RequestBuilder.js +++ b/src/containers/RequestBuilder.js @@ -7,7 +7,7 @@ import DisplayBox from '../components/DisplayBox/DisplayBox'; import '../index.css'; import RequestBox from '../components/RequestBox/RequestBox'; import buildRequest from '../util/buildRequest.js'; -import { types, defaultValues, headerDefinitions } from '../util/data.js'; +import { types, defaultValues as codeValues, headerDefinitions } from '../util/data.js'; import { createJwt } from '../util/auth'; import env from 'env-var'; @@ -20,6 +20,7 @@ import SettingsIcon from '@mui/icons-material/Settings'; import PatientSearchBar from '../components/RequestBox/PatientSearchBar/PatientSearchBar'; import { MedicationStatus } from '../components/MedicationStatus/MedicationStatus.jsx'; import { actionTypes } from './ContextProvider/reducer.js'; +import axios from 'axios'; export default class RequestBuilder extends Component { constructor(props) { @@ -39,7 +40,8 @@ export default class RequestBuilder extends Component { showSettings: false, token: null, client: this.props.client, - codeValues: defaultValues + medicationDispense: null, + lastCheckedMedicationTime: null }; this.updateStateElement = this.updateStateElement.bind(this); @@ -49,6 +51,20 @@ export default class RequestBuilder extends Component { this.requestBox = React.createRef(); } + getMedicationStatus = () => { + this.setState({ lastCheckedMedicationTime: Date.now() }); + + axios.get(`${this.state.ehrUrl}/MedicationDispense?prescription=${this.state.request.id}`).then( + response => { + const bundle = response.data; + this.setState({ medicationDispense: bundle.entry?.[0].resource }); + }, + error => { + console.log('Was not able to get medication status', error); + } + ); + }; + componentDidMount() { if (!this.state.client) { this.reconnectEhr(); @@ -272,7 +288,7 @@ export default class RequestBuilder extends Component { callbackMap={this.updateStateMap} // updatePrefetchCallback={PrefetchTemplate.generateQueries} clearCallback={this.clearState} - options={this.state.codeValues} + options={codeValues} responseExpirationDays={this.props.globalState.responseExpirationDays} defaultUser={this.props.globalState.defaultUser} /> @@ -323,6 +339,9 @@ export default class RequestBuilder extends Component { )} From fac2edfc08be520a31adbc6da84c4318dcbda831 Mon Sep 17 00:00:00 2001 From: Joyce Quach Date: Mon, 26 Feb 2024 11:01:52 -0500 Subject: [PATCH 3/6] Remove unused code --- src/containers/RequestBuilder.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/containers/RequestBuilder.js b/src/containers/RequestBuilder.js index fdc6959d..60bc2b97 100644 --- a/src/containers/RequestBuilder.js +++ b/src/containers/RequestBuilder.js @@ -286,9 +286,7 @@ export default class RequestBuilder extends Component { callback={this.updateStateElement} callbackList={this.updateStateList} callbackMap={this.updateStateMap} - // updatePrefetchCallback={PrefetchTemplate.generateQueries} clearCallback={this.clearState} - options={codeValues} responseExpirationDays={this.props.globalState.responseExpirationDays} defaultUser={this.props.globalState.defaultUser} /> From 6b6940b6852c4f9ee4571f583f609e4f1eebd7f5 Mon Sep 17 00:00:00 2001 From: Joyce Quach Date: Mon, 26 Feb 2024 11:24:43 -0500 Subject: [PATCH 4/6] Fix incorrect variable --- src/containers/RequestBuilder.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/containers/RequestBuilder.js b/src/containers/RequestBuilder.js index 60bc2b97..e589d618 100644 --- a/src/containers/RequestBuilder.js +++ b/src/containers/RequestBuilder.js @@ -54,15 +54,17 @@ export default class RequestBuilder extends Component { getMedicationStatus = () => { this.setState({ lastCheckedMedicationTime: Date.now() }); - axios.get(`${this.state.ehrUrl}/MedicationDispense?prescription=${this.state.request.id}`).then( - response => { - const bundle = response.data; - this.setState({ medicationDispense: bundle.entry?.[0].resource }); - }, - error => { - console.log('Was not able to get medication status', error); - } - ); + axios + .get(`${this.globalState.ehrUrl}/MedicationDispense?prescription=${this.state.request.id}`) + .then( + response => { + const bundle = response.data; + this.setState({ medicationDispense: bundle.entry?.[0].resource }); + }, + error => { + console.log('Was not able to get medication status', error); + } + ); }; componentDidMount() { From 06b1ca11e8d8f0179c6fe23354717af1f5b9852e Mon Sep 17 00:00:00 2001 From: Joyce Quach Date: Mon, 26 Feb 2024 11:27:10 -0500 Subject: [PATCH 5/6] Fix typo again --- src/containers/RequestBuilder.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/containers/RequestBuilder.js b/src/containers/RequestBuilder.js index e589d618..7904d594 100644 --- a/src/containers/RequestBuilder.js +++ b/src/containers/RequestBuilder.js @@ -55,7 +55,9 @@ export default class RequestBuilder extends Component { this.setState({ lastCheckedMedicationTime: Date.now() }); axios - .get(`${this.globalState.ehrUrl}/MedicationDispense?prescription=${this.state.request.id}`) + .get( + `${this.props.globalState.ehrUrl}/MedicationDispense?prescription=${this.state.request.id}` + ) .then( response => { const bundle = response.data; From 461f596a0fe375b983be9ddc903cad7818814f18 Mon Sep 17 00:00:00 2001 From: Joyce Quach Date: Mon, 26 Feb 2024 12:28:23 -0500 Subject: [PATCH 6/6] Move update startup dispatch call out of for loop since if local storage is empty, the dispatch will never happen --- src/components/RequestDashboard/SettingsSection.jsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/RequestDashboard/SettingsSection.jsx b/src/components/RequestDashboard/SettingsSection.jsx index ec5a97fd..9c704046 100644 --- a/src/components/RequestDashboard/SettingsSection.jsx +++ b/src/components/RequestDashboard/SettingsSection.jsx @@ -34,10 +34,11 @@ const SettingsSection = props => { console.log('Could not load setting:' + element[0]); } } - // indicate to the rest of the app that the settings have been loaded - dispatch({ - type: actionTypes.flagStartup - }); + }); + + // indicate to the rest of the app that the settings have been loaded + dispatch({ + type: actionTypes.flagStartup }); }, []); const updateSetting = (key, value) => {