|
#1
|
|||
|
|||
![]()
I'm attempting to cleanup a bunch of our channels that have duplicate code and consolidate our logic.
Most of our interfaces are HL7 which we transform into a standard JSON message that gets passed to our application for processing. The logic for 95% of the channels is the same (map PID.5.1 to first name, etc ...). We have moved a large portion of our code base to code template functions. While this has reduced a large portion of duplicate code, I'm not completely satisfied with the results. Because there are some interfaces that do something different, we have to account for it by adding some if/then logic in the functions or duplicate the function to be use just by that channel. I'm looking to move to a more object oriented approach and was wondering if anyone has done anything similar. I'm looking to move our logic to a JavaScript object stored as code template. You create this object in your channel transformation, pass the message and call a method to return the transformed message. For those interfaces that like to be different, I could override the particular method that maps the field which is different. No duplicate code is create. In my sample code, I have a base object PatientStay which has a method to create my standard JSON message. The PatientStayHL7 message inherits from PatientStay and provides methods to populate the JSON (map first name to PID.5.1). Code:
// Base class (used by HL7, delimiter, etc ..) function PatientStay() {}; PatientStay.prototype.toJSON = function() { var patientStayJSON = { patientFirstName: this.patientFirstName(), patientLastName: this.patientLastName(), mrn: this.getMedicalRecordNumber() } return JSON.stringify(patientStayJSON); } PatientStay.prototype.patientFirstName = function() { return null; } PatientStay.prototype.patientLastName = function() { return null; } PatientStay.prototype.getMedicalRecordNumber = function() { return null; } // PatientStay HL7 function PatientStayHL7(hl7Message) { this.hl7Message = hl7Message.copy(); } PatientStayHL7.prototype = Object.create(PatientStay.prototype); PatientStayHL7.prototype.patientFirstName = function() { return this.hl7Message['PID']['PID.5']['PID.5.2'].toString(); } PatientStayHL7.prototype.patientLastName = function() { return this.hl7Message['PID']['PID.5']['PID.5.1'].toString(); } PatientStayHL7.prototype.getMedicalRecordNumber = function() { return this.hl7Message['PID']['PID.3']['PID.3.1'].toString() } Code:
var patientStay = new PatientStayHL7(msg); msg = patientStay.toJSON(); In this example they put the MRN in 2.1 instead of 2.3. Code:
// Create HospitalB object that inherits from PatientStayHL7 function HospitalB(hl7Message) { PatientStayHL7.call(this, hl7Message); } HospitalB.prototype = Object.create(PatientStayHL7.prototype); // Override getMedicalRecordNumber to pull from PID.2.1 instead of PID.2.1 HospitalB.prototype.getMedicalRecordNumber = function() { return this.hl7Message['PID']['PID.2']['PID.2.1'].toString() } var patientStay = new HospitalB(msg); msg = patientStay.toJSON(); Thoughts? Any downsides? An alternative that you are using successfully |
#2
|
|||
|
|||
![]()
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() }; } Code:
msg = new PatientStayHL7(msg); 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() } |
#3
|
|||
|
|||
![]()
Much appreciated. Both good suggestions.
|
#4
|
|||
|
|||
![]()
Adding to this, is it possible to store the mappings in the database and use it in the channel?
So that I do not have to make any changes to the channel when an interface follows a different mappings??? |
#5
|
|||
|
|||
![]()
Yes it is. Which database are you using?
|
#6
|
|||
|
|||
![]()
I'm planning to use SQL DB. Can you tell me how. I'm able to store all the mapping and read it in mirth, but I'm not able to use those as it is.
|
![]() |
Tags |
mapping, xpath |
Thread Tools | |
Display Modes | |
|
|