我们最近讨论过将 Node.js 语言与 强大的 M 数据库 集成的重要性,尤其是在医疗保健应用领域。
Node.js 的效率与 M 的高性能相结合,为构建医疗保健应用提供了无与伦比的全新方法。
以下是如何立即尝试的方法
- 安装 GT.M (M 的开源实现)
- 安装 Node.js
- 安装 nodem 模块,该模块为 M 提供 Node.js 驱动程序
- 安装 ewdglobals 模块,该模块提供 Node.js 集成
有了这些,您现在可以尝试以下 示例。 让我们从一个简单的例子开始:
var ewd = require('ewdglobals');
var nodem = require('nodem');
var db = new nodem.Gtm();
ewd.init(db);
db.open();
var patient = new ewd.GlobalNode('patient',[123456]);
var document = {
"name": "John Doe",
"city": "New York"
};
patient._setDocument(document);
db.close();
如果我们将其放在名为 exampleA.js 的文件中并使用以下命令运行它
nodejs exampleA.js
然后,我们可以使用 ZWRITE 命令检查 M 数据库中条目的状态
GTM>zwrite ^patient
以发现它现在设置为
^patient(123456,"city")="New York"
^patient(123456,"name")="John Doe"
这反映了 映射,在 M 多维树状分层结构 数组与 Node.js 对象的嵌套属性结构之间。
我们还可以使用 Node.js 从 M 数据库 获取整个条目到 JSON 结构中,然后使用以下两行将其打印到控制台
var record = patient._getDocument();
console.log("patient info: " + JSON.stringify(record));
通过使用受 jQuery 启发的表示法,我们现在可以访问 M 条目的分层结构中更深层的元素
var nameValue = patient.$('name')._value;
var cityValue = patient.$('city')._value;
console.log("Name: " + nameValue + " City: " + cityValue);
更完整的示例说明了数据层次结构的多个级别的使用。
var ewd = require('ewdglobals');
var nodem = require('nodem');
var db = new nodem.Gtm();
ewd.init(db);
console.log("Setting a Global");
db.open();
var patient = new ewd.GlobalNode('patient',[123456]);
var document = {
"name": "John Doe",
"city": "New York",
"treatments" : {
"surgeries" : [ "apendicectomy", "biopsy" ],
"radiation" : [ "gamma", "x-rays" ],
"physiotherapy" : [ "knee", "shoulder" ]
},
};
patient._setDocument(document);
console.log("Querying properties");
// By quering for a subscript, all its attributes
// become available as properties.
//
var treatementsObject = patient.$('treatments');
console.log("Surgeries:");
patient.treatments.surgeries._forEach( function( id ) {
console.log( patient.treatments.surgeries[id]._value );
});
// Accessing radiation treatements
console.log("Radiation:");
console.log( patient.treatments.radiation[0]._value );
console.log( patient.treatments.radiation[1]._value );
db.close();
请特别注意使用 forEach() 构造来访问结构中数组的所有元素。以及使用点表示法逐步访问映射到 M 子索引的每个属性。
这类似于基于 JSON 结构的 MongoDB 存储,但不同之处在于我们可以访问数据结构的内部元素。
Node.js 与 M 的这种现代集成为 Javascript 开发人员提供了一个 独特的机会,让他们进入医疗保健 IT 应用领域,并为其带来快速创新。
Node.js 开发人员:医疗保健需要您的帮助!
评论已关闭。