I've been using a fhir.js library in nodejs. I have got the read and search working but not the create or update which consistently gives me an error. Has anyone else used this library?
I instantiate my client like this:
var client = new mkFhir({
baseUrl: 'http://fhirtest.uhn.ca/baseDstu1'
});
Develop a patient entry like so:
var entry =
{
category: [{term: 'TAG term', schema: 'TAG schema', label: 'TAG label'}],
content:
{
resourceType: "Patient",
name:
[
{
family: ["Bob"],
given: ["Smith"]
}
],
birthDate: '1990-06-20'
}
};
Call create from the library like this:
var test = client.create(entry, function(err, entry)
{
console.log(entry.id);
console.log(err);
});
In the library, the error I receive is in resource.js stating id = headers('Content-Location') -- type error, undefined is not a function.
Things I've tried:
So I changed it to id = headers && headers('Content-Location') as per the read method. This gave me a 'Content-Type' is not defined but required for UPDATE. So I added a Content-Type in headers. That gave me a can not parse JSON error. So I re-wrote the method and now retrieve a patient object, which is updated in my console but not in the server.
Here is the create method:
exports.create = function(baseUrl, http, entry, cb, err) {
var headers, resource, tagHeader, tags, type;
tags = entry.category || [];
resource = entry.content;
assert(resource, 'entry.content with resource body should be present');
type = 'Patient';
assert(type, 'entry.content.resourceType with resourceType should be present');
headers = {};
headers['Content-Type'] = "application/json";
tagHeader = tagsToHeader(tags);
if (tagHeader.length > 0) {
headers["Category"] = tagHeader;
}
return http({
method: 'POST',
url: "" + baseUrl + "/" + type,
data: toJson(resource),
headers: headers,
success: function(data, status, headers, config) {
var id;
id = headers('Content-Location');
tags = headerToTags(headers('Category')) || tags;
return cb({
id: id,
category: tags || [],
content: data || resource
}, config);
},
error: err
});
};