FHIR Chat · Syntax check · javascript

Stream: javascript

Topic: Syntax check


view this post on Zulip Grahame Grieve (Dec 29 2017 at 19:28):

I'm just working on setting up javascript hosting in my server.

view this post on Zulip Grahame Grieve (Dec 29 2017 at 19:28):

can I just check expectations.... if you're working with a patient,

view this post on Zulip Grahame Grieve (Dec 29 2017 at 19:29):

where p is a Patient

view this post on Zulip Grahame Grieve (Dec 29 2017 at 19:29):

p.identifier[0].system

view this post on Zulip Grahame Grieve (Dec 29 2017 at 19:29):

that would access the system value on the first identifier, yes?

view this post on Zulip Grahame Grieve (Dec 29 2017 at 19:29):

what would be expected to add an identifier?

view this post on Zulip Grahame Grieve (Dec 29 2017 at 19:31):

p.identifier = p.identifier.concat([new Identifier() {system='http://something'}])

view this post on Zulip Grahame Grieve (Dec 29 2017 at 19:31):

is that right?

view this post on Zulip Stefan Lang (Dec 29 2017 at 21:09):

p.identifier[0].system is indeed the first identifier's system.

As for adding an identifier, there are a bunch of ways one could do this.
Your example probably won't work (JS gurus may correct me ...)
You would either just add an anonymous JS object to the p.identifier array:

p.identifier = p.identifier.concat([{system: 'http://something'}]);

or you might have a JS class called Identifier with some constructor (and fully blown probably with setters and getters):

class Identifier {
  constructor(system) {
    this.system = system; // in real life should also check whether system is not null ...
  }
}
p.identifier = p.identifier.concat([new Identifier('http://something')]);

view this post on Zulip Stefan Lang (Dec 29 2017 at 21:12):

to add a single object to an array, you might also use push() instead of concat(), saving a pair of brackets and the assignment:

p.identifier.push(SOME_IDENTIFIER_OBJECT);

view this post on Zulip Grahame Grieve (Dec 29 2017 at 21:58):

thanks. Doesn't / shouldn't the JS reference library define Identifier() so that it can be used?

view this post on Zulip Stefan Lang (Dec 30 2017 at 13:44):

Well, if you are talking about https://github.com/FHIR/fhir.js - this is basically a client wrapper for the RESTful API.
fhir.js doesn't know about resources and data types.
The same is true for SMART's client-js, which internally uses fhir.js.
You can use one of the JSON schema implementations to validate JS objects against FHIR resource definitions, or the fhir-validator-js available on Github.
Afaik, that's all there is, in terms of more or less official libraries.
Whether there should be more ... maybe @nicola (RIO/SS) can elaborate on that ;-)


Last updated: Apr 12 2022 at 19:14 UTC