简体   繁体   English

AHK:比较两个Txt文件

[英]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". 现在,我的AHK会在整个图表中检查ICD-10代码Z23之类的密钥,然后检查“流感”。 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. 如果找到两者,则将患者的病历号添加到适合年龄的文本文件中,即65岁以上或65岁以下。还有一些带有10个插槽的纸张,我们手工记录了MRN,以进行仔细检查。 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. 我想创建一个脚本来比较三个文件,即混合MRN(65+和<65)的MRN文件,如果在混合文件中找到了MRN,则应删除该行。 (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. 您在flushot.txt中检查“成人”和“高级”同花顺文本文件的关联数组,以查找MRNS,然后,如果找不到,则将它们添加到未开票。 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). 以下是我为扭转这种情况所做的几种尝试,并检查了flushot.txt中成人和老年人中的MRN,如果找不到,请将其添加到一个名为notrecorded.txt的文件中,这样我就知道哪些人有同花顺以及谁没有记录下来(由初级保健提供者记录)。

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 billedAdultFlushots.txt

101
102
103
104

billed65+Flushots.txt billed65 + Flushots.txt

205
206
207
208

flushot.txt BEFORE flushot.txt之前

301
101
103
302
205
301
207
103
303
301

flushot.txt AFTER 之后的flushot.txt

301
302
303

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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