首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mongodb for HL7-FHIR

Mongodb for HL7-FHIR
EN

Stack Overflow用户
提问于 2016-11-20 14:03:11
回答 3查看 2.2K关注 0票数 2

学习FHIR并尝试实现使用MongoDb作为数据库的均值堆栈,我想在我的问题上寻求您的帮助。

当我收到一个新资源文档的POST请求时,我会将它插入到MongoDB中。因为MongoDB会将_id (对象id)作为唯一id添加到资源。当我检索文档时,它将有一个额外的字段_id。我认为这将使资源不再合规,因为_id没有在资源中定义。

我可以知道如何处理这个问题吗?这个额外的_id会在冷杉资源中起作用吗?

致以最好的问候,自动运行

EN

回答 3

Stack Overflow用户

发布于 2017-02-03 17:14:07

因此,我也在使用MongoDB和mongoose在nodejs中实现FHIR。我刚刚在mongoose的模式定义中添加了一个名为id的字段,如下所示

代码语言:javascript
复制
import mongoose from 'mongoose';
import shortid from 'shortid';
class resource extends mongoose.Schema {
  constructor(schema) {
    super();
    this.add({
      // just added this to make MongoDB use shortid
      _id: { type: String, default: shortid.generate },
      id: { type: {} },
      id_: { type: {} },
      implicitRules: { type: String },
      implicitRules_: { type: {} },
      language: { type: String },
      language_: { type: {} },
      ...schema
    });
  }
}
export default resource;

然后,在创建/更新资源时,_id字段从id中获取其值

我用来插入患者资源的代码

代码语言:javascript
复制
upsert(root, params, context, ast) {
    const projection = this.getProjection(ast);
    if (!params.data.id) {
      params.data.id = shortid.generate();
    }
    params.data.resourceType = 'Patient';
    const upserted = model
      .findByIdAndUpdate(params.data.id, params.data, {
        new: true,
        upsert: true,
        select: projection
      })
      .exec();

    if (!upserted) {
      throw new Error('Error upserting');
    }
    return upserted;
  }
票数 1
EN

Stack Overflow用户

发布于 2016-11-20 14:47:02

是的,_id将不符合。你不能把它改成“id”吗?

票数 0
EN

Stack Overflow用户

发布于 2016-11-21 17:30:23

也许您可以看看Spark server,它也使用MongoDB来存储资源。在Spark.Store.Mongo命名空间中,您将看到一些助手方法,用于将Mongo BSONdocument转换为FHIR资源。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40701191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档