Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parsing a file that's not quite comma-delimited
Message
From
13/07/2007 09:25:28
 
 
To
11/07/2007 18:23:55
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:
01240138
Views:
21
>>>>>>If you create specialized LineToObject methods that match with field namings of target tables then you'd directly do an insert into in those methods. The one I wrote is a generic parser.
>>>>>
>>>>>Sweet! What is the best way to insert into a cursor from an object?
>>>>
>>>>I still warn you. The string you are attempting to parse is a medical HL7 delimited string. This format has expanded and become VERY complicated to parse. Image a five dimensional spare string array. If you have not heard of this, you may have trouble getting your mind around HL7. Strongly requimend Google'ing for HL7 format and HL7 parser.
>>>>
>>>>P.S. I once attempting to write a parser myself and finally used a existing parser after wasting over a month trying to prefect it.
>>>
>>>Not seeing what's so tough about it. You run through the lines, run through the segments, etc. With help, I've aleady got each line into it's own object. Just a matter of getting that into cursors, using a data dictionary to handle the mapping from the cursors to the correct table/field. Not easy, and kind of tedious, but doesn't seem incredibly hard. Not much different than importing comma-delimited data really, just have more hoops to jump through. Or did I miss your point?
>>
>>Yes, you got my point.
>
>Were you being serious? I was. I want to know if what I posted above was a correct assumption, or is there much more to this that I'm not seeing, but you are aware of?

From my and others help, I believe you are on the right road.

By the way, your problem intrigued me last night. I throw together a snip of code that parse the HL7 stream (include all five levels of nesting). It crude, but I hope it leads you in the right direction. (P.S. I left off when I discovered it was skipping the first element of each level, I think.)
*------------------------------------------------------------
* Description: Basic HL7 Parse
* Parameters:  <para>, <req/opt>, D=<def>, <desc>
* Return:
* Use:
*------------------------------------------------------------
* Id Date		By		Description
*  1 07/11/2007	GLR		Initial Creation
*
*------------------------------------------------------------
TEXT TO lcHL7 noshow
MSH|^~\&|Medinotes|CP|External||20070705154008||DFT^P03|468D4AD320F3|P|2.4|||AL|||
EVN|P03|20070705154008|20070705154008
PID|1|11384|468AE48A7926||Johengen^Jay||20051108000000||||||||||||
PV1|1|O|Ambulatory Surgery Center^^^^^^^^Ambulatory Surgery Center||||^Cardio^Full|||||||||||||||||||||||||||||||||||||20070705154008||||||
ORC|SN|
FT1|1|||20070705154008||CG||||||||||^^^Ambulatory Surgery Center|||250.00^Diabetes Mellitus Without Mention Of Complication, Type II Or Unspecified Type, Not Stated As Uncontrolled^I9|^Cardio^Full|||||99212^Office Or Other Outpatient Visit For The Evaluation And Management Of An Established Patient, Which Requires At Least Two Of These Three Key Components: A Problem Focused History; A Problem Focused Examination; Straightforward Medical Decision Making. Counseling And/Or Coordination Of Care With Other Providers Or Agencies Are Provided Consistent With The Nature Of The Problem(s) And The Patient's And/Or Family's Needs. Usually, The Presenting Problem(s) Are Self Limited Or Minor. Physicians Typically Spend 10 Minutes Face-To-Face With The Patient And/Or Family.^C4|
DG1|1||250.00^Diabetes Mellitus Without Mention Of Complication, Type II Or Unspecified Type, Not Stated As Uncontrolled^I9|||F
ENDTEXT

#DEFINE CRLF CHR(13)+CHR(10)

*07/11/2007 16:17:14- GLR -------------------------
* validate the stream
*--------------------------------------------------
IF LEFT(lcHL7,3)="MSH"

	*07/11/2007 16:16:56- GLR -------------------------
	* each line is object in the collection
	*--------------------------------------------------
	PRIVATE loHL7
	loHL7 = CREATEOBJECT("Empty")

	*07/11/2007 16:18:36- GLR -------------------------
	* get delimiters
	*--------------------------------------------------
	ADDPROPERTY(loHL7, "Delimiters", SUBSTR(lcHL7,4,5) )
	LOCAL pnLevel
	pnLevel = 0

	*07/11/2007 16:17:30- GLR -------------------------
	* walk down the list
	*--------------------------------------------------
	LOCAL i, laHL7[1] 
	FOR i=1 TO ALINES(laHL7,lcHL7,.T.,CRLF)


		*07/11/2007 16:20:56- GLR -------------------------
		* create object, and assign unique name
		*--------------------------------------------------
		LOCAL lcName AS String 
		lcName = LEFT(laHL7[i],3)+SYS(2015)
		ADDPROPERTY(loHL7, lcName, CREATEOBJECT("Empty"))

		ParseLine( EVALUATE("loHL7."+lcName), laHL7[i], pnLevel )

	NEXT

ELSE
	? "Not a HL7 stream"
ENDIF

RETURN loHL7

*------------------------------------------------------------
* Description:
* Parameters:  <para>, <req/opt>, D=<def>, <desc>
* Return:
* Use:
*------------------------------------------------------------
* Id Date		By		Description
*  1 07/11/2007	GLR		Initial Creation
*
*------------------------------------------------------------
PROCEDURE ParseLine
	LPARAMETERS toObj, tcLine, tnLevel

	LOCAL laLine[1], lcDelimiter AS String , j
	
	tnLevel = tnLevel + 1
	lcDelimiter = SUBSTR(loHL7.delimiters, tnLevel,1)

	FOR j=2 TO ALINES(laLine, tcLine, .F., lcDelimiter)

		ADDPROPERTY(toObj, "prop"+TRANSFORM(j), laLine[j])
		
		IF SUBSTR(loHL7.delimiters, tnLevel+1,1) $ laLine[j]
		
			ADDPROPERTY(toObj, "obj"+TRANSFORM(j), CREATEOBJECT("Empty") )

			ParseLine( EVALUATE("toObj."+"obj"+TRANSFORM(j)), laLine[j], tnLevel )
		ENDIF
	NEXT


ENDPROC
Greg Reichert
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform