Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions connector.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import fetch from 'node-fetch'

// Tomcat hosted fhir server
const serverUrl = 'http://localhost:8080/server'
// Define your fhir-hapi server url
const serverUrl = 'http://hapi.fhir.org/baseDstu3/'

// Allow reducers to call for a resource type, and pass url search parameters
const Fhir = {
getAll({ resource, searchParams }) {
return fetch(serverUrl + '/fhir/' + resource + '?' + searchParams)
.then(res => res.json())
const url = serverUrl + resource + (searchParams ? '?' + searchParams : '')
return fetch(url)
.then(res => res.json()).then(json => {
console.log('Response from ' + url + '\n' + JSON.stringify(json, null, 2).substring(0, 100) + '\n' + '... ')
return json
})
},
getOne({ resource, id, searchParams }) {
return fetch(serverUrl + '/fhir/'+ resource + '/' + id + '?' + searchParams)
.then(res => res.json())
const url = serverUrl + resource + '/' + id + (searchParams ? '?' + searchParams : '')
return fetch(url)
.then(res => res.json()).then(json => {
console.log('Response from ' + url + '\n' + JSON.stringify(json, null, 2).substring(0, 100) + '\n' + '... ')
return json
})
}
}

Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"casual": "^1.5.19",
"express": "^4.16.3",
"graphql": "^0.13.2",
"graphql-tools": "^3.0.4"
"graphql-tools": "^3.0.4",
"node-fetch": "^2.1.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
Expand Down
15 changes: 11 additions & 4 deletions resolvers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { findByLinkId } from "./resolverHelpers";
import { Fhir } from "./connector";

const questionnaireResponse = {
resourceType: "QuestionnaireResponse",
Expand Down Expand Up @@ -54,11 +55,17 @@ const questionnaireResponse = {
const resolvers = {
Query: {
questionnaireResponses() {
return [questionnaireResponse];
return Fhir.getAll({ resource: 'QuestionnaireResponse' }).then(res => {
// Extract resource out of the bundle.
const result = res.entry.map(entry => entry.resource)
return result;
})
},
// args: linkId
// Using the linkId, find the corresponding questionnaireResponseItem
// From the questionnaireResponseItem, return the answers array.
/**
* @linkId {string} unique identifier for each item.
* Using the linkId, find the corresponding questionnaireResponseItem
* From the questionnaireResponseItem, return the answers array.
*/
questionnaireAnswer(root, args) {
const questionnaireResponseItem = findByLinkId(
questionnaireResponse, // getting the questionnaire Response will become async when we hook up FHIR HAPI
Expand Down
10 changes: 10 additions & 0 deletions schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,23 @@ const typeDefs = `
address: [Address]
}

type Attachment {
contentType: String
data: String
}

type QuestionnaireResponseAnswer {
valueDate: String
valueDateTime: String
valueTime: String
valueUri: String
valueCoding: Code
valueDecimal: Float
valueBoolean: Boolean
valueInteger: Int
valueReference: Reference
valueString: String
valueAttachment: Attachment
}

type QuestionnaireResponseItem {
Expand Down