web stats
Mirth Community - View Single Post - Using JavaScript Objects for Transformations
View Single Post
  #2  
Old 01-10-2019, 11:16 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 898
agermano is on a distinguished road
Default

I like the approach.

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

Code:
PatientStay.prototype.toJSON = function() {
    return {
        patientFirstName: this.patientFirstName(),
        patientLastName: this.patientLastName(),
        mrn: this.getMedicalRecordNumber()
    };
}
That should reduce your hospitalA transformer to
Code:
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:)
Code:
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