Skip to content

Commit

Permalink
Fix resolve and read API
Browse files Browse the repository at this point in the history
  • Loading branch information
jmandel committed Nov 7, 2014
1 parent 5a41aff commit 27f1c4a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
15 changes: 14 additions & 1 deletion integration_test/jquerySpec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,17 @@ describe "jquery", ->
.fail (err)->
throw new Error("Couldn't create")


it "can resolve refs", (done) ->
subject.search
type: 'MedicationPrescription'
query:
$include:
MedicationPrescription: 'medication'
.then (rxs)->
rx = rxs.entry[0].content
med = subject.resolveSync
reference: rx.medication
resource: rx
bundle: rx
expect(med.content).toBeTruthy()
done()
5 changes: 4 additions & 1 deletion src/adapters/jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ module.exports = (config)->
"update"
"delete"
"vread"
].reduce ((acc, v)-> acc[v] = defer(v); acc), {}
"resolve"
].reduce ((acc, v)-> acc[v] = defer(v); acc), {
"resolveSync": fhir["resolveSync"]
}
4 changes: 2 additions & 2 deletions src/fhir.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ fhir = (cfg, adapter) ->
crud["delete"] deps(opt)

resolve: (opt) ->
resolve.async(opt) depsWithCache(opt)
resolve.async depsWithCache(opt)

resolveSync: (opt) ->
resolve.sync(opt) depsWithCache(opt)
resolve.sync depsWithCache(opt)

module.exports = fhir
2 changes: 1 addition & 1 deletion src/resource.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exports.read = ({baseUrl, http, id, success, error})->
console.log("[read] ", id)
http
method: 'GET'
url: id
url: utils.absoluteUrl(baseUrl, id)
success: (data, status, headers, config)->
id = headers and headers('Content-Location') or '??'
tags = headers and headerToTags(headers('Category')) or '??'
Expand Down
14 changes: 8 additions & 6 deletions test/resourceSpec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,30 @@ describe "search:", ->
expect(q.url).toBe('BASE/Patient')
expect(q.data).toBe(JSON.stringify(entry.content))
expect(q.headers['Category']).toBe('term; scheme="sch"; label="lbl"')

done()

it "read", (done)->
simpleRead = (id, done) ->
entry = {content: {resourceType: 'Patient'}, category: tags}
http = (x)-> x.success(entry.content, 200, headers, x)

res.read
baseUrl: 'BASE'
http: http
id: 'BASE/Patient/5'
id: id
success: (res, q)->
expect(res).not.toBe(null)
expect(res.id).toBe('BASE/Patient/5')
expect(res.category).toEqual(tags)

expect(q.method).toBe('GET')
expect(q.url).toBe('BASE/Patient/5')

done()

it "read", (done)->
simpleRead('BASE/Patient/5', done)

it "read relative", (done)->
simpleRead('Patient/5', done)

it "update", (done)->
entry = {id: 'BASE/Patient/5', content: {resourceType: 'Patient'}, category: tags}
http = (x)-> x.success(entry.content, 200, headers, x)
Expand All @@ -68,7 +71,6 @@ describe "search:", ->
expect(res).not.toBe(null)
expect(res.id).toBe('BASE/Patient/5')
expect(res.category).toEqual(tags)

expect(q.method).toBe('PUT')
expect(q.url).toBe('BASE/Patient/5')

Expand Down

0 comments on commit 27f1c4a

Please sign in to comment.