@interoperability/atna-audit-messages
Version:
The ATNA Audit Messages Generator is a JavaScript library that provides a set of reusable static methods for generating Audit Trail and Node Authentication (ATNA) compliant audit messages. This library is particularly useful in healthcare systems and othe
113 lines (108 loc) • 4.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AuditMessage = void 0;
var _ATNAComplexType = require("./ATNAComplexType.js");
var _ActiveParticipant = require("./ActiveParticipant.js");
var _AuditSourceIdentification = require("./AuditSourceIdentification.js");
var _EventIdentification = require("./EventIdentification.js");
var _ParticipantObjectIdentification = require("./ParticipantObjectIdentification.js");
var _XMLElement = require("../helpers/xml/XMLElement.js");
/**
* Represents an AuditMessage element for ATNA.
*/
class AuditMessage extends _ATNAComplexType.ATNAComplexType {
/**
* @param {EventIdentification} eventIdent - The event identification for the audit message.
*/
constructor(eventIdent) {
super();
if (eventIdent instanceof _EventIdentification.EventIdentification) {
this.eventIdent = eventIdent;
} else {
throw new Error(`Not a valid event identification!`);
}
}
/**
* Sets the ActiveParticipant elements for the AuditMessage.
* @param {ActiveParticipant|ActiveParticipant[]} activeParticipants - The ActiveParticipants.
* @returns {AuditMessage} - Returns the current instance for chaining.
*/
setActiveParticipant(activeParticipants) {
if (!Array.isArray(activeParticipants)) {
activeParticipants = [activeParticipants];
}
this.activeParticipants = activeParticipants.map(activeParticipant => {
if (activeParticipant instanceof _ActiveParticipant.ActiveParticipant) {
return activeParticipant;
} else {
throw new Error(`Not a valid ActiveParticipant`, activeParticipant);
}
});
return this;
}
/**
* Sets the ParticipantObjectIdentification elements for the AuditMessage.
* @param {ParticipantObjectIdentification|ParticipantObjectIdentification[]} participantObjs - The ParticipantObjectIdentifications.
* @returns {AuditMessage} - Returns the current instance for chaining.
*/
setParticipantObjectIdentification(participantObjs) {
if (!Array.isArray(participantObjs)) {
participantObjs = [participantObjs];
}
this.participantObjs = participantObjs.map(participantObj => {
if (participantObj instanceof _ParticipantObjectIdentification.ParticipantObjectIdentification) {
return participantObj;
} else {
throw new Error(`Not a valid ParticipantObjectIdentification`, participantObj);
}
});
return this;
}
/**
* Sets the AuditSourceIdentification elements for the AuditMessage.
* @param {AuditSourceIdentification|AuditSourceIdentification[]} auditSources - The AuditSourceIdentifications.
* @returns {AuditMessage} - Returns the current instance for chaining.
*/
setAuditSourceIdentification(auditSources) {
if (!Array.isArray(auditSources)) {
auditSources = [auditSources];
}
this.auditSources = auditSources.map(auditSource => {
if (auditSource instanceof _AuditSourceIdentification.AuditSourceIdentification) {
return auditSource;
} else {
throw new Error(`Not a valid AuditSourceIdentification`, auditSource);
}
});
return this;
}
/**
* Prepares XML representation of the AuditMessage element.
* @returns {XMLElement} - The XML representation of the AuditMessage element.
*/
prepareXML() {
this.xml = new _XMLElement.XMLElement().setName('AuditMessage');
if (this.eventIdent) {
this.xml.addChild(this.eventIdent.prepareXML());
}
if (this.activeParticipants) {
this.activeParticipants.forEach(participant => {
this.xml.addChild(participant.prepareXML());
});
}
if (this.auditSources) {
this.auditSources.forEach(auditSource => {
this.xml.addChild(auditSource.prepareXML());
});
}
if (this.participantObjs) {
this.participantObjs.forEach(participantObj => {
this.xml.addChild(participantObj.prepareXML());
});
}
return this.xml;
}
}
exports.AuditMessage = AuditMessage;