Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parsing a file that's not quite comma-delimited
Message
 
To
17/07/2007 13:05:57
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01238841
Message ID:
01241201
Views:
38
Jay

I use the Symphonia 3 (http://www.symphonia3.com/) components for communication and parsing. It works well, but is expensive ($3K) plus a royalty fee on my distributed interfaces. But it makes it pretty easy, I just create the objects, and use vfpcom to capture the events when they fire. Basically there are three events, New Connection, New Message (fires when complete message received) and Connection Dropped.

Once the new message event fires, I pull the data from the stream, stick it in a file, send an ACK, and then parse and process the message. The other day we did an initial patient dump from the HIS system via the interface, 48K HL7 messages came across one at a time and we processed them in 3 hours.

Below is the abbreviated version of the code.
************************************************************************
* Create the Objects that listen for messages
* Using the Symphonia HL7 Communication componenets
************************************************************************
ovfpcomm 		= CREATEOBJECT('vfpCom.comutil')
vfpsockevent 	= NEWOBJECT("_IConnectionFactoryEvents")
sockfactory 	= CREATEOBJECT("S2TCPComms.TCPConnectionFactory.1")
************************************************************************
* Define The Parser Control for decoding the messages
************************************************************************
oparser 		= CREATEOBJECT("pbaradt.inputParser.1")
IF VARTYPE(oParser)!=[O]
	=MESSAGEBOX("Could not create oParser - pbaradt.inputParser",16,"PBARLIST",20000)
ENDIF 

*************************************************************************
* Bind the HL7 Message events so that VFP can do something when they 
* (messages) are received
*************************************************************************
ovFpcomm.bindEvents(sockfactory,vfpSockEvent)
*************************************************************************
* Tell it which port to listen on and to start listening
*************************************************************************
sockfactory.listen(lcPortid)

read events



**************************************************************************
* Here is the message class factory code that is bound to events
**************************************************************************
DEFINE CLASS _IConnectionFactoryEvents AS CUSTOM
PROCEDURE NewMessage
	LPARAMETERS CONNECTION
	***********************************************************
	* This event fires when we receive a message
	* from the remote system
	***********************************************************
	*****************************************************************
	* Get the message from the connection object into a string
	* varaible, and save it as a file
	*****************************************************************
	dataReceived = CONNECTION.readmessage
	STRTOFILE(dataReceived, lcFile, 0)
	*****************************************************************
	* Send Ack back to other system
	*****************************************************************
	CONNECTION.sendmessage(oack.parse)
	*****************************************************************
	* Parse and Process Message
	*****************************************************************
	do ParseMsg with lcFile
	
EndProc

ENDDEFINE
Previous
Reply
Map
View

Click here to load this message in the networking platform