@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
92 lines (87 loc) • 3.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EventIdentification = void 0;
var _ATNAComplexType = require("./ATNAComplexType.js");
var _Code = require("./Code.js");
var _XMLElement = require("../helpers/xml/XMLElement.js");
/**
* Represents an EventIdentification element for ATNA.
*/
class EventIdentification extends _ATNAComplexType.ATNAComplexType {
/**
* @param {string} actionCode - The action code.
* @param {string|Date} datetime - The event datetime.
* @param {string} outcome - The event outcome indicator.
*/
constructor(actionCode, datetime, outcome) {
super();
this.actionCode = actionCode;
this.datetime = datetime instanceof Date ? datetime : new Date(datetime);
this.outcome = outcome;
}
/**
* Sets the EventID for the EventIdentification.
* @param {Code} eventID - The EventID code.
* @returns {EventIdentification} - Returns the current instance for chaining.
*/
setEventID(eventID) {
if (eventID instanceof _Code.Code) {
this.eventID = eventID;
} else {
throw new Error(`Not a valid EventID`, eventID);
}
return this;
}
/**
* Sets the PurposeOfUse for the EventIdentification.
* @param {Code} purposeOfUse - The PurposeOfUse for the event.
* @returns {EventIdentification} - Returns the current instance for chaining.
*/
setPurposeOfUse(purposeOfUse) {
if (purposeOfUse instanceof _Code.Code) {
this.purposeOfUse = purposeOfUse;
} else {
throw new Error(`Not a valid PurposeOfUse`, purposeOfUse);
}
return this;
}
/**
* Sets the TypeCode for the EventIdentification.
* @param {Code} typeCode - The TypeCode for the event.
* @returns {EventIdentification} - Returns the current instance for chaining.
*/
setTypeCode(typeCode) {
if (typeCode instanceof _Code.Code) {
this.typeCode = typeCode;
} else {
throw new Error(`Not a valid TypeCode`, typeCode);
}
return this;
}
/**
* Prepares XML representation of the EventIdentification element.
* @returns {XMLElement} - The XML representation of the EventIdentification element.
*/
prepareXML() {
let attributes = {
EventActionCode: this.actionCode,
EventDateTime: this.datetime.toISOString(),
EventOutcomeIndicator: this.outcome
};
this.xml = new _XMLElement.XMLElement().setName('EventIdentification');
if (this.eventID) {
this.xml.addChild(new _XMLElement.XMLElement().setName('EventId').addChild(this.eventID.prepareXML()));
}
if (this.purposeOfUse) {
this.xml.addChild(new _XMLElement.XMLElement().setName('PurposeOfUse').addChild(this.purposeOfUse.prepareXML()));
}
if (this.typeCode) {
this.xml.addChild(new _XMLElement.XMLElement().setName('EventTypeCode').addChild(this.typeCode.prepareXML()));
}
this.xml.setAttributes(attributes);
return this.xml;
}
}
exports.EventIdentification = EventIdentification;