emsi-lib
Version:
A EMSI (Emergency Management Shared Information) object model to manipulate emergency messages defined in ISO/TR 22351 document
109 lines (108 loc) • 4.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Resource = void 0;
const config_1 = require("../../common/config");
const default_1 = require("../../common/default");
const resource_error_1 = require("../../error/resource.error");
const contact_1 = require("./contact");
const resource_geo_1 = require("./resource-geo");
const resource_type_1 = require("./resource-type");
class Resource extends default_1.Default {
constructor(rTypes, id) {
if (rTypes.length === 0)
throw new resource_error_1.ResourceError('Description of resource is required');
resource_error_1.ResourceError.checkLength(id, config_1.MAX_RESOURCE_ID_LENGTH);
super();
this.rType = rTypes;
this.id = id;
}
setOrgId(orgId) {
resource_error_1.ResourceError.checkLength(orgId, config_1.MAX_ID_LENGTH);
this.orgId = orgId;
return this;
}
setName(name) {
resource_error_1.ResourceError.checkLength(name, config_1.MAX_NAME_LENGTH);
this.name = name;
return this;
}
setfreeText(freeText) {
resource_error_1.ResourceError.checkLength(freeText, config_1.MAX_FREETEXT_LENGTH);
this.freeText = freeText;
return this;
}
addResourceGeo(rgeos) {
if (!this.rGeo)
this.rGeo = new Array();
this.rGeo.push(...rgeos);
return this;
}
setQuantity(quantity) {
this.quantity = quantity;
return this;
}
setUnitOfMeasure(unit) {
this.um = unit;
return this;
}
setStatus(status) {
this.status = status;
return this;
}
setNationality(nationality) {
this.nationality = nationality.substring(0, 2).toUpperCase();
return this;
}
addContact(contacts) {
if (!this.contact)
this.contact = new Array();
this.contact.push(...contacts);
return this;
}
static default() {
return new Resource([resource_type_1.RType.default()]);
}
assign(source) {
let key;
const keys = Object.keys(source);
if ((key = keys.find(f => f === 'id')))
this.id = source[key];
if ((key = keys.find(f => f === 'orgId')))
this.orgId = source[key];
if ((key = keys.find(f => f === 'name')))
this.name = source[key];
if ((key = keys.find(f => f === 'quantity')))
this.quantity = source[key];
if ((key = keys.find(f => f === 'um')))
this.um = source[key];
if ((key = keys.find(f => f === 'freeText')))
this.freeText = source[key];
if ((key = keys.find(f => f === 'status')))
this.status = source[key];
if ((key = keys.find(f => f === 'nationality')))
this.nationality = source[key];
if ((key = keys.find(f => f === 'rType'))) {
this.rType = new Array();
if (source[key] instanceof Array)
source[key].forEach((add) => { var _a; return (_a = this.rType) === null || _a === void 0 ? void 0 : _a.push(resource_type_1.RType.default().assign(add)); });
else
this.rType.push(resource_type_1.RType.default().assign([key]));
}
if ((key = keys.find(f => f === 'rGeo'))) {
this.rGeo = new Array();
if (source[key] instanceof Array)
source[key].forEach((add) => { var _a; return (_a = this.rGeo) === null || _a === void 0 ? void 0 : _a.push(resource_geo_1.RGeo.default().assign(add)); });
else
this.rGeo.push(resource_geo_1.RGeo.default().assign([key]));
}
if ((key = keys.find(f => f === 'contact'))) {
this.contact = new Array();
if (source[key] instanceof Array)
source[key].forEach((add) => { var _a; return (_a = this.contact) === null || _a === void 0 ? void 0 : _a.push(contact_1.Contact.default().assign(add)); });
else
this.contact.push(contact_1.Contact.default().assign([key]));
}
return this;
}
}
exports.Resource = Resource;