Skip to content

Commit

Permalink
feat: improve how we connect to the client
Browse files Browse the repository at this point in the history
  • Loading branch information
zeevo committed Jun 4, 2020
1 parent ef2567e commit a9d5306
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/containers/App/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
addSmartInformationErrorAction,
} from './actions';

import FhirClient from '../../services/FhirClient';
import connect from '../../services/FhirClient';

import config from '../../config';

Expand All @@ -20,7 +20,7 @@ export function* loadConfig() {

export function* loadSmartInfo() {
try {
const client = yield call(FhirClient.connect);
const client = yield call(connect);
yield put(addSmartInformationAction(client));
} catch (e) {
yield put(addSmartInformationErrorAction(e));
Expand Down
5 changes: 3 additions & 2 deletions src/containers/Home/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
*/

import { all, put, call, takeEvery } from 'redux-saga/effects';
import FhirClient from '../../services/FhirClient';
import connect from '../../services/FhirClient';

import { LOAD_PATIENT_INFO } from './constants';
import { loadPatientInfoActionError, loadPatientInfoActionSuccess } from './actions';

function* loadPatientInfo() {
try {
const patient = yield call(FhirClient.getPatient);
const client = yield call(connect);
const patient = yield call(client.patient.read);
yield put(loadPatientInfoActionSuccess(patient));
} catch (e) {
yield put(loadPatientInfoActionError(e));
Expand Down
13 changes: 2 additions & 11 deletions src/services/FhirClient.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import FHIR from 'fhirclient';

let loaded = false;

let client = {};
let client;

const connect = async () => {
if (loaded) {
Expand All @@ -15,12 +14,4 @@ const connect = async () => {
});
};

export default {
client,
connect,
getPatient: () => {
return connect().then(smart => {
return smart.patient.read();
});
},
};
export default connect;

0 comments on commit a9d5306

Please sign in to comment.