web stats
Mirth Community - View Single Post - Using JavaScript Objects for Transformations
View Single Post
Old 01-11-2019, 12:16 AM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,106
agermano is on a distinguished road

I like the approach.

I would change your toJSON function to return an object instead of a string.

PatientStay.prototype.toJSON = function() {
    return {
        patientFirstName: this.patientFirstName(),
        patientLastName: this.patientLastName(),
        mrn: this.getMedicalRecordNumber()
That should reduce your hospitalA transformer to
msg = new PatientStayHL7(msg);
as setting the outbound type to JSON will automatically call JSON.stringify(msg) when your transformer finishes (which will in turn call your toJSON function.)

I also wouldn't bother subclassing unless you plan on putting the derived class in the code template to share between multiple hospitals. If I was overriding in the transformer I would do it like this (assuming the above change was also made:)
msg = new PatientStayHL7(msg);

// Override getMedicalRecordNumber to pull from PID.2.1 instead of PID.2.1
msg.getMedicalRecordNumber = function() {
	return this.hl7Message['PID']['PID.2']['PID.2.1'].toString()
Reply With Quote