Replies: 1 comment 1 reply
-
The error you're encountering indicates that the XML being processed has an
issue at the very start ("Content is not allowed in prolog"). This often
happens due to unexpected characters before the XML declaration.
Here are the steps to troubleshoot and resolve the issue:
1.
Check for Hidden Characters: Ensure that the XML string does not have
any hidden characters (like BOM - Byte Order Mark) or spaces before the XML
declaration. This can be done by logging the XML content before it's
processed to check for any such characters.
2.
Validate the JSON Structure: Ensure that the JSON structure being
converted to HL7 is correct. Your current code already does this, but
double-checking the input JSON can help avoid structural issues.
3.
Debug Logging: Add additional logging to see the exact XML content being
passed to the ER7Serializer. This can help identify if the issue is with
the transformation or the content itself.
4.
Error Handling: Modify the error handling to capture and log more
details about the failure.
// Check if msg is already a JSON object
var jsonData;
if (typeof msg === 'string') {
// If it's a string, parse it to a JSON object
try {
jsonData = JSON.parse(msg);
} catch (e) {
throw new Error("Failed to parse JSON string: " + e.message);
}
} else {
// If it's already an object, use it directly
jsonData = msg;
}
// Ensure the structure is as expected
if (!jsonData || !jsonData.patientdetails ||
!Array.isArray(jsonData.encountermetadata)) {
throw new Error("Invalid JSON structure");
}
var patient = jsonData.patientdetails;
var encounters = jsonData.encountermetadata;
function formatHL7Date(dateString) {
var date = new Date(dateString);
var year = date.getFullYear().toString().padStart(4, '0');
var month = (date.getMonth() + 1).toString().padStart(2, '0');
var day = date.getDate().toString().padStart(2, '0');
var hours = date.getHours().toString().padStart(2, '0');
var minutes = date.getMinutes().toString().padStart(2, '0');
var seconds = date.getSeconds().toString().padStart(2, '0');
return year + month + day + hours + minutes + seconds;
}
function createHL7Message(patient, encounter) {
var MSH = [
"MSH",
"^~\\&",
"ATHENA",
"HF",
"EPIC",
"HF",
formatHL7Date(new Date().toISOString()),
"",
"ADT^A08",
"123456",
"P",
"2.3",
].join("|");
var EVN = [
"EVN",
"",
formatHL7Date(new Date().toISOString()),
"",
"",
"",
formatHL7Date(encounter.lastupdated || "")
].join("|");
var PID = [
"PID",
"",
"",
patient.athenapatientid,
"",
patient.lastname + "^" + patient.firstname,
"",
formatHL7Date(patient.dob || "")
].join("|");
var PV1 = [
"PV1",
"",
"OP",
encounter.departmentid,
"",
"",
"",
encounter.providerid,
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
encounter.encounterid,
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
formatHL7Date(encounter.encounterdate || ""),
formatHL7Date(encounter.encounterdate || "")
].join("|");
// Combine segments into a single HL7 message
return [MSH, EVN, PID, PV1].join("\r");
}
// Create HL7 messages for each encounter
var hl7Messages = encounters.map(function(encounter) {
return createHL7Message(patient, encounter);
});
// Log the generated HL7 message for debugging
logger.info("Generated HL7 Messages: " + hl7Messages.join("\r"));
// Set the transformed HL7 messages as the outbound message
msg = hl7Messages.join("\r");
logger.info("Parsed JSON Data: " + JSON.stringify(jsonData));
logger.info("Generated HL7 Messages: " + msg);
…On Tue, May 28, 2024 at 2:42 PM jgh1189 ***@***.***> wrote:
Creating mirth channel to translate encounter data from JSON files to HL7.
Config info, error message, and code listed below. Any help is appreciated.
Thanks.
Json_to_Hl7.Summary.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/fe9bb774-d9b1-4a96-a57d-eafc5606b806>
Json_to_Hl7.Summary.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/fe9bb774-d9b1-4a96-a57d-eafc5606b806>
Json_to_Hl7.Source.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/f8741a4c-7cf6-4ecc-a7a8-5a44c1754864>
Json_to_Hl7.Source.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/f8741a4c-7cf6-4ecc-a7a8-5a44c1754864>
Json_to_Hl7.Destination.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/b1e891a8-9aa6-4ed0-a851-01cfd901a778>
Json_to_Hl7.Destination.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/b1e891a8-9aa6-4ed0-a851-01cfd901a778>
Logger.details.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/fe97f121-5974-4b34-b778-9bdabf541bf2>
Logger.details.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/fe97f121-5974-4b34-b778-9bdabf541bf2>
Messages.Tranformed.output.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/9faa8341-f71c-4836-9cb0-74128e88c702>
Messages.Tranformed.output.png (view on web)
<https://github.com/nextgenhealthcare/connect/assets/109697053/9faa8341-f71c-4836-9cb0-74128e88c702>
*Error Message:*
ER7Serializer error
ERROR MESSAGE: Error converting XML to ER7
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is
not allowed in prolog.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at
com.mirth.connect.plugins.datatypes.hl7v2.ER7Serializer.fromXML(ER7Serializer.java:304)
at
com.mirth.connect.donkey.server.channel.FilterTransformerExecutor.processConnectorMessage(FilterTransformerExecutor.java:122)
at
com.mirth.connect.donkey.server.channel.Channel.process(Channel.java:1675)
at
com.mirth.connect.donkey.server.channel.Channel.dispatchRawMessage(Channel.java:1302)
at
com.mirth.connect.donkey.server.channel.SourceConnector.dispatchRawMessage(SourceConnector.java:194)
at
com.mirth.connect.donkey.server.channel.SourceConnector.dispatchRawMessage(SourceConnector.java:172)
at
com.mirth.connect.connectors.file.FileReceiver.processFile(FileReceiver.java:418)
at
com.mirth.connect.connectors.file.FileReceiver.processFiles(FileReceiver.java:328)
at
com.mirth.connect.connectors.file.FileReceiver.poll(FileReceiver.java:239)
at
com.mirth.connect.donkey.server.channel.PollConnectorJob.execute(PollConnectorJob.java:49)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
// Check if msg is already a JSON object
var jsonData;
if (typeof msg === 'string') {
// If it's a string, parse it to a JSON object
jsonData = JSON.parse(msg);
} else {
// If it's already an object, use it directly
jsonData = msg;
}
// Ensure the structure is as expected
if (!jsonData || !jsonData.patientdetails || !Array.isArray(jsonData.encountermetadata)) {
throw new Error("Invalid JSON structure");
}
var patient = jsonData.patientdetails;
var encounters = jsonData.encountermetadata;
function formatHL7Date(dateString) {
var date = new Date(dateString);
var year = date.getFullYear().toString().padStart(4, '0');
var month = (date.getMonth() + 1).toString().padStart(2, '0');
var day = date.getDate().toString().padStart(2, '0');
var hours = date.getHours().toString().padStart(2, '0');
var minutes = date.getMinutes().toString().padStart(2, '0');
var seconds = date.getSeconds().toString().padStart(2, '0');
return year + month + day + hours + minutes + seconds;
}
function createHL7Message(patient, encounter) {
var MSH = [
"MSH",
"^~\\&",
"ATHENA",
"HF",
"EPIC",
"HF",
formatHL7Date(new Date().toISOString()),
"",
"ADT^A08",
"123456",
"P",
"2.3",
].join("|");
var EVN = [
"EVN",
"",
formatHL7Date(new Date().toISOString()),
"",
"",
"",
formatHL7Date(encounter.lastupdated || "")
].join("|");
var PID = [
"PID",
"",
"",
patient.athenapatientid,
"",
patient.lastname + "^" + patient.firstname,
"",
formatHL7Date(patient.dob || "")
].join("|");
var PV1 = [
"PV1",
"",
"OP",
encounter.departmentid,
"",
"",
"",
encounter.providerid,
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
encounter.encounterid,
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
formatHL7Date(encounter.encounterdate || ""),
formatHL7Date(encounter.encounterdate || "")
].join("|");
// Combine segments into a single HL7 message
return [MSH, EVN, PID, PV1].join("\r");
}
// Create HL7 messages for each encounter
var hl7Messages = encounters.map(function(encounter) {
return createHL7Message(patient, encounter);
});
logger.info("Parsed JSON Data: " + JSON.stringify(jsonData));logger.info("Generated HL7 Messages: " + hl7Messages.join("\r"));
// Set the transformed HL7 messages as the outbound message
msg = hl7Messages.join("\r");
logger.info("Parsed JSON Data: " + JSON.stringify(jsonData));logger.info("Generated HL7 Messages: " + hl7Messages.join("\r"));
—
Reply to this email directly, view it on GitHub
<#6213>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/APRXWD6WS6EPATO2ZAZICSLZETFXXAVCNFSM6AAAAABINPHVVWVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWG42DGOJRGA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Best,
Kirby Knight
| 231.735.4650 | ***@***.***
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Creating mirth channel to translate encounter data from JSON files to HL7. Config info, error message, and code listed below. Any help is appreciated. Thanks.
Error Message:
ER7Serializer error
ERROR MESSAGE: Error converting XML to ER7
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.mirth.connect.plugins.datatypes.hl7v2.ER7Serializer.fromXML(ER7Serializer.java:304)
at com.mirth.connect.donkey.server.channel.FilterTransformerExecutor.processConnectorMessage(FilterTransformerExecutor.java:122)
at com.mirth.connect.donkey.server.channel.Channel.process(Channel.java:1675)
at com.mirth.connect.donkey.server.channel.Channel.dispatchRawMessage(Channel.java:1302)
at com.mirth.connect.donkey.server.channel.SourceConnector.dispatchRawMessage(SourceConnector.java:194)
at com.mirth.connect.donkey.server.channel.SourceConnector.dispatchRawMessage(SourceConnector.java:172)
at com.mirth.connect.connectors.file.FileReceiver.processFile(FileReceiver.java:418)
at com.mirth.connect.connectors.file.FileReceiver.processFiles(FileReceiver.java:328)
at com.mirth.connect.connectors.file.FileReceiver.poll(FileReceiver.java:239)
at com.mirth.connect.donkey.server.channel.PollConnectorJob.execute(PollConnectorJob.java:49)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Source Transformer Code:
Beta Was this translation helpful? Give feedback.
All reactions