var subscription = {
criteria: "/Patient?identifier=http://acme.org/patient/123",
status: 'active',
channel: {
type: 'websocket',
endpoint: Meteor.absoluteUrl()
}
}
Meteor.subscribe("todaysOrders", subscription);
Meteor.publish("todaysOrders", function (subscription){
if(subscription.status === 'active'){
if (this.userId) {
var criteriaObject = parseCriteriaString(subscription.criteria);
return Mongo.Collections[criteriaObject.collection].find(criteriaObject.query);
} else {
return [];
}
} else {
return [];
}
});
parseCriteriaString = function(criteria){
var result = {
collection: '',
query: {}
};
// is this a serialized complex object?
if (criteria && criteria.includes('?')){
// the base before the ? gets assigned to the collection
var criteriaArray = criteria.split('?');
result.query.collection = criteriaArray[0].replace('/', '').trim();
// then we want to look at how many parameters were given
var paramsArray = [];
if(criteriaArray && criteriaArray[1]){
paramsArray = criteriaArray[1].split('&');
paramsArray.forEach(function(param){
// for each parameter, figure out the field name and the value
var fieldArray = param.split('=');
// some data types require subfields
if (fieldArray[0] === "identifier"){
result.query['identifier.value'] = fieldArray[1];
}
// continue with the rest of the search specification
// https://www.hl7.org/fhir/search.html
});
}
}
console.log('parseCriteriaString', result);
// deserialize string into mongo query
return result;
}