diff --git a/connector.js b/connector.js index 59d8115..467d1f7 100644 --- a/connector.js +++ b/connector.js @@ -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 + }) } } diff --git a/package-lock.json b/package-lock.json index 6b7b624..0e9694b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5996,6 +5996,11 @@ "resolved": "http://127.0.0.1:5678/tarballs/negotiator/0.6.1.tgz", "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" }, + "node-fetch": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz", + "integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=" + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", diff --git a/package.json b/package.json index a282fe8..f0d5571 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/resolvers.js b/resolvers.js index 0d67ea8..c7e6465 100644 --- a/resolvers.js +++ b/resolvers.js @@ -1,4 +1,5 @@ import { findByLinkId } from "./resolverHelpers"; +import { Fhir } from "./connector"; const questionnaireResponse = { resourceType: "QuestionnaireResponse", @@ -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 diff --git a/schema.js b/schema.js index 3093783..9dc043e 100644 --- a/schema.js +++ b/schema.js @@ -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 {