Skip to content

Commit

Permalink
Merge pull request #1 from barabo/v2
Browse files Browse the repository at this point in the history
v2 changes
  • Loading branch information
barabo authored Nov 19, 2019
2 parents 53a2fbe + 49e4ffc commit b345d67
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 106 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,32 @@ Instructions

```sh
npm install
npm run launch &
npm run demo
```

Visit http://localhost:3001/ to log in (use any username and password)
To launch the app via SMART launch, [click here](http://launch.smarthealthit.org/?auth_error=&fhir_version_1=r4&fhir_version_2=r4&iss=&launch_ehr=1&launch_url=http%3A%2F%2Flocalhost%3A8899%2Flaunch.html&patient=&prov_skip_auth=1&provider=&pt_skip_auth=1&public_key=&sb=&sde=&sim_ehr=1&token_lifetime=15&user_pt=) and then click the green Launch App button.

<img src="./images/login.png" alt="alt text" width="256">
<img src="./images/v2launch.png" alt="alt text" width="256">

Select a patient age, gender, indication, and order to determine whether it
is within recommended guidelines.

<img src="./images/empty_form.png" alt="alt text" width="256">
Select a provider and a patient, then select an indication, and an order to
determine whether it is within recommended guidelines.

<img src="./images/v2provider.png" alt="alt text" width="256">
<img src="./images/v2patient.png" alt="alt text" width="256">
<img src="./images/v2indication.png" alt="alt text" width="256">
<img src="./images/v2procedure.png" alt="alt text" width="256">
<img src="./images/v2rating.png" alt="alt text" width="256">

V2 TODO
-------

- [x] Make it work with SMART Launch
- [x] Launch from http://launch.smarthealthit.org simulated EHR
- [x] Grab demographics from SMART context
- [x] populating (name and DOB) or at least "age and gender" fields from v1
- [x] Everything else the same (except old login form was disabled)

V1 TODO
-------
Expand Down
Binary file removed images/empty_form.png
Binary file not shown.
Binary file removed images/login.png
Binary file not shown.
Binary file added images/v2indication.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/v2launch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/v2patient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/v2procedure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/v2provider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/v2rating.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 38 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@

<body>
<div>
<form action="evaluate" method="POST">
<form action="http://localhost:3002/evaluate" method="POST">
<input type="hidden" id="provider" name="provider">
<table>
<caption>Enter Patient Demographics</caption>
<tr>
<th><label for="gender">Gender</label></th>
<td>
<select name="gender" required>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
<option id="male" value="male">Male</option>
<option id="female" value="female">Female</option>
<option id="other" value="other">Other</option>
</select>
</td>
</tr>
<tr>
<th><label for="age">Age</label></th>
<td><input name="age" required></td>
<td><input id="age" name="age" required></td>
</tr>
<tr>
<th><label for="indication">Indication</label></th>
Expand All @@ -41,7 +42,7 @@
<tr>
<th><label for="procedure">Procedure</label></th>
<td>
<input list="procedures" name="procedure">
<input list="procedures" name="procedure" required>
<datalist id="procedures">
<option value="75561">cardiac mri</option>
<option value="70450">ct scan - no contrast material</option>
Expand All @@ -55,6 +56,37 @@
<input type="submit">
</form>
</div>

<script src="node_modules/fhirclient/build/fhir-client.js"></script>
<script>
async function getContext(client) {
return {
patient: await client.patient.read(),
user: await client.user.read(),
};
}

function populateForm(context) {
const patient = context.patient;
const then = new Date(patient.birthDate),
now = new Date();
const msPerYear = 365.25 * 24 * 60 * 60 * 1000;
const age = (now.getTime() - then.getTime()) / msPerYear;

document.getElementById('provider').value = context.user.id;
document.getElementById('age').value = Math.round(age);
document.getElementById(patient.gender).setAttribute('selected', 1);
}

if (typeof FHIR !== 'undefined') {
FHIR.oauth2.ready()
.then(getContext)
.then(populateForm)
.catch(console.error);
}
</script>


</body>

</html>
46 changes: 6 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const path = require('path');
const port = process.env.PORT || '3001';
const login = `<a href="http://localhost:${port}/">login</a>`;
const port = process.env.PORT || '3002';

const CPT = {
_FHIR_CODING_SYSTEM: 'http://www.ama-assn.org/go/cpt',
Expand Down Expand Up @@ -63,52 +61,20 @@ const cptReasons = {
};

const app = express();
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: true
}));
app.use(bodyParser.urlencoded({extended : true}));
app.use(bodyParser.json());

app.get('/', function(request, response) {
if (request.session.loggedin) {
response.redirect('/consult');
} else {
response.sendFile(path.join(__dirname + '/login.html'));
}
response.redirect('/consult');
});

app.get('/consult', function(request, response) {
if (request.session.loggedin) {
response.sendFile(path.join(__dirname + '/index.html'));
} else {
response.send(`Please ${login} to view this page!`).end();
}
response.sendFile(path.join(__dirname + '/index.html'));
});

app.post('/evaluate', function(request, response) {
if (!request.session.loggedin) {
response.status(404).send(`You must ${login} to access this.`);
} else {
const reasons = cptReasons[request.body.procedure];
const rating = reasons.getRating(new Set([request.body.indication]));
response.status(200).send(rating);
}
response.end();
});

app.post('/auth', function(request, response) {
const username = request.body.username;
const password = request.body.password;
if (username && password) {
request.session.loggedin = true;
request.session.username = username;
response.redirect('/');
} else {
response.send('Please enter Username and Password!');
}
response.end();
const reasons = cptReasons[request.body.procedure];
const rating = reasons.getRating(new Set([request.body.indication]));
response.status(200).send(rating).end();
});

app.listen(port);
13 changes: 13 additions & 0 deletions launch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<script src="./node_modules/fhirclient/build/fhir-client.js"></script>
<script>
FHIR.oauth2.authorize({
client_id: "demo_auc_guideline_consultation_app",
scope: "patient/*.read openid profile"
});
</script>
</head>
<body>Loading...</body>
</html>
49 changes: 0 additions & 49 deletions login.html

This file was deleted.

Loading

0 comments on commit b345d67

Please sign in to comment.