0

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
    });
  };
  • The error message is clear: `header` is not a function, it's an object. I guess you should be using `headers["Content-Location"]` instead - but this will return `undefined`. – Andreas Jul 08 '15 at 15:53

1 Answers1

0

Do you have write permissions on the directory? If you can read and search but not create or update, you may not be able to write to the directory.

Rocky Raccoon
  • 243
  • 3
  • 14