---
# System prepended metadata

title: punch

---

# punch
```vb=
Sub punch(row As Integer, isIn As Boolean)
'Sub punch()
'    isIn = False
'    row = 2
    On Error GoTo ErrorHandler
    Dim html As HTMLDocument
    username = Start.Range("A" & row).Value
    password = Start.Range("B" & row).Value
    URL = "https://staff.kfsyscc.org/punch/"

    Randomize
    Dim temperature$
    temperature = 36 + Round(Rnd, 1)
    
    Application.StatusBar = "Start Login Process"
    With edge
        Application.StatusBar = "Edge Driver was set to Headless"
        .SetCapability "ms:edgeOptions", "{" & """args"":[""headless""]" & "}"
        Application.StatusBar = "Launching Edge Web driver in headless mode....it might take a few seconds, be patient"
        .Start
        Application.StatusBar = "Loading login page..."
        .Get URL
        x = Now + 5 '<== capture current time and plus 5 second
        Do Until edge.FindElementsById("username").Count > 0 Or Now > x
            DoEvents
        Loop
        'Here, how to handle if there's no connection?
        If Not isIn Then .FindElementByXpath("//*[@id='full-width-tab-1']/span/h5").Click
        Application.Wait (Now + TimeValue("0:00:01"))
        Application.StatusBar = "Fill in username and password..."
        .FindElementById("username").SendKeys (username)
        .FindElementById("outlined-adornment-password").SendKeys (password)
        Application.StatusBar = "Click Login"
        If isIn Then
            .FindElementByXpath("//*[@id='full-width-tabpanel-0']/div/span/main/div[1]/form/button/span[1]").Click
            Application.StatusBar = "Clicked"
        Else
            .FindElementByXpath("//*[@id='full-width-tabpanel-1']/div/span/main/div[1]/form/button/span[1]").Click
            Application.StatusBar = "Clicked"
        End If
    End With
    x = Now + 5
    Do Until Not edge.FindElementByXpath("//*[@id='outlined-adornment-weight']") Is Nothing Or Now > x
    DoEvents
    Loop
    Application.StatusBar = "Fill in temperature"
    edge.FindElementById("outlined-adornment-weight").SendKeys (temperature)
    edge.FindElementByXpath("/html/body/div[3]/div[3]/div/div[2]/div[2]/div[1]/button[1]").Click
    edge.FindElementByXpath("/html/body/div[3]/div[3]/div/div[2]/div[2]/div[2]/button[1]").Click
    edge.FindElementByXpath("/html/body/div[3]/div[3]/div/div[2]/div[2]/div[3]/button[1]").Click
    edge.FindElementByXpath("/html/body/div[3]/div[3]/div/div[2]/div[2]/div[4]/button[1]").Click
    edge.FindElementByXpath("/html/body/div[3]/div[3]/div/div[3]/button").Click
    Application.Wait (Now + TimeValue("0:00:02"))
    Set dlg = edge.SwitchToAlert()
    txt = dlg.Text
    dlg.accept
    edge.FindElementByXpath("/html/body/div[2]/div[3]/div/div[3]/button").Click
ErrorHandler: ' 錯誤處理用的程式碼
    Application.StatusBar = "Reloaded"
End Sub
```

# 2022/06
```vb=
Dim has_w_done as boolean 
Dim has_d_done as boolean 
Dim has_e_done as boolean 
Dim has_p_done as boolean 
Dim has_a_done as boolean 
Dim has_o_done as boolean 

sub set_done_false()
    has_w_done = False 
    has_d_done = False 
    has_e_done = False 
    has_p_done = False 
    has_a_done = False 
    has_o_done = False 
end sub 
' check if is done
Sub batch_w()
    if has_w_done then exit sub
    batch("w")
    has_w_done=True
End Sub 
        
Sub AllAuto()
            Application.onTime 7:15 set_done_false()
            'call next cycle'
            ' call clear
            'call following 6'
            'schedule time'
            ' don the inside '
            ' set done'
End Sub
```
## Framework
* schedule
* scrapy
* public variable
* batch process


## 06/20
```vim
set nocompatible
filetype off

set hidden          " opening new file hides current instead of closing
set nowrap          " switch off line wrapping
set tabstop=4       " Set tabs to 4 characaters wide
set shiftwidth=4    " Set indentation width to match tab
set expandtab       " Use spaces instead of actual hard tabs
set softtabstop=4   " Set the soft tab to match the hard tab width
set backspace=indent,eol,start  " Make bs work across line breaks etc
set autoindent      " Enable basic auto indentation
set copyindent      " Preserve manual indentation
set number
set shiftround
set showmatch
set ignorecase
set smartcase
set smarttab
set hlsearch
set incsearch
set history=1000
set undolevels=1000
set wildmenu
set wildcharm=<Tab>	" Needed to open the wildmenu from shortcuts
set clipboard=unnamed	" Use system clipboard, bonus copy/paste between local & SSH
set wildignore=*.swp,*.bak,*.pyc,*.class,*.o
set title
set ruler
set novisualbell
set noerrorbells
set lazyredraw
set laststatus=2
set cursorline
" set colorcolumn=85
set background=dark
set encoding=utf-8
set guifont=Consolas:h14:cANSI

" netrw file browser settings
let g:netrw_banner=0		" Hide the directory banner
let g:netrw_liststyle=3		" 0=thin; 1=long; 2=wide; 3=tree

filetype plugin indent on
syntax on
colorscheme koehler

" Map Ctrl+[hjkl] to navigate windows vim style
nnoremap <silent> <C-h> <C-w>h
nnoremap <silent> <C-j> <C-w>j
nnoremap <silent> <C-k> <C-w>k
nnoremap <silent> <C-l> <C-w>l

" Map Ctrl+[arrow] to navigate windows`
nnoremap <silent> <C-Left> <C-w>h
nnoremap <silent> <C-Down> <C-w>j
nnoremap <silent> <C-Up> <C-w>k
nnoremap <silent> <C-Right> <C-w>l

" Increase/descrease window split size
if bufwinnr(1)
	map + <C-W>+
	map - <C-W>-
endif

" Pageup/down will scroll half-page and center the current line on the screen
nnoremap <silent> <PageUp> <C-U>zz
vnoremap <silent> <PageUp> <C-U>zz
inoremap <silent> <PageUp> <C-O><C-U><C-O>zz

nnoremap <silent> <PageDown> <C-D>zz
vnoremap <silent> <PageDown> <C-D>zz
inoremap <silent> <PageDown> <C-O><C-D><C-O>zz

" F1 netrw file browser
" nnoremap <silent> <F1> :Explore<CR>

" F2 to toggle paste mode
nnoremap <silent> <F2> :set paste!<CR>

" F3 to remove all trailing whitespace
nnoremap <silent> <F3> :let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>

let mapleader=","

" Open netrw filebrowser in current window, with current file selected
nmap <leader>e :e .<CR>

" Rotate windows
nmap <leader>r <C-w>r

" Quick save the current file
nmap <leader>w :w<CR>

" Insert empty line below
nmap <silent> <leader><CR> o<ESC>

" Clear search highlights
nmap <silent> <leader><space> :noh<CR>

" Close buffer without affecting splits
nmap <leader>d :bprevious<CR>:bdelete #<CR>

" Easy buffer navigation
nmap <leader>n :bn<CR>
nmap <leader>p :bp<CR>
nmap <leader>b :buffer <Tab>

" Load vimrc
nmap <leader>v :e ~/.vimrc<CR>

" Toggle/cycle line number modes
nmap <leader>l :call CycleLineNumbers()<CR>

function! CycleLineNumbers()
  if (&number == 1 && &relativenumber == 0)
    set relativenumber
  else
    if (&relativenumber == 1 && &number == 1)
        set norelativenumber
        set nonumber
    else
        set number
        set norelativenumber
    endif
  endif
endfunc
```

## 06/07
- [ ] 解析如何串接Google Sheet試算表寫入爬取的資料


## 06/06


```
https://ing.kfsyscc.org/ord-api/service

POST

{
  "api": "restfulApi",
  "method": "PUT",
  "tableName": "ORDPHRM",
  "queryItem": {
    "CONTENTS": "hypertension"
  },
  "uniqKey": {
    "PHR_CODE": "HTN",
    "DOC_NO": "004506"
  },
  "database": "production"
}

```

## 06/05

```vb=
Sub punch(row As Integer, isIn As Boolean)
'Sub punch()
'    isIn = True
'    row = 2
    On Error GoTo ErrorHandler
    Dim html As HTMLDocument
    username = Start.Range("A" & row).Value
    password = Start.Range("B" & row).Value
    URL = "https://staff.kfsyscc.org/punch/"

    
    Randomize
    Dim temperature$
    temperature = 36 + Round(Rnd, 1)
    
    Application.StatusBar = "Start Login Process"
    With edge
        Application.StatusBar = "Edge Driver was set to Headless"
        .SetCapability "ms:edgeOptions", "{" & """args"":[""headless""]" & "}"
        Application.StatusBar = "Launching Edge Web driver in headless mode....it might take a few seconds, be patient"
        .Start
        Application.StatusBar = "Loading login page..."
        .Get URL
        x = timer() + 5 '<== capture current time and plus 5 second
        Do Until edge.FindElementsById("username").Count > 0 Or timer() > x
            DoEvents
        Loop
        'Here, how to handle if there's no connection?
        If Not isIn Then .FindElementByXpath("//*[@id='full-width-tab-1']/span/h5").Click
        Application.Wait (Now + TimeValue("0:00:01"))
        Application.StatusBar = "Fill in username and password..."
        .FindElementById("username").SendKeys (username)
        .FindElementById("outlined-adornment-password").SendKeys (password)
        Application.StatusBar = "Click Log in"
        .FindElementByXpath("//*[@id='full-width-tabpanel-0']/div/span/main/div[1]/form/button/span[1]").Click
    End With
    'Timeout
    x = timer() + 5
    Do Until Not edge.FindElementByXpath("//*[@id='outlined-adornment-weight']") Is Nothing Or timer() > x
    DoEvents
    Loop
    edge.FindElementById("outlined-adornment-weight").SendKeys (temperature)
    Stop
    edge.FindElementByXpath("/html/body/div[3]/div[3]/div/div[3]/button[1]/span[1]").Click
    Stop
    edge.SwitchToAlert().accept
    edge.FindElementByXpath("/html/body/div[2]/div[3]/div/div[3]/button").Click
ErrorHandler: ' 錯誤處理用的程式碼
    edge.Get URL
End Sub
```

# 2022/05

```vb=
Sub excuteFirstAndLast()
    Dim rowNumEnd As Long
    rowNumEnd = Cells(Rows.Count, 1).End(xlUp).row
    For i = 2 To rowNumEnd
        Call FirstAndLast(i)
    Next
End Sub

Sub FirstAndLast(row As Long)
    Dim i As Long
    Dim values As Range
    Dim dates As Range
    Set values = Range("A" & row & ":" & "D" & row)
    Set dates = Range("E" & row & ":" & "H" & row)
    For i = 1 To values.Cells.Count
        If Not values.Item(i).Value = "x" And Not values.Item(i).Value = 8 Then
           Application.ActiveSheet.Range("I" & row).Value = values.Item(i).Value
           Application.ActiveSheet.Range("J" & row).Value = dates.Item(i).Value
            Exit For
        End If
    Next i
    For i = values.Cells.Count To 1 Step -1
        If Not values.Item(i).Value = "x" And Not values.Item(i).Value = 8 Then
            Application.ActiveSheet.Range("K" & row).Value = values.Item(i).Value
            Application.ActiveSheet.Range("L" & row).Value = dates.Item(i).Value
            Exit For
        End If
    Next i
End Sub

```

![](https://i.imgur.com/BAmJZ0O.png)


## Freature: 數據整理機器人
- [ ] Get IO data
    - [ ] How to arrange the IO card

- [ ] When cell select then active marcro
```vb=
Private Sub Worksheet_SelectionChange(ByVal Target As range)
    If Selection.Count = 1 Then
        If Not Intersect(Target, range("C2")) Is Nothing Then
            MsgBox "Hi there"
        End If
    End If
End Sub
```
- [ ] 處理登入後沒有病人被視為末登入的問題
    - [ ] 改成判斷title是病歷系統
    - [ ] if 有成功登入但病人是0的狀況

## Feature:自動產生交班單

regex101: build, test, and debug regex

- [ ] ### Active and Inactive
    - [ ] Write the function
    - [ ] Find the progress note URL
    - [ ] Find the Xpath of Assessment
    - [ ] Test the regex
```
臆斷 (IMPRESSION)
 [Active]
xxxxxx
 
 [Underlying disease]
xxxxxx
 
計劃與目標 (PLAN TO DO & GOAL)

```
- [ ] 用藥
```
目前用藥（不含ＳＴ）
 Espin EM * cap 100 mg            1        CAP    QD       PO  2022-05-25-2022-06-08 N
 Plavix FC tab 75 mg              1        TAB    QD       PO  2022-05-25-2022-06-08 N
 Concor FC * tab 1.25 mg          1        TAB    QD       PO  2022-05-25-2022-06-08 N
 Agglutex ##* inj 25000 u/5ml/vl  X1       VL     ONCE     IVA 2022-05-26-2022-05-27 Y
 LIXIANA FC #* tab 60 mg          1        TAB    QD       PO  2022-05-26-2022-06-09 N
 Norvasc * tab 5 mg               1        TAB    QD       PO  2022-05-26-2022-06-09 N
 LIPITOR FC * TAB 20 MG           1        TAB    QD       PO  2022-05-26-2022-06-09 N
 自備用藥
```

- [ ] APACH II
https://web9.vghtpe.gov.tw/emr2/icueval/Apache.do?action=browse&phistnum=15124013&pcaseno=28605269
```
//*[@id="ApacheItem2"]/td/table/tbody/tr[23]/td[3]

```

