简体   繁体   中英

AHK: Comparing Two Txt Files

So I'm doing billing for a doctors office, and we like to triple check that the flu shots we give are actually billed out. Right now, my AHK checks their entire chart for keys like the ICD-10 Code Z23, then checks for "Influenza". If it finds both of these, it adds the patients Medical Record Number to the age appropriate text file, either 65+ or Under 65. There are also paper sheets with 10 slots we record the MRNs by hand on, to double check. I want to create a script that will compare three files, a file of mixed MRNs (both 65+ and <65), and if the MRN is found in the mixed file, it should remove that line. (I've done a bunch of googling on the subject, but everyone is recommending using a library, something that would only slow down my program.) If the line isn't found, it should be left in the master file for my review. I cannot figure out how to remove lines, let alone a specific line. So far, to check the files against each other, I have this. In lieu of removing lines, I'm appending the unbilled numbers to a fourth text file, but ultimately, removing would be better.

FILENUM = 1
FILENU = 1
^L::
Loop
    {
    FileReadLine, MRN, E:\AHK & AHKS\flushot.txt, %LINENUM%
    If ErrorLevel
        {
        break
        }
    Else
        {
        Loop
            {
            FileReadLine, MRNc, E:\AHK & AHKS\Billed65+Flushots.txt, LINENU
            StringTrimRight, MRNc, 11
            If (MRN != MRNc)
                {
                LINENU++
                Match = 0
                }
            If (MRN == MRNc)
                Match = 1
            If ErrorLevel and Match = 0
                {
                FileAppend, MRN, E:\AHK & AHKS\Unbilledtester.txt
                LINENU = 1
                }
            If (Match = 1)
                GoTo Lab2

            }
        Lab2:
        Loop
            {
            FileReadLine, MRNc, E:\AHK & AHKS\BilledAdultFlushots.txt, LINENU
            StringTrimRight, MRNc, 11
            If (MRN != MRNc)
                {
                LINENU++
                Match = 0
                }
            If (MRN == MRNc)
                Match = 1
            If ErrorLevel and Match = 0
                FileAppend, MRN, E:\AHK & AHKS\Unbilledtester.txt
            If (Match = 1)
                GoTo Lab2

            }
        LINENUM++

        }
    }

UPDATE!!!!!!!

Alright, so I grabbed your code, and I've been trying to run a reverse check. You check the associative arrays of the Adult and Senior flushot text files for the MRNS in flushot.txt, then if not found they're added to unbilled. Below are several of my attempts to reverse that, and check for the MRNs in Adult and Senior in flushot.txt, and if not found, to add it to a file called notrecorded.txt so I know what people got flushots and the MA who didn't record it (by Primary Care Provider).

FlushotsBilled()
{
Root_Dir            := "E:\AHK & AHKS"
fName_Input         := "flushot.txt"
fName_Backup        := "flushot_old.txt"
fName_Output        := "unbilled.txt"
fName_Billed_Adult  := "billedAdultFlushots.txt"
fName_Billed_Senior := "billed65+Flushots.txt"
fName_Billed_NR     := "notrecorded.txt"
fName_Mixed     := "mixrecord.txt"  

SetWorkingDir %Root_Dir%
FileDelete, %fName_Output%

AdultFlu   := {}
SeniorFlu  := {}
GivenFluA  := {}
GivenFluB  := {}
Mixed      := {}

Loop, Read, %fName_Mixed%
    Mixed[A_LoopReadLine] := True   

Loop, Read, %fName_Billed_Adult%
    {
    ;Loop, Parse, A_LoopReadLine, `t
    ;   AdultFlu[A_LoopField] := True
    AdultFlu[A_LoopReadLine] := True
        If !Mixed[A_LoopReadLine]
            FileAppend, %A_LoopReadLine%`n, %fName_Mixed%
    }

Loop, Read, %fName_Billed_Senior%
    {
    ;Loop, Parse, A_LoopReadLine, `t
    ;   SeniorFlu[A_LoopField] := True
    SeniorFlu[A_LoopReadLine] := True
        If !Mixed[A_LoopReadLine]
            FileAppend, %A_LoopReadLine%`n, %fName_Mixed%
    }

Loop, Read, %fName_Input% ;check flushot.txt for
    If !AdultFlu[SubStr(A_LoopReadLine, 1, InStr(A_LoopReadLine,"`t"))] && !SeniorFlu[SubStr(A_LoopReadLine, 1, InStr(A_LoopReadLine,"`t"))]
    ;If !AdultFlu[A_LoopReadLine] && !SeniorFlu[A_LoopReadLine] ;flushot is checking the associated arrays
        FileAppend, %A_LoopReadLine%`n, %fName_Output% ;if not found, stick it into unbilled.

Loop, Read, %fName_Input%
    GivenFluA[A_LoopReadLine] := True



/*  Loop, Read, %fName_Billed_Senior%
    If !Mixed[A_LoopReadLine]
        FileAppend, %A_LoopReadLine%`n, %fName_Mixed%

Loop, Read, %fName_Billed_Adult%
    If !Mixed[A_LoopReadLine]
        FileAppend, %A_LoopReadLine%`n, %fName_Mixed%

Loop, Read, %fName_Mixed%
    Mixed[A_LoopReadLine] := True
*/
Loop, Read, %fName_Mixed%
    If !GivenFluA[SubStr(A_LoopReadLine, 1, InStr(A_LoopReadLine,"`t"))] ;a_Loopreadline is a line in mixed. it is looking through flushot.txt for that line, if it's there, it's givenflua's index
        Loop, Read, %fName_Billed_NR%
            If !GivenFluA[A_LoopReadLine]
                FileAppend, %A_LoopReadLine%`n




/*
Loop, Read, %fName_Input% ;read flushot
    If Mixed[A_LoopReadLine] Contains A_LoopReadLine ;check to see if each line in flushot is in mixed
        GivenFluA[Mixed[A_LoopReadLine]] := True ;Mixed[A_LoopReadLine]

Loop, Read, %fName_Billed_NR%
    If !GivenFluA[A_LoopReadLine]
        FileAppend GivenFluA[%A_LoopReadLine%], %fName_Billed_NR%
*/

;if readline is in mixed, but not in flushot, check to see if it's in notrecorded, if not, append it

/*
Loop, Read, %fName_Mixed% ;open up the mixed record
    IfNotInString, A_LoopReadLine, GivenFluA[A_LoopReadLine] ;see if inside each line, we can find the lines from flushot.txt, if not
        ;GivenFluB[GivenFluA[A_LoopReadLine]] := True ;if not we give the line from inside flushot to another associative array
        GivenFluB[A_LoopReadLine] := True ;lets try this, put the value 

Loop, Read, %fName_Mixed%
    IfInString, A_LoopReadLine, GivenFluA[A_LoopReadLine]
        GivenFluB[A_LoopReadLine]

Loop, Read, %fName_Billed_NR% ;open up not recorded
    IfNotInString, A_LoopReadLine, GivenFluB[A_LoopReadLine] ;see if inside each line we can find that line from
        FileAppend, %A_LoopReadLine%`n, %fName_Billed_NR%
*/
}

I think you were on the right track by creating an output file rather than deleting lines. Text files are usually treated as streams, not fixed-record-length data files. Deleting lines is error prone and not efficient; you'd have to compact the file somehow.

How big are your files? If there are only a few thousand patients, I would just load everything into associative arrays so we can use keyed lookups.

Program

^L:: medical_run()

medical_run()
{
  root_dir            := "E:\AHK & AHKS"
  fname_input         := "flushot.txt"
  fname_backup        := "flushot_old.txt"
  fname_temp_output   := "Unbilledtester.txt"
  fname_billed_adult  := "billedAdultFlushots.txt"
  fname_billed_senior := "billed65+Flushots.txt"

  SetWorkingDir %root_dir%
  FileDelete %fname_output%

  adults    := {}
  seniors   := {}
  unmatched := {}

  loop READ, %fname_billed_adult%
    adults[A_LoopReadLine] := true

  loop READ, %fname_billed_senior%
    seniors[A_LoopReadLine] := true

  loop READ, %fname_input%
    if !adults[A_LoopReadLine] && !seniors[A_LoopReadLine]
      unmatched[A_LoopReadLine] := true

  for code,dummy in unmatched
    FileAppend %code%`n, %fname_output%

  FileMove %fname_input%, %fname_backup%
  FileMove %fname_temp_output%, %fname_input%
}

billedAdultFlushots.txt

101
102
103
104

billed65+Flushots.txt

205
206
207
208

flushot.txt BEFORE

301
101
103
302
205
301
207
103
303
301

flushot.txt AFTER

301
302
303

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM