Skip to content

Commit

Permalink
Prefer getId() as data source API for getting string-based ids
Browse files Browse the repository at this point in the history
The CQL execution engine requires that data models expose an id over the
API and it expects that this id is a string.  Currently this is only
used when building out the results object (in which the patient id is
used as a key) -- but it is important.

Problems arise when a data model defines an id property that is not a
string.  This is the case for the FHIR data models (in which id is an
object, in order to support extensions).  Then the required string-based
id conflicts with the data-model defined object id.

To get around this, we change the API to expect a getId() function that
should return the ID as a string.  To support backwards compatibility
(i.e., not break Bonnie and other apps), if the getId() function isn't
found, we fall back to id().
  • Loading branch information
cmoesel committed May 3, 2018
1 parent 5116e75 commit 1ca7045
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/example/browser/cql4browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43831,8 +43831,9 @@
}

Results.prototype.recordPatientResult = function(patient_ctx, resultName, result) {
var base, patientId;
patientId = patient_ctx.patient.id();
var base, p, patientId;
p = patient_ctx.patient;
patientId = typeof p.getId === 'function' ? p.getId() : p.id();
if ((base = this.patientResults)[patientId] == null) {
base[patientId] = {};
}
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/results.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ module.exports.Results = class Results
@localIdPatientResultsMap = {}

recordPatientResult: (patient_ctx, resultName, result) ->
patientId = patient_ctx.patient.id()
p = patient_ctx.patient
# NOTE: From now on prefer getId() over id() because some data models may have an id property
# that is not a string (e.g., FHIR) -- so reserve getId() for the API (and expect a string
# representation) but leave id() for data-model specific formats.
patientId = if typeof p.getId == 'function' then p.getId() else p.id()
@patientResults[patientId] ?= {}
@patientResults[patientId][resultName] = result
@localIdPatientResultsMap[patientId] = patient_ctx.getAllLocalIds()
Expand Down

0 comments on commit 1ca7045

Please sign in to comment.