fhirbuilder
Version:
Another FHIR Tool to build FHIR Resources
124 lines (123 loc) • 4.09 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BundleBuilder = void 0;
const models_1 = require("../../models");
const base_1 = require("../base");
/**
* @version R4 (v4.0.1)
* @summary FHIR® Specification by HL7®
* @description Class for building a Bundle
* @class BundleBuilder
* @extends {DomainResourceBuilder}
* @implements {IBundleBuilder}
* @author Roberto Araneda Espinoza
*/
class BundleBuilder extends base_1.DomainResourceBuilder {
bundle;
constructor() {
super();
this.bundle = new models_1.Bundle();
}
/**
* @description Sets the resource type to Bundle
* @param json - the json to parse
* @returns {this}
*/
fromJSON(json) {
const incomingData = typeof json === 'string' ? JSON.parse(json) : json;
Object.assign(this.bundle, incomingData);
return this;
}
/**
* @description Adds a primitive extension to the element
* @param param - the field to add the extension to
* @param extension - the extension to add
* @returns {this}
* @example addPrimitiveExtension('_value', { value: 'test' })
*/
addPrimitiveExtension(param, extension) {
this.bundle[param] = extension;
return this;
}
/**
* @description Builds the model
* @returns {Bundle}
*/
build() {
return Object.assign(this.bundle, super.build());
}
/**
* @description Sets the identifier value
* @description A persistent identifier for the bundle that won't change as a bundle is copied from server to server.
* @param value - the value to set
* @returns {this}
*/
setIdentifier(value) {
this.bundle.identifier = value;
return this;
}
/**
* @description Sets the type value
* @description Indicates the purpose of this bundle - how it is intended to be used.
document | message | transaction | transaction-response | batch | batch-response | history | searchset | collection.
* @param value - the value to set
* @returns {this}
*/
setType(value) {
this.bundle.type = value;
return this;
}
/**
* @description Sets the timestamp value
* @description The date/time that the bundle was assembled - i.e. when the resources were placed in the bundle.
* @param value - the value to set
* @returns {this}
*/
setTimestamp(value) {
this.bundle.timestamp = value;
return this;
}
/**
* @description Sets the total value
* @description If a set of search matches, this is the total number of entries of type 'match' across all pages in the search. It does not include search.mode = 'include' or 'outcome' entries and it does not provide a count of the number of entries in the Bundle.
* @param value - the value to set
* @returns {this}
*/
setTotal(value) {
this.bundle.total = value;
return this;
}
/**
* @description Adds a value to the link array
* @description A series of links that provide context to this bundle.
* @param value - the value to add
* @returns {this}
*/
addLink(value) {
this.bundle.link = this.bundle.link || [];
this.bundle.link.push(value);
return this;
}
/**
* @description Adds a value to the entry array
* @description An entry in a bundle resource - will either contain a resource or information about a resource (transactions and history only).
* @param value - the value to add
* @returns {this}
*/
addEntry(value) {
this.bundle.entry = this.bundle.entry || [];
this.bundle.entry.push(value);
return this;
}
/**
* @description Sets the signature value
* @description Digital Signature - base64 encoded. XML-DSig or a JWT.
* @param value - the value to set
* @returns {this}
*/
setSignature(value) {
this.bundle.signature = value;
return this;
}
}
exports.BundleBuilder = BundleBuilder;