Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) [Solved] importing ASCII file in Subform (Read 2383 times)
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
[Solved] importing ASCII file in Subform
Sep 22nd, 2007 at 9:22am
Print Post Print Post  
Solution: See code later in thread.

Hello!

I have regularly ASCII - files from medical instruments exported and this would like to import in Sesame file.

Problem or better the luck that the Subform where the data to be imported is that each unique field of the ASCII - file 
already stored.

Thus only two results in the ASCII - file in the Subform to the suitable data record to add.
My desire to experience as is to be solved these tasks.

Each contribution or suggestion is to be thanked you cordially.


Dr. Belhareth
« Last Edit: Sep 25th, 2007 at 12:17am by Hammer »  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: importing ASCII file in Subform
Reply #1 - Sep 22nd, 2007 at 10:16am
Print Post Print Post  
Amor,

I think I know what you're asking for, but I'm not sure. Can you explain a bit further?

Also, is this a subform linking naturally or relationally?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: importing ASCII file in Subform
Reply #2 - Sep 22nd, 2007 at 11:03am
Print Post Print Post  
Hello Erika,

The subform linking is relationally.

Thanks.
Dr. Belhareth
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: importing ASCII file in Subform
Reply #3 - Sep 22nd, 2007 at 11:09am
Print Post Print Post  
Can you clarify what you have and what you need to do with it?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: importing ASCII file in Subform
Reply #4 - Sep 22nd, 2007 at 1:53pm
Print Post Print Post  
Hello Erika ,

The ASCII - File is Resultate to a Parameter for a Patient with unique OrderNo ="1000"
per Example  HIV -Antikorper with Code HIV for a OrderNo "1000" has a ParameterCode ("1000HIV")
In the Subform the Field ParameterCode ="1000HIV".
In the Subform the OrderNo and the ParameterCode to OrderNo 1000  is already stored.
But the Field Resultate in the Subform is still  empty (Resultate is the that ASCII-File).

In the ASCII - File the OrderNo 1000 and the Code "HIV" exit but not the ParameterCode ="1000HIV"

Each Code and The OrderNo for this Patient is in the ASCII - file somewhere say in the 3th and 5th Position.

I see it´s not easy to describe but i will try again  and again if you like.

Thanks.

Dr. Belhareth
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
pineberry
Full Member
***
Offline


No personal text

Posts: 115
Location: Strawberry, AZ  USA
Joined: Nov 30th, 2002
Re: importing ASCII file in Subform
Reply #5 - Sep 22nd, 2007 at 3:58pm
Print Post Print Post  
Dr. Belhareth,
Is the following the information you desire ?

Patient number
        1000HIV
          20/09/2007 result01
          20/09/2007 result02
          24/09/2007 result01
          24/09/2007 result02

Harley
  
Back to top
 
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: importing ASCII file in Subform
Reply #6 - Sep 22nd, 2007 at 7:42pm
Print Post Print Post  
Hello Harly,
The Result a desire per example:

Patient No 200
OrderNo  1000
AnalysisCode (unique)  1000HIV (for HIV)
AnalysisCode (unique)  1000HB (for HeptitisB)
AnalysisCode (unique)  1000CHO (for Cholesterin)

Pos. in the                                                      Item
Subform     PatientNo   OrderNo   ItemCode     Unique Code              Date & Results (must come from the ASCII-File)
1.                 200       1000         HIV              1000HIV                      20/09/2007 result01
2.                 200       1000         HB                1000Hb                       21/09/2007 result02
3.                 200       1000         CHO             1000CHO                     21/09/2007 result03
         
The ASCII - File contain the OrderNo and the ItemCode.

Thanks.
Dr. Belhareth
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: importing ASCII file in Subform
Reply #7 - Sep 22nd, 2007 at 7:47pm
Print Post Print Post  
Can we see a line or two from the ascii file?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: importing ASCII file in Subform
Reply #8 - Sep 22nd, 2007 at 8:48pm
Print Post Print Post  
Hello Erika,

Hier is a ASCII - File :
Each Line is one Patient:
Waht we need to import are the Results
                    OrderNo Item1.   Resultat1   Item2   Resultat2 .. etc

02E   3 0 3   119370   GLU         85.2         TRI       132


03E   4 0 4   119775   HB            2.31


02N   1 1 1   119776   TRI         133.6


03N   2 1 2   119795   GLU         62.2       NAT    45


02N   3 1 3   119796    NAT         133       KAL    12    CHL    9   TRI    11  CHOL   225 CAL  0.83  GLU   2.4  TRI   23 FT3   2 FT4 2  TSH 1.2


03N   4 1 4   119796   CHL          92


02N   5 1 5   119797   NAT          81        KAL    5   CHL    11  TRI   1 27  CHL   262  QUI  2.82  LDH  2.0  LDL   5.6 HCG    320   AFP  21   FT3 2.1 FT4 2.7   TSH   1.1   PSA  19    FPSA 1.2


03N   6 1 6   119797   HIV      0




Thanks.
Dr. Belhareth
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: importing ASCII file in Subform
Reply #9 - Sep 22nd, 2007 at 8:52pm
Print Post Print Post  
Can you depend on everything after the order number being an Item/Result pair?

What is the delimiter being used between the values on a line? Is it a Tab?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: importing ASCII file in Subform
Reply #10 - Sep 22nd, 2007 at 11:39pm
Print Post Print Post  
Erika,

The pair Order number Item/Result is UNIQUE!
The delimiter between the values it is a Tab.

Thank you.

Dr. Belhareth
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: importing ASCII file in Subform
Reply #11 - Sep 23rd, 2007 at 1:33pm
Print Post Print Post  
Assuming that your relational key is the order number, this is neatly doable with a combination of File I/O, Split, and XResultSet. I'll try to write it up for you tomorrow, unless someone beats me to it.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: importing ASCII file in Subform
Reply #12 - Sep 24th, 2007 at 3:44pm
Print Post Print Post  
Amor,

I created a small app with a Parent form (Orders) and a child form (Results) that matched your design. The parent and child are relationally linked by the OrderNo field.

I created a separate Tools database/form with a button on it for Import Records.

The button has the following code, which works quite well. Let me know if you'd like for me to put the actual app someplace you can get to it.

NOTE: If you do not have SERVER PREINDEX RELATIONAL: OFF in your ini file, you will need to close and reopen your database to see the new child records.

NOTE: This works for relational links. If you want to do this with natural linking, you will also need to use XResultSetReparent().

Code
Select All
#include "sbasic_include.sbas"

var vCRS as Int		// Child Result Set
var vFile as Int	// Results file
var vPatient as String	// Current PatientNo
var vOrder as String	// Current OrderNo
var vLine as String	// Current Results line from file
var vVal as String	// Current value from Results line
var vLen as Int		// Length of Results file
var vTemp as Int

FUNCTION ProcessLine() as Int
var vRet as Int
var vCode as String
var vResult as String

	vRet = 0
	// Everything left in line should be code/result pairs.
	// Make a subrecord for each pair.
	While @Len(vLine) > 0
	{
		vCode = Split(vLine, Tab(1))
		vResult = Split(vLine, Tab(1))
		If (vCode <> "") And (vResult <> "")
		{
			// Make new child record
			XResultSetCreateNewRecord(vCRS)
			XResultSetValue(vCRS, "PatientNo", vPatient)
			XResultSetValue(vCRS, "OrderNo", vOrder)
			XResultSetValue(vCRS, "ItemCode", vCode)
			XResultSetValue(vCRS, "UniqueCode", vOrder + vCode)
			XResultSetValue(vCRS, "DateAndResults", @Str(@ServerDate()) + " " + vResult)
		}
		Else
		{
			// If info not paired, abandon the line with error
			vRet = 1
		}
	}
	Return vRet

END FUNCTION

	// Create an empty child record result set by specifying crtieria that no record will match
	vCRS = @XResultSetSearch(@FN, "Orders!Results", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!OrderNo==")
	If vCRS > -1
	{
		vFile = FileOpen("amor.txt")
		If vFile > -1
		{
			FileSeek(vFile, 0)
			vLen = FileSize(vFile)

			// Read and process results file line by line
			While (FilePos(vFile) < vLen)
			{
				vOrder = ""
				vPatient = ""
				FileReadLn(vFile, vLine)
				If @Len(vLine) > 0
				{
					// Throw away first two values on line
					vVal = Split(vLine, Tab(1))
					vVal = Split(vLine, Tab(1))

					// Get OrderNo from Position 3
					vVal = Split(vLine, Tab(1))
					If @Len(vVal) > 0
					{
						vOrder = vVal

						// Get matching PatientNo and confirm OrderNo exists
						vPatient = @XLookup(@FN, vOrder, "Orders!OrderNo", "PatientNo")
						If @Len(vPatient) > 0
						{
							// Process rest of line into subrecords
							vTemp = ProcessLine()
							If vTemp <> 0
							{
								WriteLn("Error while processing Order: " + vOrder)
							}
						}
						Else
						{
							WriteLn("No matching Order record for: " + vOrder)
						}
					}
				}
			}

			FileClose(vFile)
		}
		Else
		{
			@MsgBox("Error: Failed to open results file.", "", "")
		}
		XResultSetClose(vCRS)
	}
	Else
	{
		@MsgBox("Error: Failed to open child result set.", "", "")
	}

 


  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: importing ASCII file in Subform
Reply #13 - Sep 24th, 2007 at 10:03pm
Print Post Print Post  
Thank you thank you Erika, you've taught me a lot today!

Please send me the App.
my Mail Adress : amor@belhareth.com

Dr. Belhareth
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: [Solved] importing ASCII file in Subform
Reply #14 - Sep 25th, 2007 at 2:54pm
Print Post Print Post  
Amor,

Zip file attached contains the dsr, db and also the text file I used. The startup form has a button. When clicked, the button reads in and processes the text file. You may need to adjust the path to the text file in the SBasic behind the button. Let me know if you need me to explain any of the techniques.
  

amor.zip (Attachment deleted)

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print