This is a document for the IPCI practical session at the M conference on 2022/09/03
- MongoDB,Node.jsを使用してFHIRサーバーを構築する。
- 本マニュアルではDocker上にMongoDBを構築する。
Release4, PatientResource
をメインに解説。
- windows10(ubuntu20.04動作確認済)
- Node.js(ver16.1 or later)
- npm
- Docker for windows
- Postman Desktop (Postman Collection)
- MongoDB(ver5.09 or later)
- Git
# clone
git clone https://github.com/ryumtym/dokcer_mongo.git
git clone https://github.com/ryumtym/fhirServer.git
先ほどクローンしたryumtym/docker_mongoのディレクトリに移動後、下記コマンドを入力することで、Docker上にMongoDB(port27017)とMongoExpress(port8081)が立ち上がる。
コンテナの起動例
# ディレクトリに移動
PS C:\Users\user\Desktop> cd docker_mongo
# 起動
PS C:\Users\user\Desktop\docker_mongo> docker-compose up -d
以下のコマンドでmongoDBコンテナの起動を確認
# 動いているコンテナを確認
PS C:\Users\user\Desktop> docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
faa8ded75a9c mongo-express:latest "tini -- /docker-ent…" 3 weeks ago Up About an hour 0.0.0.0:8081->8081/tcp mongo_docker-mongo-express-1
3b342f1c80d0 mongo:latest "docker-entrypoint.s…" 3 weeks ago Up About an hour 0.0.0.0:27017->27017/tcp mongo_docker-mongo-1
ryumtym/fhirServerは、bluehalo/node-fhir-server-mongo からFHIR準拠に対応するためにforkした現在開発中のリポジトリ
fhirServerディレクトリ直下のenv.json
内MONGO_HOSTNAME.default
値がMongoDBアドレス&ポートと合致しているか確認後、以下のコマンド入力。
http://localhost:3000/4_0_0/metadata
にアクセスできれば起動している。
# ディレクトリ移動
PS C:\Users\user\Desktop> cd fhirServer
# moduleインストール
PS C:\Users\user\Desktop\fhirServer> npm install
# 起動
PS C:\Users\user\Desktop\fhirServer> npm start
RESTでのFHIR準拠でのcall方法に正しく則った手順と設定をPostman Collectionsで作成した。
- Postman Desktop左上のImportボタン(下図赤枠箇所)をクリック
- Linkタブを選択し、
https://www.getpostman.com/collections/39b5e9d6f37b86a56600
をペースト、Continueをクリック - Importボタンをクリックし完了
今回の動き
sequenceDiagram
%%{init:{'theme':'base'}}%%
autonumber
participant client
participant fhirServer(PORT3000)
participant mongoDB
client->>fhirServer(PORT3000) : RestAPI形式で患者IDをリクエスト<br>[GET]https://example.com/{id}
fhirServer(PORT3000)->>mongoDB: リクエスト内容をもとにQueryを作成し、mongoDBへアクセス
mongoDB->>fhirServer(PORT3000): status:200<br>リクエストされた患者IDをレスポンス
fhirServer(PORT3000)->>client: status:200<br>リクエストされた患者IDをレスポンス
認可サーバー込みの場合
sequenceDiagram
%%{init:{'theme':'base'}}%%
autonumber
participant client
participant fhirServer(PORT3000)
participant Authz
participant mongoDB
client->>fhirServer(PORT3000) : RestAPI形式でリクエスト<br>[GET]https://example.com/{id}<br>Token付き
fhirServer(PORT3000) ->>Authz:Tokenチェック
Authz-->>fhirServer(PORT3000):チェック結果の返却
fhirServer(PORT3000)->>mongoDB: リクエスト内容をもとにQueryを作成し、mongoDBへアクセス
mongoDB-->>fhirServer(PORT3000): status:200<br>リクエストされた患者IDをレスポンス
fhirServer(PORT3000)-->>client: status:200<br>リクエストされた患者IDをレスポンス
メソッド | 概要 | URI |
---|---|---|
POST | 登録 | http://localhost:3000/4_0_0/Patient |
GET | 取得 | http://localhost:3000/4_0_0/Patient/{id} |
UPDATE | 更新 | http://localhost:3000/4_0_0/Patient/{id} |
DELETE | 削除 | http://localhost:3000/4_0_0/Patient/{id} |
Bodyにexampleデータを入れて試す
インポートしたPostmanCollectionからDELETE DATA
を選択、{id}
を先ほどコンソールに表示された値に変え、Send
でデータ削除が完了
元版のbluehalo/node-fhir-server-mongoは、クエリ検索に未対応箇所がある為、hl7/QueryParamsを基に作成中 ✔️は対応済みのTypeとmodifier
各リソースの編集・追加はsrc/service
内で行う
追加機能(2022/8/16現在)
- buildStu3 -> buildRelease4
- Date/DateTime -> 年月日検索, 日付範囲検索
- String -> 完全一致検索, 前方一致検索, 部分一致検索
- Token -> 否定検索
例: 性別が男性以外 & 姓にChiangを含む & 1965/07/01から1999までに生まれた & 最終更新日が2022/08の患者データ一覧を取得
http://localhost:3000/4_0_0/patient?gender:not=male&family:contains=Chiang&birthdate=gt1965-07-01&birthdate=lt1999&_lastUpdated=2022-08
例: 住所(line/city/district/state/country/postalCodeのいずれか)が1600023 & 名前(text/family/given//prefixのいずれか)が山田から始まる & 記録が有効でない患者データ一覧を取得
http://localhost:3000/4_0_0/Patient?address=1600023&name=山田&active:not=true
Summary | modif ✔️ | example |
---|---|---|
_id | ?_id=12345 | |
_lastUpdated | eq gt lt |
?_lastUpdated=2021 |
Summary | modif ✔️ | example |
---|---|---|
active | :not |
?active:not=true |
address | :contains :exact |
?address:contains=ja |
address.City | :contains :exact |
?address-city=PleasantVille |
birthDate | eq gt lt |
?birthdate=gt2001&birthdate=lt2022-06-12 |
deathDate | eq gt lt |
?death-date=2015-01-01T00:00:00+00:00 |
deceased | :not |
?deceased:not=true |
gender | :not |
?gender:not=unknown |
general_practitioner | ||
identifier | :text |
?identifier=example.com |
link | ?link=pat2 | |
name | :contains :exact |
?name:exact=thebausffs |
name.family | :contains :exact |
?family=chiang |
name.given | :contains :exact |
?given=ted |
organization | ?organization=1 | |
telecom | ?telecom=phone|070-1234-5678 |
Summary | modif ✔️ | example |
---|---|---|
code | ?code=55233-1 | |
component-code-value-quantity | ?component-code-value-quantity=8462-4$gt80 | |
date | eq gt lt |
?date=gt2013&date=lt2015 |
encounter | ?encounter=1568820 |
. ├─public ├─src │ ├─capabilty.js │ ├─constants.js │ ├─global.js │ ├─lib │ ├─utils │ ├─service -> 各resourceファイルを置くフォルダ │ ├─strategies -> 認可サーバーへの接続関連フォルダ │ ├─config.js -> fhirサーバーの設定をまとめるファイル │ ├─index.js -> config.jsの呼び出し・fhirサーバーの起動等を行うファイル └─env.json -> 環境変数ファイル