Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #39 from standardhealth/cimpl6-import
Browse files Browse the repository at this point in the history
CIMPL6 Import
  • Loading branch information
cmoesel authored Jun 5, 2019
2 parents f1e3350 + 228a8ce commit 59be131
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 187 deletions.
29 changes: 6 additions & 23 deletions lib/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class DataElementSpecifications {
if (id.isEntryKeyWord) {
[namespace, name] = ['shr.base', 'Entry'];
} else if (id.isConceptKeyWord) {
[namespace, name] = ['shr.core', 'CodeableConcept'];
[namespace, name] = ['primitive', 'concept'];
}
}
if (this._nsMap.has(namespace)) {
Expand Down Expand Up @@ -1012,7 +1012,7 @@ class Constraint {
}
}

// ValueSetConstraint only makes sense on a code or Coding type value
// ValueSetConstraint only makes sense on a concept type value
class ValueSetConstraint extends Constraint {

constructor(valueSet, path, bindingStrength=REQUIRED) {
Expand Down Expand Up @@ -1061,7 +1061,7 @@ class ValueSetConstraint extends Constraint {
}
}

// CodeConstraint only makes sense on a code or Coding type value
// CodeConstraint only makes sense on a concept type value
class CodeConstraint extends Constraint {

constructor(code, path) {
Expand Down Expand Up @@ -1099,7 +1099,7 @@ class CodeConstraint extends Constraint {
}
}

// IncludesCodeConstraint only makes sense on an array of code or Coding
// IncludesCodeConstraint only makes sense on an array of concept
class IncludesCodeConstraint extends Constraint {

constructor(code, path) {
Expand Down Expand Up @@ -1889,23 +1889,6 @@ class IdentifiableValue extends Value {
}
}

class RefValue extends IdentifiableValue {

constructor(identifier) {
super(identifier);
}

clone() {
const clone = new RefValue();
super._clonePropertiesTo(clone);
return clone;
}

toString() {
return `ref(${this.identifier.name})`;
}
}

class ChoiceValue extends Value {


Expand Down Expand Up @@ -2751,11 +2734,11 @@ const EXAMPLE = 'EXAMPLE';

// Primitive constants
const PRIMITIVE_NS = 'primitive';
const PRIMITIVES = ['boolean', 'integer', 'decimal', 'unsignedInt', 'positiveInt', 'string', 'markdown', 'code', 'id',
const PRIMITIVES = ['boolean', 'integer', 'decimal', 'unsignedInt', 'positiveInt', 'string', 'markdown', 'concept', 'id',
'oid', 'uri', 'base64Binary', 'date', 'dateTime', 'instant', 'time', 'xhtml'];

// Inheritance constants
const INHERITED = 'inherited';
const OVERRIDDEN = 'overridden';

module.exports = {Specifications, NamespaceSpecifications, DataElementSpecifications, ContentProfileSpecifications, Namespace, DataElement, ContentProfile, ContentProfileRule, Concept, Identifier, PrimitiveIdentifier, Value, IdentifiableValue, RefValue, ChoiceValue, IncompleteValue, TBD, ConstraintsFilter, ConstraintHistory, Cardinality, ValueSetConstraint, CodeConstraint, IncludesCodeConstraint, BooleanConstraint, TypeConstraint, IncludesTypeConstraint, CardConstraint, ValueSet, ValueSetIncludesCodeRule, ValueSetIncludesDescendentsRule, ValueSetExcludesDescendentsRule, ValueSetIncludesFromCodeSystemRule, ValueSetIncludesFromCodeRule, CodeSystem, ElementMapping, FieldMappingRule, CardinalityMappingRule, FixedValueMappingRule, Version, PRIMITIVE_NS, PRIMITIVES, VERSION, GRAMMAR_VERSION, REQUIRED, EXTENSIBLE, PREFERRED, EXAMPLE, INHERITED, OVERRIDDEN, MODELS_INFO, sanityCheckModules};
module.exports = {Specifications, NamespaceSpecifications, DataElementSpecifications, ContentProfileSpecifications, Namespace, DataElement, ContentProfile, ContentProfileRule, Concept, Identifier, PrimitiveIdentifier, Value, IdentifiableValue, ChoiceValue, IncompleteValue, TBD, ConstraintsFilter, ConstraintHistory, Cardinality, ValueSetConstraint, CodeConstraint, IncludesCodeConstraint, BooleanConstraint, TypeConstraint, IncludesTypeConstraint, CardConstraint, ValueSet, ValueSetIncludesCodeRule, ValueSetIncludesDescendentsRule, ValueSetExcludesDescendentsRule, ValueSetIncludesFromCodeSystemRule, ValueSetIncludesFromCodeRule, CodeSystem, ElementMapping, FieldMappingRule, CardinalityMappingRule, FixedValueMappingRule, Version, PRIMITIVE_NS, PRIMITIVES, VERSION, GRAMMAR_VERSION, REQUIRED, EXTENSIBLE, PREFERRED, EXAMPLE, INHERITED, OVERRIDDEN, MODELS_INFO, sanityCheckModules};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shr-models",
"version": "5.9.0",
"version": "6.0.0",
"description": "Models used to represent SHR namespaces, data elements, value sets, code systems, and mappings for import/export",
"author": "",
"license": "Apache-2.0",
Expand Down
47 changes: 18 additions & 29 deletions test/canon-json-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ describe('#CanonicalJSON.DataElements.core', () => {
expect(outputJson).to.deep.equal(fixtureJson);
});

it('should correctly generate a simple element with a reference', () => {
let de = new simpleDE('shr.test', 'SimpleReference', true, false)
.withValue(new mdl.RefValue(id('shr.test', 'Simple')).withMinMax(1, 1))
.withDescription('It is a reference to a simple element');

let outputJson = de.toJSON();
let fixtureJson = importDataElementFixture('SimpleReference');

expect(outputJson).to.deep.equal(fixtureJson);
});

it('should correctly generate an element with a multi-string value', () => {
let de = new simpleDE('shr.test', 'MultiString', true, false)
.withDescription('It is a multi-string entry')
Expand Down Expand Up @@ -102,7 +91,7 @@ describe('#CanonicalJSON.DataElements.core', () => {

it('should correctly generate an entry element with a coded value', () => {
let de = new simpleDE('shr.test', 'SimpleCoded', true, false)
.withValue(new mdl.IdentifiableValue(pid('code')).withMinMax(1, 1));
.withValue(new mdl.IdentifiableValue(pid('concept')).withMinMax(1, 1));

let outputJson = de.toJSON();
let fixtureJson = importDataElementFixture('SimpleCoded');
Expand Down Expand Up @@ -216,8 +205,8 @@ describe('#DataElements.constraints', () => {

let de = new mdl.DataElement(id('shr.test', 'CodeConstraintOnField'), true, false)
.withField(new mdl.IdentifiableValue(id('shr.test', 'Simple')).withMinMax(0, 1))
.withField(new mdl.IdentifiableValue(id('shr.test', 'Coding')).withMinMax(0, 1)
.withConstraint(new mdl.CodeConstraint(defaultCode, [pid('code')]))
.withField(new mdl.IdentifiableValue(id('shr.test', 'CodedThing')).withMinMax(0, 1)
.withConstraint(new mdl.CodeConstraint(defaultCode, [pid('concept')]))
);

let outputJson = de.toJSON();
Expand All @@ -233,7 +222,7 @@ describe('#DataElements.constraints', () => {
let de = new mdl.DataElement(id('shr.test', 'CodeConstraintOnFieldChild'), true, false)
.withField(new mdl.IdentifiableValue(id('shr.test', 'Simple')).withMinMax(0, 1))
.withField(new mdl.IdentifiableValue(id('shr.test', 'CodedFromValueSet')).withMinMax(0, 1)
.withConstraint(new mdl.CodeConstraint(defaultCode, [id('shr.test','Coding'), pid('code')]))
.withConstraint(new mdl.CodeConstraint(defaultCode, [pid('concept')]))
);

let outputJson = de.toJSON();
Expand All @@ -247,8 +236,8 @@ describe('#DataElements.constraints', () => {
let defaultCode = new mdl.Concept('http://foo.org', 'bar');

let de = new mdl.DataElement(id('shr.test', 'CodeConstraintOnValue'), true, false)
.withValue(new mdl.IdentifiableValue(id('shr.test', 'Coding')).withMinMax(1, 1)
.withConstraint(new mdl.CodeConstraint(defaultCode, [pid('code')]))
.withValue(new mdl.IdentifiableValue(id('shr.test', 'CodedThing')).withMinMax(1, 1)
.withConstraint(new mdl.CodeConstraint(defaultCode, [pid('concept')]))
);

let outputJson = de.toJSON();
Expand All @@ -263,7 +252,7 @@ describe('#DataElements.constraints', () => {

let de = new mdl.DataElement(id('shr.test', 'CodeConstraintOnValueChild'), true, false)
.withValue(new mdl.IdentifiableValue(id('shr.test', 'CodedFromValueSet')).withMinMax(1, 1)
.withConstraint(new mdl.CodeConstraint(defaultCode, [id('shr.test','Coding'), pid('code')]))
.withConstraint(new mdl.CodeConstraint(defaultCode, [pid('concept')]))
);

let outputJson = de.toJSON();
Expand All @@ -277,8 +266,8 @@ describe('#DataElements.constraints', () => {
let defaultCode = new mdl.Concept(null, 'bar');

let de = new mdl.DataElement(id('shr.test', 'SystemlessCodeConstraintOnValue'), true, false)
.withValue(new mdl.IdentifiableValue(id('shr.test', 'Coding')).withMinMax(1, 1)
.withConstraint(new mdl.CodeConstraint(defaultCode, [pid('code')]))
.withValue(new mdl.IdentifiableValue(id('shr.test', 'CodedThing')).withMinMax(1, 1)
.withConstraint(new mdl.CodeConstraint(defaultCode, [pid('concept')]))
);

let outputJson = de.toJSON();
Expand All @@ -294,8 +283,8 @@ describe('#DataElements.constraints', () => {
let defaultCode = new mdl.Concept('http://foo.org', 'bar');

let de = new mdl.DataElement(id('shr.test', 'IncludesCodeConstraintOnValue'), true, false)
.withValue(new mdl.IdentifiableValue(id('shr.test', 'Coding')).withMinMax(1)
.withConstraint(new mdl.IncludesCodeConstraint(defaultCode, [pid('code')]))
.withValue(new mdl.IdentifiableValue(id('shr.test', 'CodedThing')).withMinMax(1)
.withConstraint(new mdl.IncludesCodeConstraint(defaultCode, [pid('concept')]))
);

let outputJson = de.toJSON();
Expand All @@ -311,7 +300,7 @@ describe('#DataElements.constraints', () => {
let de = new mdl.DataElement(id('shr.test', 'IncludesCodeConstraintOnFieldChild'), true, false)
.withField(new mdl.IdentifiableValue(id('shr.test', 'Simple')).withMinMax(0, 1))
.withField(new mdl.IdentifiableValue(id('shr.test', 'MultiCodedFromValueSet')).withMinMax(0, 1)
.withConstraint(new mdl.IncludesCodeConstraint(defaultCode, [id('shr.test','Coding'), pid('code')]))
.withConstraint(new mdl.IncludesCodeConstraint(defaultCode, [pid('concept')]))
);

let outputJson = de.toJSON();
Expand All @@ -325,8 +314,8 @@ describe('#DataElements.constraints', () => {
let defaultCode = new mdl.Concept('http://foo.org', 'bar');

let de = new mdl.DataElement(id('shr.test', 'IncludesCodeConstraintOnValue'), true, false)
.withValue(new mdl.IdentifiableValue(id('shr.test', 'Coding')).withMinMax(1)
.withConstraint(new mdl.IncludesCodeConstraint(defaultCode, [pid('code')]))
.withValue(new mdl.IdentifiableValue(id('shr.test', 'CodedThing')).withMinMax(1)
.withConstraint(new mdl.IncludesCodeConstraint(defaultCode, [pid('concept')]))
);

let outputJson = de.toJSON();
Expand All @@ -341,7 +330,7 @@ describe('#DataElements.constraints', () => {

let de = new mdl.DataElement(id('shr.test', 'IncludesCodeConstraintOnValueChild'), true, false)
.withValue(new mdl.IdentifiableValue(id('shr.test', 'MultiCodedFromValueSet')).withMinMax(1, 1)
.withConstraint(new mdl.IncludesCodeConstraint(defaultCode, [id('shr.test', 'Coding'), pid('code')]))
.withConstraint(new mdl.IncludesCodeConstraint(defaultCode, [pid('concept')]))
);

let outputJson = de.toJSON();
Expand Down Expand Up @@ -480,8 +469,8 @@ describe('#DataElements.constraints', () => {
let TESTVS = 'http://standardhealthrecord.org/test/vs';

let codedFromVS = new simpleDE('shr.test', 'CodedWithCodeFromValueSet', false, false)
.withValue(new mdl.IdentifiableValue(id('shr.test', 'Coding')).withMinMax(1, 1)
.withConstraint(new mdl.ValueSetConstraint(`${TESTVS}/Coded`, [pid('code')])));
.withValue(new mdl.IdentifiableValue(id('shr.test', 'CodedThing')).withMinMax(1, 1)
.withConstraint(new mdl.ValueSetConstraint(`${TESTVS}/Coded`, [pid('concept')])));

let outputJson = codedFromVS.toJSON();
let fixtureJson = importDataElementFixtureFromPath(['constraints', 'valuesetConstraints'], 'CodedWithCodeFromValueSet');
Expand All @@ -493,7 +482,7 @@ describe('#DataElements.constraints', () => {
let TESTVS = 'http://standardhealthrecord.org/test/vs';

let de = new simpleDE('shr.test', 'CodedFromValueSet', true, false)
.withValue(new mdl.IdentifiableValue(pid('code')).withMinMax(1, 1)
.withValue(new mdl.IdentifiableValue(pid('concept')).withMinMax(1, 1)
.withConstraint(new mdl.ValueSetConstraint(`${TESTVS}/Coded`)));

let outputJson = de.toJSON();
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/dataelements/SimpleCoded.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"isEntry": true,
"isAbstract": false,
"value": {
"fqn": "code",
"fqn": "concept",
"valueType": "IdentifiableValue",
"card": {
"min": 1,
Expand Down
16 changes: 0 additions & 16 deletions test/fixtures/dataelements/SimpleReference.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
}
},
{
"fqn": "shr.test.Coding",
"fqn": "shr.test.CodedThing",
"valueType": "IdentifiableValue",
"card": {
"min": 0,
"max": 1
},
"constraints": {
"subpaths": {
"code": {
"concept": {
"fixedValue": {
"type": "code",
"value": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@
},
"constraints": {
"subpaths": {
"shr.test.Coding": {
"subpaths": {
"code": {
"fixedValue": {
"type": "code",
"value": {
"system": "http://foo.org",
"code": "bar"
}
}
"concept": {
"fixedValue": {
"type": "code",
"value": {
"system": "http://foo.org",
"code": "bar"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"isEntry": true,
"isAbstract": false,
"value": {
"fqn": "shr.test.Coding",
"fqn": "shr.test.CodedThing",
"valueType": "IdentifiableValue",
"card": {
"min": 1,
"max": 1
},
"constraints": {
"subpaths": {
"code": {
"concept": {
"fixedValue": {
"type": "code",
"value": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
},
"constraints": {
"subpaths": {
"shr.test.Coding": {
"subpaths": {
"code": {
"fixedValue": {
"type": "code",
"value": {
"system": "http://foo.org",
"code": "bar"
}
}
"concept": {
"fixedValue": {
"type": "code",
"value": {
"system": "http://foo.org",
"code": "bar"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"isEntry": true,
"isAbstract": false,
"value": {
"fqn": "shr.test.Coding",
"fqn": "shr.test.CodedThing",
"valueType": "IdentifiableValue",
"card": {
"min": 1,
"max": 1
},
"constraints": {
"subpaths": {
"code": {
"concept": {
"fixedValue": {
"type": "code",
"value": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
}
},
{
"fqn": "shr.test.Coding",
"fqn": "shr.test.CodedThing",
"valueType": "IdentifiableValue",
"card": {
"min": 1
},
"constraints": {
"subpaths": {
"code": {
"concept": {
"includesCode": [
{
"system": "http://foo.org",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@
},
"constraints": {
"subpaths": {
"shr.test.Coding": {
"subpaths": {
"code": {
"includesCode": [
{
"system": "http://foo.org",
"code": "bar"
}
]
"concept": {
"includesCode": [
{
"system": "http://foo.org",
"code": "bar"
}
}
]
}
}
}
Expand Down
Loading

0 comments on commit 59be131

Please sign in to comment.