Stream: javascript
Topic: schema
nicola (RIO/SS) (Nov 23 2015 at 12:41):
Just init stream for discussion of FHIR -> JSON schema. @Dunmail @Josh Mandel
nicola (RIO/SS) (Nov 23 2015 at 12:42):
@Dunmail we need to separate node code from pure convertion and validation code.
Alse let's decide on language (es6?) and project location
nicola (RIO/SS) (Nov 23 2015 at 14:04):
I hate vanilla js syntax, @Dunmail are you ok about es6?
Ewout Kramer (Nov 23 2015 at 14:05):
ES6 = TypeScript?
Josh Mandel (Nov 23 2015 at 14:05):
Without the types...
nicola (RIO/SS) (Nov 23 2015 at 14:05):
almost :) just a subset of TypeScript :)
Josh Mandel (Nov 23 2015 at 14:06):
https://babeljs.io/docs/learn-es2015/ is a good overview
nicola (RIO/SS) (Nov 23 2015 at 14:06):
I found how to make babel faster - just add exclude: node_modules to babelrc :)
Josh Mandel (Nov 23 2015 at 14:07):
Ah, that sounds better!
Ewout Kramer (Nov 23 2015 at 14:09):
Without the types...
Ha. The crucial part.
Ewout Kramer (Nov 23 2015 at 14:10):
Ok. Read it. Understand the differences.
nicola (RIO/SS) (Nov 23 2015 at 14:10):
@Ewout Kramer time to learn some dynamic lang :)
Dunmail (Nov 23 2015 at 14:11):
Conformance -> swagger.json -> auto-generated clients
Ewout Kramer (Nov 23 2015 at 14:13):
I am not spending my days chasing down a bug that a compiler could have found. Like assigning strings to integers or calling functions with missing params. I have done that for ages in older languages pre-javascript. No thanks ;-) TypeScript is dynamic enough for me.
nicola (RIO/SS) (Nov 23 2015 at 14:13):
You have to be a user of Haskell :)
nicola (RIO/SS) (Nov 23 2015 at 14:14):
Here is purescript for real typed guys - http://www.purescript.org/
nicola (RIO/SS) (Nov 23 2015 at 16:56):
still hate js and es6 syntax, so much boilerplate in comparison with coffeescript
Ewout Kramer (Nov 23 2015 at 20:23):
Y. Coffescript is nice!
nicola (RIO/SS) (Nov 25 2015 at 16:06):
@Dunmail i've mostly repeated your work and passed simple test - all examples thro all schemas. https://github.com/niquola/fhir-schema
I hope, i'm ready to merge projects and discuss details :) Here is demo - http://niquola.github.io/fhir-schema/#/
Dunmail (Nov 26 2015 at 17:38):
@nicola Like it! What else do we need to do?
Dunmail (Nov 26 2015 at 17:40):
Constraints may be easier if/when structuredefs have fhirpath
Dunmail (Nov 26 2015 at 17:41):
Binding to required valuesets can be done
nicola (RIO/SS) (Nov 26 2015 at 17:42):
I'm fighting with https://github.com/epoberezkin/ajv. It should be faster then tv4 and more strict.
We have to layout library and separate pure JS build, node build, borwser build
nicola (RIO/SS) (Nov 26 2015 at 17:42):
So we have a core which is just a function StructureDefinition -> JSON Schema
nicola (RIO/SS) (Nov 26 2015 at 17:43):
Then we could have a nodejs wrapper, which could build from fs for example
nicola (RIO/SS) (Nov 26 2015 at 17:43):
browser wrapper with cache and async or prebuild schema
nicola (RIO/SS) (Nov 26 2015 at 17:44):
Let's decide about where on github we'll put it?
nicola (RIO/SS) (Nov 26 2015 at 17:44):
may be create organization fhir.js?
Dunmail (Nov 26 2015 at 17:45):
Sounds good. I think core will need a $validate function as we'll need to use .addFormat
Dunmail (Nov 26 2015 at 17:46):
fhir.js org is good!
Dunmail (Nov 27 2015 at 09:27):
What do you think of this lib layout?
fhir.js/json-schema-core
Core package for generating json-schema from FHIR structure definitions and
validating FHIR resources against json-schema definitions.
*Constructor*
var instance = new json-schema([schema])
- Returns json-schema instance.
- Instance has a schema property to hold the schema it uses.
- By default, we add the primitives/elements to the schema (maybe fhir core?).
- If prebuilt schema is provided, override existing definitions with new definitions.
*Get schema*
instance.schema = function() { return json-schema.schema object }
Add new definitions to schema
instance.add(structureDefinition, callback){ if structureDefinition is not an array, coerce to array for each structureDefinition, build schema and add/update in schema.definitions then callback }
Validate resource against a profile
instance.validate(resource, [url], [options], callback){ if no url assume core resource profiles : https://www.hl7.org/fhir/{{resource.resourceType.toLowerCase}}.profile.json if no schema.definitions[url] throw Error ? could we validate against profiles that resource claims to support (via resource meta) ? options to modify validation behaviour var result = validator.validate(resource, schema.definitions[url]) callback(result as OperationOutcome) }
fhir.js/json-schema-node
Package wrapping fhir.js/json-schema-core to provide additional node specific capabilities:
- add profiles from fs location?
- connect middleware function?
- promisify functions?
fhir.js/json-schema-bower
(Not necessarily bower!)
Package wrapping fhir.js/json-schema-core to provide additional browser-specific capabilities
- aysnc support?
- add profiles from localstorage?
nicola (RIO/SS) (Nov 27 2015 at 09:57):
May be start from one repo with many builds?
nicola (RIO/SS) (Nov 27 2015 at 10:06):
@Dunmail Put you ideas to fhir.js/fhir-schema - at least this would be umbrella project for all packages.
Dunmail (Nov 27 2015 at 11:16):
Yes - can always refactor to other projects if we need to
nicola (RIO/SS) (Nov 27 2015 at 11:43):
Let's just list modules:
- schema-generation
- schema-usage
- schema-adapters
- different JSON schema enginies
- browser
- node
- schema-build (include schema for current FHIR specs)
Dunmail (Nov 27 2015 at 11:45):
What does schema-adapter do?
nicola (RIO/SS) (Nov 27 2015 at 11:46):
there are a lot of JSON schema engines - so adapters would just glue library to concrete ones
Dunmail (Nov 27 2015 at 11:47):
Got it
nicola (RIO/SS) (Nov 27 2015 at 11:47):
I've played with ajv, it's one order faster then tv4 for example. But top level api of this libraries very different
Dunmail (Nov 27 2015 at 11:48):
OK
nicola (RIO/SS) (Nov 27 2015 at 11:48):
so for example usage could looks like:
fhir = require('fhir-schema/tv4') or fhir = require('fhir-schema/ajv')
nicola (RIO/SS) (Nov 27 2015 at 11:49):
I could organize my code as initial repo and push to github. Is it ok?
nicola (RIO/SS) (Nov 27 2015 at 11:49):
Or we could start from your repo....
Dunmail (Nov 27 2015 at 11:50):
Better than OK :)
Have sent a couple of PRs, porting from the proof of concept lib I did
nicola (RIO/SS) (Nov 27 2015 at 16:32):
Here is it - https://github.com/fhir-js/fhir-schema
nicola (RIO/SS) (Dec 04 2015 at 09:39):
To discussion about selecting schema based on resourceType: swagger supports - "discriminator". Adds support for polymorphism. The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. The property name used MUST be defined at this schema and it MUST be in the required property list. When used, the value MUST be the name of this schema or any schema that inherits it.
Last updated: Apr 12 2022 at 19:14 UTC