Sha256: 56367a7c2872087fb5b41ae44c32abf5a80d6e6f833d8f12d6484080e4c79798
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
const mongoose = require('mongoose/browser'); const { PatientEntity } = require('../attributes/PatientEntity'); const { Practitioner } = require('../attributes/Practitioner'); const { CarePartner } = require('../attributes/CarePartner'); const { Organization } = require('../attributes/Organization'); const { Location } = require('../attributes/Location'); function AnyEntity(key, options) { mongoose.SchemaType.call(this, key, options, 'AnyEntity'); } AnyEntity.prototype = Object.create(mongoose.SchemaType.prototype); AnyEntity.prototype.cast = (entity) => { if (entity == null) { return null; } if (entity instanceof PatientEntity || entity instanceof Practitioner || entity instanceof CarePartner || entity instanceof Organization || entity instanceof Location) { return entity; } if (entity._type != null) { // copy _id to id if it isn't defined if (entity.id == null && entity._id != null) { entity.id = entity._id; } switch (entity._type) { case 'QDM::PatientEntity': return new PatientEntity(entity); case 'QDM::Practitioner': return new Practitioner(entity); case 'QDM::CarePartner': return new CarePartner(entity); case 'QDM::Organization': return new Organization(entity); case 'QDM::Location': return new Location(entity); default: throw new Error(`Could not find entity type "${entity._type}".`); } } else { throw new Error('Could not find _type indicator for entity.'); } }; mongoose.Schema.Types.AnyEntity = AnyEntity; module.exports = AnyEntity;
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cqm-models-4.2.0 | app/assets/javascripts/basetypes/AnyEntity.js |