Lorex L. Yang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    2
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # HAPI FHIR 伺服器建置指南(新手向) [TOC] ## Prerequisites 這份指南將會使用 Rocky Linux 8.4 做為教學用的系統,Rocky Linux 8 是 CentOS 8 的替代版本,用起來一模一樣,如果你沒看過,現在讓你看看: **Rocky Linux 8 官方網站**:https://rockylinux.org/zh-tw/ 如果你有在使用 VMWare、VirtualBox 等虛擬化平台,可以考慮改用 Proxmox VE。他是一個**開放原始碼**的虛擬化平台,並提供一個類似 VMWare vCloud 的 Web 管理工具。你可以在上面開 QEMU VM 跟LXC Container,也可以在上面實現 Ceph、HA Cluster 等機制,全部都滑鼠點一點就好。 Proxmox VE 上面已經有 Rocky Linux 8 的 LXC Image,直接抓下來開就行了,請參考以下說明,或是你也可以參考 Jason(Proxmox VE 專家,江湖人稱"節神")的系列文章: **Proxmox VE 官方網站**:https://pve.proxmox.com/wiki/Main_Page **節省工具箱部落格**:https://blog.jason.tools/ ## 說明 這份筆記是給完全沒接觸過 HAPI FHIR 架設的初學者使用的(當然建議讀者還是要知道怎麼操作 Linux 作業系統),在接下來的教學中,你將學會如何從官方的 GitHub Repository 把 HAPI FHIR 伺服器抓下來,設定好 PostgreSQL 資料庫後,直接把伺服器跑起來。 至於打包成 Docker 之類的進階操作,請參考另一份筆記: [FHIR 伺服器建置指南](https://hackmd.io/e7sWPVUzQjSTJ6IYDcwAFQ?both) ## 環境設定與安裝 ### 安裝 EPEL 8 擴展套件庫 安裝 EPEL8 擴展套件庫並更新系統,中間會跳出提示,直接 y 到底就好 ```bash= $ dnf install epel-release -y $ dnf update -y ``` ### 安裝 PostgreSQL 14 安裝 PostgreSQL 套件庫,中間會跳出提示,直接 y 到底就好 ```bash= $ dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm $ dnf update -y ``` 把內建的 PostgreSQL 套件庫停用 ```bash= $ dnf -qy module disable postgresql ``` 安裝 PostgreSQL 14 伺服器(寫這篇文的時候剛好 14 stable 版本 release 出來了,就直接上) ```bash= $ dnf install postgresql14 postgresql14-server -y ``` 安裝好之後確認一下 PostgreSQL 版本對不對 ```bash= $ psql -V ``` ![](https://i.imgur.com/QpzY44Q.png) 開始之前要先初始化 PostgreSQL 14 資料庫 ```bash= $ /usr/pgsql-14/bin/postgresql-14-setup initdb ``` 確認版本沒問題後,就可以啟動並設定開機自動啟用 ```bash= $ systemctl enable postgresql-14 $ systemctl start postgresql-14 ``` 檢查一下 PostgreSQL 是否正常啟動 ```bash= $ systemctl status postgresql-14 ``` ![](https://i.imgur.com/eUJCP6W.png) ### 設定 PostgreSQL 安裝好後,PostgreSQL 預設會幫你建立一個叫 ==postgres== 的使用者,記得先改密碼 ```bash= $ passwd postgres ``` 切換到 postgres 這個使用者 ```bash= $ su - postgres ``` 改資料庫管理員 ==postgres== 的預設密碼 ```bash= $ psql -c "ALTER USER postgres WITH PASSWORD '新密碼';" ``` 顯示 **ALTER ROLE** 代表有改成功 ![](https://i.imgur.com/Lbv8k7B.png) :::warning 注意:這邊密碼設 1234 是只做教學展示用途,**好孩子請不要學**,否則你的資料庫會被打到不要不要的 ˊ_>ˋ ::: ### 新建 FHIR 用的資料庫 連線進去資料庫 ```bash= $ psql ``` 進來後你會看到這樣的提示: ![](https://i.imgur.com/A2xVYAP.png) 新建使用者 ```bash= $ create user fhir with encrypted password 'hapifhir'; # 語法長這樣 $ create user 使用者名稱 with encrypted password '密碼'; ``` :::warning 注意:還是要強調,密碼請設定**強密碼**,否則你的資料庫會被打到連你老板都認不出來 ˊ_>ˋ ::: 新建資料庫 ```bash= $ create database hapifhir with owner fhir template template0; # 語法長這樣 $ create database 資料庫名稱 with owner 資料庫擁有者名稱 template template0; ``` 將所有權限給這個使用者 ```bash= $ grant ALL privileges on database hapifhir to fhir; # 語法長這樣 $ grant ALL privileges on database 資料庫名稱 to 使用者名稱; ``` 設定資料庫時區為臺灣時區 ```bash= $ alter database hapifhir set timezone to 'ROC'; # 語法長這樣 $ alter database 資料庫名稱 set timezone to '時區代碼'; ``` 上面全部設定完之後就退出 PostgreSQL 並退出 postgres 帳號 ```bash= postgres=# \q $ exit ``` ![](https://i.imgur.com/1jAdu8P.png) ## 安裝 HAPI FHIR 伺服器 我們會直接使用最新版的 HAPI FHIR 伺服器,並設定使用 R4(FHIR 4.0.1) 版本。 因為這個是用 Java 寫的,所以會需要準備 Java 跟 Maven 環境。另外各版本 HAPI FHIR 支援的 Java 版本都不一樣,記得參考以下網站: https://hapifhir.io/hapi-fhir/docs/getting_started/versions.html :::info 在最新版本的 HAPI FHIR 裡面,官方雖然將最小 Java 版本訂為 Java 8,不過實際上 Java 8 會編譯失敗,因此要改用 Java 11 ::: ### 安裝必要套件 安裝必要套件 ```bash= $ dnf install -y vim git make gcc gcc-c++ tmux ``` 安裝 Java 11(你也可以試試看 Java 16) 跟 Maven ```bash= $ dnf install java-11-openjdk-devel maven ``` 由於 Maven 3.5.4 預設使用 Java 8,因此要把版本切換回 Java 11 ```bash= $ alternatives --config java $ alternatives --config javac ``` ![](https://i.imgur.com/gbtxHXy.png) 讓 Maven 預設使用 Java 11 ```bash= $ vim /etc/profile ``` 最下面加入這行 ```bash= export JAVA_HOME=/usr/lib/jvm/java-11-openjdk ``` 讓他生效 ```bash= $ source /etc/profile ``` ### 下載並設定 HAPI FHIR 伺服器 從 GitHub 把 Repository 抓下來 ```bash= $ git clone https://github.com/hapifhir/hapi-fhir-jpaserver-starter.git ``` 設定 HAPI FHIR Server 組態 ```bash= $ cd hapi-fhir-jpaserver-starter/ $ vim src/main/resources/application.yaml ``` 把資料庫改為 PostgreSQL 並設定連線資訊 ```yaml= spring: datasource: url: 'jdbc:postgresql://localhost:5432/hapifhir' username: fhir password: hapifhir driverClassName: org.postgresql.Driver jpa: hibernate.dialect: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect ``` 設定使用 FHIR R4 版本: ```yaml= hapi: fhir: ### This is the FHIR version. Choose between, DSTU2, DSTU3, R4 or R5 fhir_version: R4 server_address: http://<伺服器URL>/fhir # 設定伺服器 URL default_encoding: JSON # 預設使用 JSON default_pretty_print: true # 預設格式化輸出 default_page_size: 20 # 預設搜尋結果分頁數量 graphql_enabled: true # 啟用 GraphQL cors: # 啟用 CORS 設定 allow_Credentials: true allowed_origin: - '*' tester: home: name: Local Tester server_address: 'http://<伺服器URL>/fhir' # 設定伺服器位址 refuse_to_fetch_third_party_urls: false fhir_version: R4 validation: # 設定伺服器端驗證 requests_enabled: true responses_enabled: true ``` ### 編譯並執行 進入 tmux 虛擬視窗 ```bash= $ tmux ``` 編譯成 war 可執行檔,編譯候會放在 target/ROOT.war 裡面 ```bash= $ mvn clean package spring-boot:repackage -Pboot ``` 上面這條指令預設以 Single Thread 模式執行,如果你的主機是多核心,也可以加入```-T <thread>```參數,幾核心就打多少數字,像這樣: ```bash= $ mvn clean package spring-boot:repackage -Pboot -T 20 ``` 看到 ```BUILD SUCCESS``` 就代表編譯成功了 ![](https://i.imgur.com/khf1XnB.png) 用 Java 執行 ```bash= $ java -jar target/ROOT.war ``` 只要不跳錯誤,並且看到 ```Completed initialization in ....ms``` 這行就代表啟動成功了 ![](https://i.imgur.com/Cb3JpzX.png) 伺服器預設會開在 8080 Port,請直接打開瀏覽器輸入 ```http://<IP>:8080```即可看到 HAPI FHIR 頁面 ![](https://i.imgur.com/zvlJLbb.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully