目前台灣約有六千家,(不能去拿處方簽的不算在內),比7-11還多。
首先,我們先取得所有醫事機構的檔案,再來做過濾,檔案在下列網址。
http://www.nhi.gov.tw/webdata/webdata.aspx?menu=18&menu_id=703&webdata_id=660
這裡的檔案不定時會更新,更新頻率大約在4-7天一次,寫這篇文時,是4月7日更新。
接著下載上圖中框起來的那個檔案。
之後解壓縮,進人到資料夾中 ,找到hospbsc.txt ,這個是我們要的,另一個zip沒用到。
接下來,我們把檔案打開來看一下,嗯~東西有點多,北七覺得睏惑。
找到下面一點有個連結,也許有用
點進去一下,找到了特約類別代碼的中文意義,看來我只需要"5"。
接下來,咱們用Java來示範怎麼處理這個hospbsc.txt
package hospbsc;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author bert
*/
public class Hospbsc {
public static void main(String[] args) {
Hospbsc hp = new Hospbsc();
hp.readFIle();
}
private void readFIle() {
//讀檔
File fr = null;
//寫檔
BufferedWriter writer = null;
try {
//讀取D:\hospbsc.txt
fr = new File("d:\\hospbsc.txt");
//這很行重要,一定要用Big5
InputStreamReader read =
new InputStreamReader(new FileInputStream(fr), "Big5");
BufferedReader br = new BufferedReader(read);
//判斷是否為title行
boolean title = false;
String line = "";
//寫入D:\Rx.txt
File logFile = new File("D:\\Rx.txt");
writer = new BufferedWriter(new FileWriter(logFile));
//如果可以讀檔
while (br.ready()) {
//讀取一行
line = br.readLine();
//如果不是抬頭行
if (title) {
String[] temp = line.split(",");
//如果分類是藥局則寫入資料
if (temp[6].equals("\"5\"")) {
writer.write(line + "\n");
}
} else {
//寫入抬頭行
writer.write(line + "\n");
}
title = true;
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Hospbsc.class.getName()).
log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Hospbsc.class.getName()).
log(Level.SEVERE, null, ex);
} finally {
}
}
}
執行後去開一下D:\Rx.txt,只有藥局了。
如果需要取其它種類的醫事機構,只需修改,例如改成取診所
if (temp[6].equals("\"4\""))


沒有留言:
張貼留言