home *** CD-ROM | disk | FTP | other *** search
- **
- ** PROGRAM TITLE : TFORMXYZ
- **
- ** WRITTEN BY : Paul Long
- **
- ** WRITTEN FOR : Copyright (C) 1992 All rights reserved. XL Systems, Inc.
- **
- ** PROGRAM INTENT: Converts XYZ company's DSHS forms data
- ** to GHOST data and adds it to the SERVICE.DBF file.
- ** Name of forms input file is expected on command line.
- **
- ** NOTE: This file uses "traditional," non-OOP programming.
- **
- #include "fileio.ch"
- #include "inkey.ch"
-
- // Name of DBF that receives converted form data
- #define OUTDBFNAME "service"
-
-
- local nHandle, nFormEntries
-
- parameter cInputFile // Name of input file to convert
-
- // Initialize variables to a known state
- public cLastName := "", cFirstName := "", cMiddleInitial := "", ;
- cAcctNo := "", cExamNo := "", cPIC := "", cSSN := "", ;
- dDOB := ctod(" / / "), adDOS := {}, ;
- lFormFound := .t., ;
- lDOSFileFound := .t.
-
- if (nHandle := DOSFileNew(cInputFile)) != F_ERROR
-
- // Convert and add service entries to DBF
- nFormEntries := FormAdd2DBF(nHandle, OUTDBFNAME)
-
- ?? ltrim(str(nFormEntries)) + ;
- " entries were added to " + OUTDBFNAME + ".dbf"
-
- fclose(nHandle)
-
- endif
-
-
- *******************************************************
- *
- * FormSkip
- *
- *******************************************************
- * Skip to next form.
- *
- function FormSkip(nHandle)
-
- memvar lFormFound, lDOSFileFound
-
- // Each form has "DSHS-OFFICE" at the top
- DOSFileLocate(nHandle, "DSHS-OFFICE")
- if lFormFound := lDOSFileFound
- FormRead(nHandle)
- endif
-
- return lFormFound
-
-
- *******************************************************
- *
- * FormRead
- *
- *******************************************************
- * Read the next form from the input file, saving pertinent data for latter
- * output by Write().
- *
- function FormRead(nHandle)
-
- memvar cLastName, cFirstName, cMiddleInitial, cAcctNo, cExamNo, cPIC, cSSN, ;
- dDOB, adDOS
-
- local n, cRecord
-
- cRecord := DOSFileSkip(nHandle, 9) // Skip down to name line
- cLastName := substr(cRecord, 4, 15)
- cFirstName := substr(cRecord, 19, 13)
- cMiddleInitial := substr(cRecord, 32, 1)
- dDOB := ctod(substr(cRecord, 43, 8))
-
- cRecord := DOSFileSkip(nHandle, 3) // Skip down to PIC line
- cPIC := substr(cRecord, 56, 14)
-
- cRecord := DOSFileSkip(nHandle, 31) // Skip down to first service line
- adDOS := {} // Clear array from previous form
- for n = 1 to 6 // Maximum of 6 services per form
- if empty(substr(cRecord, 3, 6)) // If no more service, exit loop
- exit
- endif
- // Reformat and convert date of service, then add to date-of-service array
- aadd(adDOS, ctod(substr(cRecord, 3, 2) + "/" + ;
- substr(cRecord, 5, 2) + "/" + substr(cRecord, 7, 2)))
- cRecord := DOSFileSkip(nHandle, 2) // (Double spaced)
- next
-
- // Skip down to account-number line
- cRecord := DOSFileSkip(nHandle, 20 - (2 * n))
- // (We can only hold the last 9 of the 10 account-number characters)
- cAcctNo := substr(cRecord, 5, 9)
-
- return nil
-
-
- *******************************************************
- *
- * FormAdd2DBF
- *
- *******************************************************
- * Convert forms data to GHOST data and add to DBF
- *
- function FormAdd2DBF(nHandle, cDBF)
-
- local nFormEntries := 0
-
- memvar cLastName
-
- if file(cDBF + ".dbf") // Make sure output .DBF exists
- use (cDBF) exclusive new
- if neterr()
- ?? "*** ERROR *** " + cDBF + ".dbf cannot be opened"
- else
- do while FormSkip(nHandle) // Read each form
- FormWrite(cDBF) // Write data for this form
- ?? ++nFormEntries, cLastName, chr(K_RETURN) // Tell user progess
- enddo
- (cDBF)->(dbclosearea())
- endif
- else
- ?? "*** ERROR *** " + cDBF + ".dbf file is missing"
- endif
-
- return nFormEntries
-
-
- *******************************************************
- *
- * FormWrite
- *
- *******************************************************
- * Write service information from the current form.
- *
- function FormWrite(cDBF)
-
- memvar cLastName, cFirstName, cMiddleInitial, cAcctNo, cExamNo, cPIC, cSSN, ;
- dDOB, adDOS
-
- // Add n records to DBF
- aeval(adDOS, { | dDOS | ;
- (cDBF)->(dbappend()), ;
- (cDBF)->acctno := cAcctNo, ;
- (cDBF)->examno := cExamNo, ;
- (cDBF)->svcdate := dDOS, ;
- (cDBF)->ssn := cSSN, ;
- (cDBF)->pic := cPIC, ;
- (cDBF)->firstname := cFirstName, ;
- (cDBF)->midinitial := cMiddleInitial, ;
- (cDBF)->lastname := cLastName, ;
- (cDBF)->birthdate := dDOB ;
- })
-
- return nil
-
-
- *******************************************************
- *
- * DOSFileNew
- *
- *******************************************************
- * Construct DOSFile object mainly by opening input file
- *
- function DOSFileNew(cFileName)
-
- local nHandle := F_ERROR
-
- if cFileName == nil
- ?? "*** ERROR *** missing file name"
- else
- if (nHandle := fopen(cFileName, FO_READ)) == F_ERROR
- ?? "*** ERROR *** " + cFileName + " cannot be opened"
- endif
- endif
-
- return nHandle
-
-
- *******************************************************
- *
- * DOSFileSkip
- *
- *******************************************************
- * Skip forward through file and read the last, nth record.
- * Currently, non-positive skips are treated like DOSFileSkip(1).
- * This should probably be changed to accomodate non-positive
- * skips.
- *
- function DOSFileSkip(nHandle, nRecords)
-
- local n
-
- memvar lDOSFileFound
-
- // If nil argument, treat like Skip(1)
- nRecords := if(nRecords == nil, 0, nRecords - 1)
- lDOSFileFound := .t.
-
- for n = 1 to nRecords
- if !(lDOSFileFound := fadvance(nHandle) != F_ERROR)
- exit
- endif
- next
-
- // Read and return nth record if skip succeeded; otherwise, return null string
- return if(lDOSFileFound, freadline(nHandle), "")
-
-
- *******************************************************
- *
- * DOSFileLocate
- *
- *******************************************************
- * Search for string in file. If found, the entire record is read in, and
- * file pointer is moved to beginning of next record; otherwise, null string
- * is returned.
- *
- function DOSFileLocate(nHandle, cString)
-
- memvar lDOSFileFound
-
- if lDOSFileFound := flocate(nHandle, cString) >= 0
- fbol(nHandle)
- endif
-
- return if(lDOSFileFound, freadline(nHandle), "")
-