Skip to content

Commit

Permalink
Merge pull request #49 from mcode/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
smalho01 authored Aug 1, 2023
2 parents 1f621bc + 2f33ee7 commit befce55
Show file tree
Hide file tree
Showing 18 changed files with 1,095 additions and 75 deletions.
31 changes: 31 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Development URLS

REACT_APP_REALM = ClientFhirServer
REACT_APP_CLIENT = app-login
REACT_APP_AUTH = http://localhost:8180
REACT_APP_SERVER = http://localhost:8090
REACT_APP_EHR_SERVER = http://localhost:8080/test-ehr/r4
REACT_APP_EHR_BASE = http://localhost:8080/test-ehr/r4
REACT_APP_CDS_SERVICE = http://localhost:8090/cds-services
REACT_APP_ORDER_SIGN = rems-order-sign
REACT_APP_ORDER_SELECT = rems-order-select
REACT_APP_USER = alice
REACT_APP_PASSWORD = alice
REACT_APP_PUBLIC_KEYS = http://localhost:3001/public_keys
REACT_APP_ALT_DRUG = true
REACT_APP_LAUNCH_URL = http://localhost:4040/launch
REACT_APP_SMART_LAUNCH_URL = http://localhost:4040/
REACT_APP_DEFAULT_USER = pra1234
REACT_APP_RESPONSE_EXPIRATION_DAYS = 30
REACT_APP_PIMS_SERVER = http://localhost:5051/doctorOrders/api/addRx
REACT_APP_HOMEPAGE = http://localhost:8080
REACT_APP_URL = http://localhost:3000
REACT_APP_URL_FILTER = http://localhost:3000/*
REACT_APP_EHR_LINK = http://localhost:8080/ehr-server/
HTTPS = false
HTTPS_KEY_PATH = server.key
HTTPS_CERT_PATH = server.cert

# To Override start command:
# REACT_APP_AUTH=http://example.com PORT=6000 npm start
# Note that .env values can only be accessed by react app starting with 'REACT_APP_'
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ typings/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

Expand Down
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,42 @@ This subproject provides a small web application that is capable of generating C
4. Run the application
* `npm start`

This should open a browser window directed to http://localhost:3000. The request-generator assumes the CRD server is running on `localhost:8090`. This can be changed in the properties file [properties.json](src/properties.json).
This should open a browser window directed to the value set in `REACT_APP_URL`. The request-generator assumes the CRD server is running on the default value set for `REACT_APP_SERVER`. This can be changed in the properties file [.env](./.env). [The following section](./README.md#how-to-override-defaults) lists the default values for these environment variables.

## Versions
This application requires node v20.0 or greater.


### How To Override Defaults
The .env file contains the default URI paths, these can be overwritten from the start command as follows:
`REACT_APP_LAUNCH_URL=http://example.com PORT=6000 npm start`

Following are a list of modifiable paths:

| URI Name | Default |
| -----------------------|--------------------------------------------------|
| REACT_APP_AUTH | `http://localhost:8180` |
| REACT_APP_EHR_SERVER | `http://localhost:8080/test-ehr/r4` |
| REACT_APP_CDS_SERVICE | `http://localhost:8090/cds-services` |
| REACT_APP_PUBLIC_KEYS | `http://localhost:3001/public_keys` |
| REACT_APP_LAUNCH_URL | `http://localhost:3005/launch` |
| REACT_APP_PIMS_SERVER | `http://localhost:5051/doctorOrders/api/addRx` |
| REACT_APP_REALM | `ClientFhirServer` |
| REACT_APP_CLIENT | `app-login` |
| REACT_APP_SERVER | `http://localhost:8090` |
| REACT_APP_EHR_BASE | `http://localhost:8080/test-ehr/r4` |
| REACT_APP_ORDER_SIGN | `rems-order-sign` |
| REACT_APP_ORDER_SELECT | `rems-order-select` |
| REACT_APP_USER | `alice` |
| REACT_APP_PASSWORD | `alice` |
| REACT_APP_ALT_DRUG | `true` |
| REACT_APP_SMART_LAUNCH_URL | `http://localhost:4040/` |
| REACT_APP_DEFAULT_USER | `pra1234` |
| REACT_APP_RESPONSE_EXPIRATION_DAYS | `30` |
| REACT_APP_HOMEPAGE | `http://localhost:8080` |
| REACT_APP_URL | `http://localhost:3000` |
| REACT_APP_URL_FILTER | `http://localhost:3000/*` |
| REACT_APP_EHR_LINK | `http://localhost:8080/ehr-server/` |
| HTTPS | `false` |
| HTTPS_KEY_PATH | `server.key` |
| HTTPS_CERT_PATH | `server.cert` |
16 changes: 13 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"base64url": "^3.0.0",
"classnames": "^2.2.6",
"clone": "^2.1.2",
"dotenv": "^16.3.1",
"env-var": "^7.3.1",
"fhirclient": "^2.3.1",
"json-server": "^0.16.3",
"jsrsasign": "^10.2.0",
Expand Down
7 changes: 4 additions & 3 deletions src/components/Auth/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { TextField, Button } from '@material-ui/core';
import Alert from './Alert';
import axios from 'axios';
import useStyles from './styles';
import config from '../../properties.json';
import env from 'env-var';

const Login = (props) => {
const classes = useStyles();
const [message, setMessage] = useState(null);
Expand All @@ -17,10 +18,10 @@ const Login = (props) => {
params.append('username', username);
params.append('password', password);
params.append('grant_type', 'password');
params.append('client_id', config.client);
params.append('client_id', env.get('REACT_APP_CLIENT').asString());
axios
.post(
`${config.auth}/realms/${config.realm}/protocol/openid-connect/token`,
`${env.get('REACT_APP_AUTH').asString()}/realms/${env.get('REACT_APP_REALM').asString()}/protocol/openid-connect/token`,
params,
{ withCredentials: true }
)
Expand Down
2 changes: 0 additions & 2 deletions src/components/DisplayBox/DisplayBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ export default class DisplayBox extends Component{
*/
takeSuggestion(suggestion, url, buttonId, suggestionCount, cardNum, selectionBehavior) {
if (!this.props.isDemoCard) {
console.log("taking suggestion");

if (selectionBehavior === 'at-most-one') {
// disable all suggestion buttons for this card
for (var i = 0; i < suggestionCount; i++) {
Expand Down
41 changes: 36 additions & 5 deletions src/components/RequestBox/RequestBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import _ from "lodash";
import "./request.css";
import { PrefetchTemplate } from "../../PrefetchTemplate";
import { retrieveLaunchContext } from "../../util/util";
import env from 'env-var';

export default class RequestBox extends Component {
constructor(props) {
Expand Down Expand Up @@ -41,7 +42,6 @@ export default class RequestBox extends Component {

// TODO - see how to submit response for alternative therapy
replaceRequestAndSubmit(request) {
console.log("replaceRequestAndSubmit: " + request.resourceType);
this.setState({ request: request });
// Prepare the prefetch.
const prefetch = this.prepPrefetch();
Expand Down Expand Up @@ -113,14 +113,11 @@ export default class RequestBox extends Component {
};

getPatients = () => {
console.log(this.props.access_token.access_token);
this.setState({ openPatient: true });
const params = {serverUrl: this.props.ehrUrl};
console.log(this.props.access_token.access_token);
const params = {serverUrl: env.get('REACT_APP_EHR_SERVER').asString()};
if (this.props.access_token.access_token) {
params["tokenResponse"] = {access_token: this.props.access_token.access_token}
}
console.log(params);
const client = FHIR.client(
params
);
Expand Down Expand Up @@ -277,6 +274,32 @@ export default class RequestBox extends Component {
);
}

launchSmartOnFhirApp = () => {
console.log("Launch SMART on FHIR App");

let userId = this.state.prefetchedResources?.practitioner?.id;
if (!userId) {
console.log("Practitioner not populated from prefetch, using default from config: " + this.props.defaultUser);
userId = this.props.defaultUser;
}

let link = {
appContext: "user=" + userId + "&patient=" + this.state.patient.id,
type: "smart",
url: this.props.smartAppUrl
}

retrieveLaunchContext(
link, this.props.fhirAccessToken,
this.state.patient.id, this.props.fhirServerUrl, this.props.fhirVersion
).then((result) => {
link = result;
console.log(link);
// launch the application in a new window
window.open(link.url, '_blank');
});
}

/**
* Relaunch DTR using the available context
*/
Expand Down Expand Up @@ -379,6 +402,10 @@ export default class RequestBox extends Component {
return Object.keys(this.state.request).length === 0;
}

isPatientNotSelected() {
return Object.keys(this.state.patient).length === 0;
}

updateDeidentifyCheckbox(elementName, value) {
this.setState({ deidentifyRecords: value });
}
Expand All @@ -392,6 +419,7 @@ export default class RequestBox extends Component {
const disableSendToCRD = this.isOrderNotSelected() || this.props.loading ;
const disableLaunchDTR = this.isOrderNotSelected() && Object.keys(this.state.response).length === 0;
const disableSendRx = this.isOrderNotSelected() || this.props.loading;
const disableLaunchSmartOnFhir = this.isPatientNotSelected();
return (
<div>
<div className="request">
Expand Down Expand Up @@ -451,6 +479,9 @@ export default class RequestBox extends Component {
<div id="fse" className={"spinner " + (this.props.loading ? "visible" : "invisible")}>
<div className="ui active right inline loader"></div>
</div>
<button className={"submit-btn btn btn-class "} onClick={this.launchSmartOnFhirApp} disabled={disableLaunchSmartOnFhir}>
Launch SMART on FHIR App
</button>
<button className={"submit-btn btn btn-class "} onClick={this.sendRx} disabled={disableSendRx}>
Send Rx to PIMS
</button>
Expand Down
4 changes: 3 additions & 1 deletion src/components/SMARTBox/EHRLaunchBox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, {Component} from 'react';
import {fhir} from '../../util/fhir';
import './smart.css';
import env from 'env-var';

export default class EHRLaunchBox extends Component {
constructor(props){
super(props);
Expand All @@ -17,7 +19,7 @@ export default class EHRLaunchBox extends Component {
<div>
<label className="ehr-setting">Select EHR: </label>
<select>
<option value="http://localhost:8080/ehr-server/">Local</option>
<option value={env.get('REACT_APP_EHR_LINK').asString()}>Local</option>
</select>
<div className="ehr-setting">
Note: Only the local EHR is supported at this time for EHR launch
Expand Down
1 change: 0 additions & 1 deletion src/components/SMARTBox/PatientBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export default class SMARTBox extends Component {
} else {
let request = JSON.parse(data.value);
let coding = this.getCoding(request);
//console.log(request.resourceType + " for code " + coding.code + " selected");
this.setState({
request: data.value,
code: coding.code,
Expand Down
5 changes: 3 additions & 2 deletions src/containers/PatientPortal.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { memo, useState, useEffect } from 'react';
import useStyles from './styles/styles';
import FHIR from "fhirclient";
import config from '../properties.json';
import Login from '../components/Auth/Login';
import Dashboard from '../components/Dashboard/Dashboard';
import AccountBoxIcon from '@mui/icons-material/AccountBox';
import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import env from 'env-var';

const PatientPortal = () => {
const classes = useStyles();
const [token, setToken] = useState(null);
Expand All @@ -18,7 +19,7 @@ const PatientPortal = () => {
if(token) {
const data = JSON.parse(Buffer.from(token.split('.')[1], 'base64'))
const client = FHIR.client({
serverUrl: config.ehr_base,
serverUrl: env.get('REACT_APP_EHR_BASE').asString(),
tokenResponse: {
type: 'bearer',
access_token: token,
Expand Down
Loading

0 comments on commit befce55

Please sign in to comment.