From 92fc0881ea6ffb87c179d6d904918604888dcb18 Mon Sep 17 00:00:00 2001 From: William Chou Date: Mon, 2 Jul 2018 23:25:34 -0400 Subject: [PATCH 1/2] Connect with uhn test server. --- connector.js | 10 ++++++---- package-lock.json | 5 +++++ package.json | 3 ++- resolvers.js | 7 ++++++- schema.js | 10 ++++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/connector.js b/connector.js index 59d8115..4848e87 100644 --- a/connector.js +++ b/connector.js @@ -1,16 +1,18 @@ 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) + const url = serverUrl + resource + (searchParams ? '?' + searchParams : '') + return fetch(url) .then(res => res.json()) }, getOne({ resource, id, searchParams }) { - return fetch(serverUrl + '/fhir/'+ resource + '/' + id + '?' + searchParams) + const url = serverUrl + resource + '/' + id + (searchParams ? '?' + searchParams : '') + return fetch(url) .then(res => res.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..dbe1ea9 100644 --- a/resolvers.js +++ b/resolvers.js @@ -1,4 +1,5 @@ import { findByLinkId } from "./resolverHelpers"; +import { Fhir } from "./connector"; const questionnaireResponse = { resourceType: "QuestionnaireResponse", @@ -54,7 +55,11 @@ 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 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 { From 137da6c9f0f67861fb144e916a6eb7d53b9611db Mon Sep 17 00:00:00 2001 From: Will C Date: Fri, 25 Jan 2019 09:10:30 -0500 Subject: [PATCH 2/2] Add jsdoc, add console logs. --- connector.js | 10 ++++++++-- resolvers.js | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/connector.js b/connector.js index 4848e87..467d1f7 100644 --- a/connector.js +++ b/connector.js @@ -8,12 +8,18 @@ const Fhir = { getAll({ resource, searchParams }) { const url = serverUrl + resource + (searchParams ? '?' + searchParams : '') return fetch(url) - .then(res => res.json()) + .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 }) { const url = serverUrl + resource + '/' + id + (searchParams ? '?' + searchParams : '') return fetch(url) - .then(res => res.json()) + .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/resolvers.js b/resolvers.js index dbe1ea9..c7e6465 100644 --- a/resolvers.js +++ b/resolvers.js @@ -61,9 +61,11 @@ const resolvers = { 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