OpenClinica 使用者手冊/DiscrepancyNotes
外觀
OpenClinica 可以將差異筆記匯出為 CSV 檔案,但是從 3.x 版本開始,匯出在 Excel 中開啟時會產生一些問題。這些問題是由描述和詳細筆記欄位中的雙引號、換行符和回車符引起的。此外,額外的換行符會導致 Excel 每隔一行出現空白行。
簡單地將差異筆記 CSV 匯出內容轉換為 Excel 可用格式。為此,將刪除描述和詳細筆記欄位中的換行符和回車符。雙引號將保留,但會正確轉義,並且行尾的雙換行符將替換為單個換行符。
- 以下程式碼特定於 Windows,已在 Windows 7 中測試過。
- Windows 不會執行未簽名的 PowerShell 指令碼,因此在建立簽名的指令碼之前,您必須手動執行這些命令。
- 在從 OpenClinica 下載的未修改的 csv 檔案上執行此操作 - 不要在 Excel 中修改或開啟並儲存檔案
- 指令碼啟動時,輸出檔案和輸入檔案都不能開啟。
- 可以在 Linux 下的 Perl 中重新實現正則表示式。
- 更改以下輸入和輸出值,以指向您所需的輸入檔案和輸出檔名(路徑可以從資源管理器的“位置框”中獲取)
- 在 Windows 開始選單的搜尋框中輸入 cmd(這將開啟一個終端)
- 然後將以下部分複製並貼上到終端中(右鍵單擊終端將開啟上下文選單,您可以在其中貼上)
- 指令碼下方是有關如何開啟更新的檔案並將其儲存為 Excel 格式的說明
powershell
#########################
#PowerShell script begin#
#########################
#Filename - in single quotes, the inputfile and outputfile
#The outputfile will be overwritten. The inputfile will not be modified.
$inputfile = 'C:\Users\<user>\Documents\<study>\Discrepancies\dnotes_studyid.csv'
$outputfile = 'C:\Users\user>\Documents\<study>\Discrepancies\dnotes_studyid_working.csv'
#Get the file
$text = [System.IO.File]::ReadAllText($inputfile)
#Replacements
$text= $text -replace '\n','<newline/>'
$text= $text -replace '\r','<return/>'
#Give the line after the header a double line
$text= [regex]::Replace($text, "(id,Subject name,CRF name,Description,Discrepancy type,Event name,Parent note ID,Resolution status,Detailed notes,Entity name,Entity value,Date created,Date updated,Study id,Thread Number)",'$1<newline/>')
#Mark end of lines
#Start of lines look like this: <return/><newline/>16883,12047X,FF
#OR: <newline/><newline/>16883,12047X,FF
#Assume ids are up to 8 chars length
$text= [regex]::Replace($text, "(<return/><newline/>)(\d{1,8},[^.]*?,[^.*?])", '<endofline/><startofline/>$2');
$text= [regex]::Replace($text, "(<newline/><newline/>)(\d{1,8},[^.]*?,[^.*?])", '<endofline/><startofline/>$2');
#Mark the end of file as an end of line:
$text=$text+'<endofline/>'
#Simplify by removing unusual extra lines
$text= $text -replace ',,,,,,<return/><newline/>,,,,,,,,,,,,,,<return/><newline/>',''
$text= $text -replace ',,,,,,,,<return/><newline/>,,,,,,,,,,,,,,<endofline/>','<endofline/>'
$text= $text -replace '<return/><newline/>,,,,,,,,,,,,,,<endofline/>','<endofline/>'
#Simplify by removing newlines and returns
$text= $text -replace '<newline/>',''
$text= $text -replace '<return/>',''
#Lines look like this: id,Subject name,CRF name,Description,Discrepancy type,Event name,Parent note ID,Resolution status,Detailed notes,Entity name,Entity value,Date created,Date updated,Study id,Thread Number
#find beginning of description
$text= [regex]::Replace($text, "(<startofline/>[^,]*?,[^,]*?,[^,]*?,)",'$1<begindescription/>"')
#Find end of notes
$text= [regex]::Replace($text, "(,[^,]*?,[^,]*?,[^,]*?,[^,]*?,[^,]*?,[^,]*?<endofline/>)",'"<endnote/>$1')
#Find end of description and beginning of notes
$text= [regex]::Replace($text, "(<begindescription/>.*?)(,[^,]*?,[^,]*?,)(\d{4,6}|)(,[^,]*?,)(.*?<endnote/>)",'$1"<enddescription/>$2$3$4<beginnote/>"$5')
#Fix header quirk:
$text= [regex]::Replace($text, "(id,Subject name,CRF name,Description,Discrepancy type,Event name,Parent note ID,Resolution status,Detailed notes)""(<endnote/>)",'$1')
#Fix double quotes:
$text= $text -replace '<beginnote/>""<endnote/>','<beginnote/><endnote/>'
$text= $text -replace '<beginnote/>""','<beginnote/>"'
$text= $text -replace '""<endnote/>','"<endnote/>'
$text= $text -replace '<begindescription/>""<enddescription/>','<begindescription/><enddescription/>'
$text= $text -replace '<begindescription/>""','<begindescription/>"'
$text= $text -replace '""<enddescription/>','"<enddescription/>'
#Carriage return [char]13
#Line feed [char]10
#Back replaces:
$text= $text -replace '<endofline/>',''
$text= $text -replace '<startofline/>',[char]10
$text= $text -replace '<beginnote/>',''
$text= $text -replace '<endnote/>',''
$text= $text -replace '<begindescription/>',''
$text= $text -replace '<enddescription/>',''
#Write new file
$text | Out-File $outputfile
#########################
#Powershell script end #
#########################
exit
- 開啟 Excel
- 從檔案選項卡中,選擇“開啟”。
- 透過瀏覽到輸出檔案的位置來開啟檔案 - 如果需要,將搜尋範圍擴大到“所有檔案”。
- 選擇“分隔符”,然後按“下一步”。
- 更改分隔符部分,取消選中“製表符”,選中“逗號”(將文字限定符保留為“”。
- 按“完成”。
- 您現在可以將檔案儲存為本機 xlsx 或其他格式。