Skip to content

Commit

Permalink
OEUI-311: Support Order Reason for Lab Orders
Browse files Browse the repository at this point in the history
  • Loading branch information
mogoodrich committed Dec 11, 2024
1 parent 5f935a1 commit 9d0337f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/js/actions/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ export const FETCH_ORDER_REASONS_GLOBAL_PROPERTY_LOADING = 'FETCH_ORDER_REASONS_
export const FETCH_ORDER_REASONS_FAILURE = 'FETCH_ORDER_REASONS_FAILURE';
export const FETCH_ORDER_REASONS_SUCCESS = 'FETCH_ORDER_REASONS_SUCCESS';
export const FETCH_ORDER_REASONS_LOADING = 'FETCH_ORDER_REASONS_LOADING';
export const SET_LAB_ORDER_REASON = 'SET_LAB_ORDER_REASON';
12 changes: 10 additions & 2 deletions app/js/actions/draftActions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DELETE_DRAFT_DRUG_ORDER_SUCCESS, TOGGLE_DRAFT_LAB_ORDER_URGENCY } from './actionTypes';
import {DELETE_DRAFT_DRUG_ORDER_SUCCESS, SET_LAB_ORDER_REASON, TOGGLE_DRAFT_LAB_ORDER_URGENCY} from './actionTypes';

Check failure on line 1 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

A space is required after '{'

Check failure on line 1 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

A space is required before '}'
import { DRUG_ORDER } from '../components/orderEntry/orderTypes';
import { selectDrugSuccess } from './drug';
import { setSelectedOrder } from './orderAction';
import {
removeTestFromDraft,
removeTestPanelFromDraft,
deleteDraftLabOrder,
} from '../actions/draftLabOrderAction';
} from './draftLabOrderAction';
import { deleteAllDrugDraftOrders } from './draftTableAction';
import constants from '../utils/constants';

Expand Down Expand Up @@ -54,3 +54,11 @@ export const discardTestsInDraft = (test = {}) => (dispatch) => {
dispatch(deleteDraftLabOrder());
return dispatch(deleteAllDrugDraftOrders());
};

export const setLabOrderReason = ({order, orderReason}) => {

Check failure on line 58 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

A space is required after '{'

Check failure on line 58 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

A space is required before '}'

Check failure on line 58 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`
return {
type: SET_LAB_ORDER_REASON,
order: order,

Check failure on line 61 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected property shorthand
orderReason: orderReason

Check failure on line 62 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Expected property shorthand

Check failure on line 62 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Missing trailing comma
}

Check warning on line 63 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Missing semicolon
}

Check warning on line 64 in app/js/actions/draftActions.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Missing semicolon
42 changes: 25 additions & 17 deletions app/js/components/Draft.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import fetchOrderReasonsGlobalProperty from "../actions/fetchOrderReasonsGlobalP

export class Draft extends PureComponent {

state = {
orderReasons: null
}

componentDidMount() {
this.props.dispatch(fetchOrderReasonsGlobalProperty());
}
Expand All @@ -24,6 +20,14 @@ export class Draft extends PureComponent {
return draftOrders.map((order) => {
const isPanel = !!order.set;
const isOtherOrderType = !!order.type;
const orderReasons = orderReasonsMap && orderReasonsMap[order.uuid] || null;

// set default order reason if not set
if (orderReasons && orderReasons.members && orderReasons.members.length > 0 && order.orderReason === undefined) {
this.props.setLabOrderReason({orderReason: orderReasons.members[0].uuid, order: order})
}

console.log("reason = ", order.orderReason)

if (isPanel) {
draftType = 'panel';
Expand Down Expand Up @@ -81,19 +85,22 @@ export class Draft extends PureComponent {
</span>
</div>
</li>
<li>
<FormattedMessage
id="app.orders.reason"
defaultMessage="Order Reason"
description="Reason for order" />
<select id="orderReason" name="orderReason">
<option value="0"></option>
<option value="1">Test at Enrollment</option>
<option value="2">Targeted test</option>
<option value="3">Failure Confirmation Test</option>
<option value="3">Routine test</option>
</select>
</li>

{ order.type !== 'drugorder' && orderReasons && orderReasons.members && orderReasons.members.length > 0 &&
<li key={`draft-order-reason-${order.id}`}>
<FormattedMessage
id="app.orders.reason"
defaultMessage="Order Reason"
description="Reason for order" />
<select id="orderReason" name="orderReason" value={order.orderReason}
onChange={(event) => this.props.setLabOrderReason({orderReason: event.target.value, order: order})}>
{orderReasons.members.map((reason) => (
<option value={reason.uuid}>{reason.display}</option>
))}
</select>
</li>
}

</span>
);
});
Expand Down Expand Up @@ -185,6 +192,7 @@ Draft.propTypes = {
editDraftDrugOrder: PropTypes.func.isRequired,
handleSubmit: PropTypes.func.isRequired,
handleDraftDiscard: PropTypes.func.isRequired,
setLabOrderReason: PropTypes.func.isRequired,
toggleDraftLabOrderUrgency: PropTypes.func.isRequired,
showAddResultsButton: PropTypes.bool,
};
Expand Down
5 changes: 5 additions & 0 deletions app/js/components/orderEntry/OrderEntryPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { loadGlobalProperties, APP_GLOBAL_PROPERTIES } from "../../utils/globalP
import {
editDraftDrugOrder,
toggleDraftLabOrderUrgency,
setLabOrderReason,
discardTestsInDraft,
} from '../../actions/draftActions';
import imageLoader from '../../../img/loading.gif';
Expand Down Expand Up @@ -175,6 +176,7 @@ export class OrderEntryPage extends PureComponent {
careSetting: this.props.inpatientCareSetting.uuid,
encounter: this.props.encounterType.uuid,
orderer: this.props.sessionReducer.currentProvider.uuid,
orderReason: order.orderReason,
patient: this.props.patient.uuid,
type: 'testorder',
urgency: order.urgency || 'ROUTINE',
Expand Down Expand Up @@ -385,6 +387,7 @@ export class OrderEntryPage extends PureComponent {
}
editDraftDrugOrder={this.props.editDraftDrugOrder}
locale={this.props.sessionReducer.locale}
setLabOrderReason={this.props.setLabOrderReason}
showAddResultsButton={this.state.addResultsUrl}
/>
</div>
Expand Down Expand Up @@ -492,6 +495,7 @@ OrderEntryPage.propTypes = {
draftLabOrders: PropTypes.object.isRequired,
draftDrugOrders: PropTypes.arrayOf(PropTypes.any).isRequired,
toggleDraftLabOrderUrgency: PropTypes.func.isRequired,
setLabOrderReason: PropTypes.func.isRequired,
discardTestsInDraft: PropTypes.func.isRequired,
createOrder: PropTypes.func.isRequired,
setContext: PropTypes.func.isRequired,
Expand Down Expand Up @@ -577,6 +581,7 @@ const actionCreators = {
createOrder,
setContext,
setRedirectToAddResults,
setLabOrderReason
};

const mapDispatchToProps = dispatch => bindActionCreators(actionCreators, dispatch);
Expand Down
19 changes: 19 additions & 0 deletions app/js/reducers/draftReducer/draftLabOrderReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DELETE_TEST_FROM_DRAFT_LAB_ORDER,
DELETE_PANEL_FROM_DRAFT_LAB_ORDER,
DELETE_ALL_ITEMS_IN_DRAFT_LAB_ORDER,
SET_LAB_ORDER_REASON,
} from '../../actions/actionTypes';
import initialState from '../initialState';

Expand Down Expand Up @@ -121,6 +122,24 @@ export default (state = initialState.draftReducer, action) => {
};
}

case SET_LAB_ORDER_REASON: {
const { order, orderReason } = action;
return {
...state,
draftLabOrders: {
...state.draftLabOrders,
orders: state.draftLabOrders.orders.map((draftOrder) => {
if (draftOrder.uuid === order.uuid) {
return { ...draftOrder, orderReason: orderReason };
} else {
return draftOrder;
}
})
},
};
}


case DELETE_PANEL_FROM_DRAFT_LAB_ORDER: {
const panel = action.orders;
const panelTests = action.orders.setMembers;
Expand Down

0 comments on commit 9d0337f

Please sign in to comment.