Jump to content

Recommended Posts

Posted (edited)
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <file.au3>
#include <InetConstants.au3>
#include <WinAPIFiles.au3>
#include <Date.au3>
#include <DateTimeConstants.au3>

;Global variable;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;REPLACEDROOTURL//PDFTK//PDFViewer.php?filename=db1208020249merged192149172328.pdf
;pdf url REPLACEDROOTURL//PDFTK//PDFViewer.php?filename=db1208020249merged1266445012.pdf
global $main=0
global $db = ?????; DOnt forget to set default control db value
global $inipath = @scriptdir&"\settings.ini"
global $oURL = "REPLACEDROOTURL/application/vorder_add.php?key="
global $pURL = "REPLACEDROOTURL/application/poc_add.php?key="
global $edit = 0
global $cOrder = 0 ;54220   ;;;;;;current order number
global $dirFile = @scriptdir&'\ordertasklist'&stringreplace(_nowdate(),"/","")&'.csv'
global $gdtype = 1   ;;;1 for order  2 for poc
global $end = 0
global $oIE = 0
global $username = 0
global $password = 0

;_IEErrorHandlerRegister()

;interface init;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


$main=guicreate("Order Tool",210,185,0,0,-1,$WS_EX_TOPMOST)
;WinSetTrans($main, "", 170)
;$main=guicreate("Order Buddy",195,70,@desktopwidth-220,20,-1,$WS_EX_TOPMOST)
guisetstate(@SW_SHOW)
Opt("GUIOnEventMode", 1)
guisetonevent($GUI_EVENT_CLOSE,"quit")
global $uField = guictrlcreateinput('Username',5,5,200,20)
global $pField = guictrlcreateinput('Password',5,30,200,20,0x0020)
global $dbField = guictrlcreateinput('??????',5,55,200,20)
global $tRadio1 = guictrlcreateradio('Orders',5,80)
GUICtrlSetState($tRadio1, $GUI_CHECKED)
global $tRadio2 = guictrlcreateradio('Plans of Care',80,80)
global $max = guictrlcreateinput('Start (max)',5,105,80,20)
global $min = guictrlcreateinput('End (min)',125,105,80,20)
guictrlcreatelabel("-->",100,105)
global $gButton = guictrlcreatebutton('Start',50,130,100,30)
global $sLabel =guictrlcreatelabel("Status:Idle",5,165,200,20)
guictrlsetonevent($gButton,"start")
while 1
   sleep(100)
WEnd


func start()
$oIE = _IECreate("REPLACEDROOTURL")
 $db = guictrlread($dbField)
 $username = guictrlread($uField)
 $password = guictrlread($pField)
 $cOrder = guictrlread($max)
 $end = guictrlread($min)
if guictrlread($tRadio1) = 1 Then
   $gdtype = 1
Else
   $gdtype = 2
   endif
_login()
if $gdtype = 2 Then
    $dirFile = @scriptdir&'\poctasklist'&stringreplace(_nowdate(),"/","")&'.csv'
    filewriteline($dirFile,'Doc ID, Patient MR, POC Number, Task')
 Else
    $dirFile = @scriptdir&'\ordertasklist'&stringreplace(_nowdate(),"/","")&'.csv'
    filewriteline($dirFile,'Doc ID,Patient MR, Order Number, Task')
    endif
While $cOrder > $end - 1
    guictrlsetdata($sLabel,"Status: working on order " & $cOrder)
_goToOrder($cOrder,$gdtype)
_decide ($cOrder,$gdtype)
$cOrder = $cOrder - 1
wend
guictrlsetdata($sLabel,"Idle")
_IEQuit($oIE)
endfunc


func _download ($location,$pName,$onumber)
_IENAvigate($Oie,$location)
sleep(100)
;_IEPropertyGet ( $oIE, "hwnd" )
winactivate(_IEPropertyGet ( $oIE, "hwnd" ))
;sleep(300)
send("^S")
sleep(300)
send(@scriptdir&"\"&$pname&"\"&$onumber)

    endfunc


;functions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;???? login function
func _login ()
Local $oForm = _IEFormGetObjByName($oIE, "loginForm")
Local $oText = _IEFormElementGetObjByName($oForm, "USERNAME")
_IEFormElementSetValue($oText, $username)
$oText = _IEFormElementGetObjByName($oForm, "PASSWORD")
;_IEFormElementSetValue($oText, iniread($inipath,"Login","p",1))
_IEFormElementSetValue($oText, $password)
local $element = _IEFormElementGetObjByName($oForm, "sign-in")
_IEAction($element,"click")
sleep(1000)
_ieloadwait($oIE)
endfunc

func quit ()
  ; local $buddyLoc = WinGetPos($main)
   ;iniwrite($path,"settings","buddyx",$buddyLoc[0])
  ; iniwrite($path,"settings","buddyy",$buddyLoc[1])
   _IEQuit($oIE)
   Exit
endfunc

;function that navigates to new order
func _goToOrder ($idIn, $dtype)
    local $tURL = $oURL
    if $dtype = 2 Then
        $tURL = $pURL
        endif

_ienavigate($oIE,$tURL&$idIn)
if @error Then
    _goToOrder($idIn, $dtype)
EndIf
endfunc

;logic function decides what to do with each order
Func _decide ($dOrder,$dtype)


Local $oForm = _IEFormGetObjByName($oIE, "add")
local $type = _IEFormElementGetObjByName($oForm,"table_xyz")
local $status = _IEFormElementGetObjByName($oForm,"status")
if $dtype = 1 then
local $effective = _IEFormElementGetObjByName($oForm,"dateeff")
else
local $effective = _IEFormElementGetObjByName($oForm,"datevosoc")
    endif
if $dtype = 2 then
local $docid = _IEFormElementGetObjByName($oForm,"pupin")
else
   sleep(200)
   local $docid=_IEFormElementGetCollection($oForm,117)
   if $docid.value = "" Then
      $docid=_IEFormElementGetCollection($oForm,118)
      endif
endif
local $ptid = _IEFormElementGetObjByName($oForm,"ptid")
local $ptid2 = _IEFormElementGetObjByName($oForm,"ptid_xyz")
local $sent = _IEFormElementGetObjByName($oForm,"datesent")
local $sent2 = _IEFormElementGetObjByName($oForm,"datesent2")
local $sent3 = _IEFormElementGetObjByName($oForm,"datesent3")
local $sent4 = _IEFormElementGetObjByName($oForm,"datesent4")
;;;;pt attribute value testing


;;;;;;;
if $status.value = "READY TO SEND" Then
;msgbox(0,"Decision","Order is ready to send")
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',was sent')
_eFax($dtype)
_sendDate ($dOrder, $dtype,1)
elseif $status.value = "UNCONFIRMED" Then
;filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',Is not ready to be sent')
elseif $status.value = "CONFIRMED" Then
;filewriteline($dirFile,'Order ' & $dOrder &' already confirmed')
elseif $status.value = "VOID" Then
;filewriteline($dirFile,'Order ' & $dOrder &' Order Void')
elseif  _dateD ($effective.value,30) = 1 then
    if _oCheck ($dOrder, $ptid.value) = 0 Then ;check if order is in e records
;msgbox(0,"Decision","effective date over 30 days and order not in e records")
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',over 30 days old not in erecords needs checking')
    Else ;if order present in e records
;msgbox(0,"Decision","effective date over 30 days and order found in e records")
_sendDate ($dOrder, $dtype,0)
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',was found in e records and confirmed')
        endif
    ;if effective date is over 30 days old
elseif $sent.value <> "" and $sent2.value = "" and _dateD ($sent.value,6) = 1 Then
;msgbox(0,"Decision","Order has been sent once before and needs to be sent again")
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&' ,was resent')
_eFax($dtype)
_sendDate ($dOrder, $dtype,2)
    ;send if only one sent date which is over 7 days
elseif $sent2.value <> "" and $sent3.value = "" and _dateD ($sent2.value,6) = 1 Then
    ;if sent and resent2 date arent blank and resent2 date is more than 7 days
        if _oCheck ($dOrder, $ptid.value) = 0 Then ;check if order is in e records
;msgbox(0,"Decision","Order has been sent twice before and is not in e records")
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',not in e records and was NOT resent needs follow up call')
;_eFax($dtype)
_sendDate ($dOrder, $dtype,3)

    Else ;if order present in e records
;msgbox(0,"Decision","Order has been sent twice before and is found in e records")
_sendDate ($dOrder, $dtype,0)
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',was found in e records and confirmed')
        endif
elseif $sent3.value <> "" and $sent4.value = ""  Then
    ;3rd rsend not blank and over 30 days
        if _oCheck ($dOrder, $ptid.value) = 0 Then ;check if order is in e records
;msgbox(0,"Decision","Order has been sent thrice before and is not in e records")
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',has been sent 3 times needs checking')
    Else ;if order present in e records
;msgbox(0,"Decision","Order has been sent thrice before and is found in e records")
_sendDate ($dOrder, $dtype,0)
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',was found in e records and confirmed')
        endif
elseif $sent4.value <> ""  then
    ;4rd rsend not blank and over 30 days
        if _oCheck ($dOrder, $ptid.value) = 0 Then ;check if order is in e records
;msgbox(0,"Decision","Order has been sent four times and is not in e records")
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',has been sent 4 times needs checking')
    Else ;if order present in e records
;msgbox(0,"Decision","Order has been sent four times and is found in e records")
_sendDate ($dOrder, $dtype,0)
filewriteline($dirFile,$docid.value&','&$ptid.value&','&$dOrder&',was found in e records and confirmed')
    endif
    else
    ;msgbox(0,"Decision","no action taken")
    ;filewriteline($dirFile,'Order ' & $dOrder &' doesnt require any action')
    endif
    EndFunc

;send e fax through ????? interface
Func _eFax($dType2)
Local $oForm = _IEFormGetObjByName($oIE, "add")
local $coll = _ieformelementgetcollection($oForm,1)
;msgbox(0,"test",$coll.value)
_IEAction($coll,"click")
local $loop=1
local $handle
while $loop = 1
    if winexists('PDF CREATOR - Internet Explorer') Then
        $handle=wingethandle('PDF CREATOR - Internet Explorer')
        $loop=0
    EndIf
    sleep(100)
    wend
$faxWindow=_IEattach($handle,"hwnd")
sleep(100)
_IELoadwait($faxWindow)
if $dType2 = 1 then
_IENavigate($faxWindow,'REPLACEDROOTURL//PDFTK//hts_app/?faxto=&faxnum=#/faxingSend?file=db' & $db &_pdfName($faxWindow)&'&key='&$cOrder&'&type=vorder')
else
_IENavigate($faxWindow,'REPLACEDROOTURL//PDFTK//hts_app/?faxto=&faxnum=#/faxingSend?file=db' & $db &_pdfName($faxWindow)&'&key='&$cOrder&'&type=poc')
endif
_IELoadwait($faxWindow)

while $loop = 0
    if winexists('FAXING SEND | ????? - Internet Explorer') Then
        $handle=wingethandle('FAXING SEND | ??????? - Internet Explorer')
        $faxWindow=_IEattach($handle,"hwnd")
        $loop=1
        sleep(500)
    EndIf
    sleep(100)
    wend
    $oFP = _IEFormGetCollection($faxWindow, 0)
    sleep(100)
    local $sDoctor = _ieformelementgetcollection($oFP,2)
    if $sDoctor.value = 'REPLACED DOC NAME' then;;Exclusion List
        filewriteline($dirFile,'Disregard the previous line, doctor is on exclusion list. Fax was not sent but follow up if needed')
        _IEQuit($faxWindow)
        return 0
        endif
    local $sAccount = _ieformelementgetcollection($oFP,0)
    _IEFormElementOptionSelect($sAccount, 1, 1, "byIndex")
    _IEAction($sAccount,"focus")
    sleep(100)
    send("{down}")   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;fax account select
    sleep(100)
;local $sFax = _ieformelementgetcollection($oFP,3)
    ;_IEAction($sFax,"focus")
    ;send("phone number")
    local $sButton = _ieformelementgetcollection($oFP,6)
    sleep(100)
_IEAction($sButton,"click")
sleep(5000)
_IEQuit($faxWindow)
EndFunc

;;; pulls pdf file name from ht window containing pdf
Func _pdfName ($windowIN)
    local $HTML = _IEBodyReadHTML($windowIN)
local $start = stringinstr($HTML,"merged")
local $end = stringinstr($HTML,".pdf&fax")
local $file = stringmid($HTML,$start,$end + 4 - $start)
return $file
endfunc


;;;;;function that returns 1 if current date is x more daya than $difIN
func _dateD ($dIN,$difIN)
local $fDate = stringmid($dIN,7,4)&'/'&stringmid($dIN,1,2)&'/'&stringmid($dIN,4,2)
local $pDate = stringSplit(_nowDate(),'/')
local $nDate = $pDate[3] & "/" & $pDate[1] & "/" & $pDate[2]
    if $difIN < _datediff("D",$fDate,$nDate) Then
        return 1
    else
        return 0
     endif
    endfunc

;;;;;function to check if order is in erecords returns loc if present returns 0 if not

func _oCheck ($oIN, $ptIn)
    local $checkWindow = _iecreate("REPLACEDROOTURL/application/patient_add.php?key="&$ptIn & "#e_recordsTab")
    local $oHTML = _iebodyreadhtml($checkWindow)
    ;msgbox(0, "testing "&$oIn,"ORDER "&$oIN)
    _ieQuit($checkWindow)
    return stringinstr($oHTML,"ORDER "&$oIN)
endfunc

func _sendDate ($idIN, $dtype,$sField)  ;order number in, poc or order, field to mark
    _goToOrder($idIn, $dtype)
Local $oForm = _IEFormGetObjByName($oIE, "add")
    if $sfield = 1 Then
    local $sent = _IEFormElementGetObjByName($oForm,"datesent")
    _IEformelementsetvalue($sent,_nowdate())
    local $option = _IEFormElementGetObjByName($oForm,"status")
    if $dtype = 1 then
    _IEFormElementOptionselect($option,4,1,"byIndex")
    Else
        _IEFormElementOptionselect($option,2,1,"byIndex")
    endif
    ElseIf $sfield = 2 Then
        local $sent = _IEFormElementGetObjByName($oForm,"datesent2")
        _IEformelementsetvalue($sent,_nowdate())
    ElseIf $sfield = 3 Then
        local $sent = _IEFormElementGetObjByName($oForm,"datesent3")
        _IEformelementsetvalue($sent,_nowdate())
    ElseIf $sfield = 4 Then
        local $sent = _IEFormElementGetObjByName($oForm,"datesent4")
        _IEformelementsetvalue($sent,_nowdate())
    ElseIf $sfield = 0 Then ;only sets status to confirmed
        local $option = _IEFormElementGetObjByName($oForm,"status")
    if $dtype = 1 then
    _IEFormElementOptionselect($option,6,1,"byIndex")
    Else
        _IEFormElementOptionselect($option,4,1,"byIndex")
    endif
    endif
    local $submit = _IEFormElementGetObjByName($oForm,"submit_xyz")
    sleep(1000)
    _IEAction($submit,"click")
    sleep(1000)
     _validate()
     _ieloadwait($oIE)
endfunc

func _validate()
local $vWidnow
sleep(1000)
if winexists('VALIDATING - Internet Explorer') Then
        $handle=wingethandle('VALIDATING - Internet Explorer')
        $vWindow=_IEattach($handle,"hwnd")
;;;;;
    local $oInputs = _IETagNameGetCollection($vWindow, "input")
 For $oInput In $oInputs
    if stringinstr($oInput.value , "SUBMIT" ) <> 0 Then
      $submitbtn = $oInput
      endif
   Next
_IEAction ($submitbtn, "click")
 sleep(2000)
;;;;;
EndIf

    endfunc

 

Edited by ComradVlad
Posted
  On 5/24/2018 at 8:24 PM, junkew said:

What happens when you restart the computers? Could itbe you have dozens of ie processes running. Maybe specific addins are loaded. Can you manually browse to the url you want.

Expand  

Restarting computers doesn't work, once the program starts failing it doesn't stop and always fails as soon as it hits the _goToOrder function. I can Manually go to the url just fine.

 

Posted the code with identifying info removed up top.

Posted

Do you have #requireadmin ? If not - put it and test if it works. Does the failing PC/Logged users have admin rights?

Posted
  On 5/28/2018 at 7:00 AM, Juvigy said:

Do you have #requireadmin ? If not - put it and test if it works. Does the failing PC/Logged users have admin rights?

Expand  

All users are admins, I tried #requireadmin and the program exits with 0 exit code instead of throwing ie navigate error. 

Posted
  On 5/24/2018 at 4:26 PM, ComradVlad said:

ill give it a try

Expand  

Did you try Au3.3.12.0 ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 6/1/2018 at 8:18 AM, mLipok said:

Did you try Au3.3.12.0 ?

 

Expand  

yup same deal:

 

"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (272) : ==> The requested action with this object has failed.:
$oObject.navigate($sUrl)
$oObject^ ERROR

Posted

Put an error handler to see what exactly is going on.  Instead of using the UDF, try the navigate method directly:

For example like this:

$oIE = _IECreate("abv.bg")
_IELoadWait($oIE)
$oIE2 = $oIE.navigate2("dir.bg")

 

  • 10 months later...
Posted

Resurrecting this old thread in case someone else is looking for the answer.  The issue was that windows defender blocked a portion of the program, specifically the IE navigate function. It only did this on some computers. Not sure why. Disabling protection for IExplore gets rid of this issue. There was nothing wrong with the code.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...