Try   HackMD

cql-translation-service介紹

https://github.com/cqframework/cql-translation-service

簡介

官網的說明:A microservice wrapper for the CQL to ELM conversion library and CQL formatter. 其實還蠻直覺的,就是一個CQL轉ELM的微服務。

安裝步驟

  1. git clone
goit clone https://github.com/cqframework/cql-translation-service
  1. Build Package
mvn package
  1. Build Docker Image
    下載的Repositories中有寫好的Dockerfile,按右鍵執行Build Image...即可,Dockerfile內容如下:
# fetch basic image
FROM maven:3.9.5-eclipse-temurin-11

# application placed into /opt/app
RUN mkdir -p /app
WORKDIR /app

# selectively add the POM file and
# install dependencies
COPY pom.xml /app/
RUN mvn install

# rest of the project
COPY src /app/src
RUN mvn package

# local application port
EXPOSE 8080

# execute it
# CMD ["mvn", "exec:java"]
CMD ["java", "-jar", "target/cqlTranslationServer-2.3.0.jar", "-d"]
  1. Deploy

簡單的docker compose檔案如下:

version: '3.7'

services:

  cql:
    container_name: bmaincql
    image: cqltranslationservice
    ports:
      - "8081:8080"

執行docker compose up即可啟動

測試結果

使用HTTP POST,C#程式碼如下:

  1. 基本設定
using System.Net.Http;
using System.Text;
using System.Net.Http.Headers;
using System.Threading.Tasks;

HttpClient cqlClient = new HttpClient();
string URI = "http://localhost:8081/cql/translator?signatures=Overloads";

string cql = "";
string cqlFile = "Exercises10Key";
  1. 測試資料讀取
//read cql from file 
cql = System.IO.File.ReadAllText(@"C:\Project\sqf-exercises\cqf-exercises\input\cql\" + cqlFile + ".cql");

/*
    POST http://localhost:8081/cql/translator HTTP/1.1
    Content-Type: application/cql
    Accept: application/elm+json
*/
StringContent cqlContent= new StringContent(cql, Encoding.UTF8,"application/cql");
  1. 測試結果與輸出
// add Content-Type: multipart/form-data
cqlClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/elm+json"));

//send cql to cql translator service
HttpResponseMessage cqlResponse = await cqlClient.PostAsync(URI, cqlContent);

try
{
    cqlResponse.EnsureSuccessStatusCode();
}
catch (HttpRequestException e)
{
    Console.WriteLine("\nException Caught!");
    Console.WriteLine("Message : {0} ",e.Message);
}

參數設定

配合firely-cql-sdkhttps://github.com/FirelyTeam/firely-cql-sdk使用,以下參數必須修改:

Item value Description
locators true Indicates that the translator should include source code locators within output ELM
signatures Overloads Indicates whether signatures should be included for invocations in the output ELM. Differing will include invocation signatures that differ from the declared signature. Overloads will include declaration signatures when the operator or function has more than one overload with the same number of arguments as the invocation
result-types true Indicates that the translator should include result types in the output ELM

待解決問題

從FHIR官方網站"Clinical Quality Framework Common FHIR Assetshttps://fhir.org/guides/cqf/common/index.html可以知道,目前發展了三個CQL Library:FHIR ModelInfo、FHIR Helpers和FHIR Common。

using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1'
include FHIRCommon version '4.0.1'

但如同官網所描述:Note that FHIRCommon is not a "well-known" library name,因此include FHIRCommon version '4.0.1'並不能正常運作。

目前可行替代方案是利用cql-translation-service提供的Multipart Translator Request功能,將所有CQL檔案(包含FHIRCommon.cql)一起傳入,之後將Response根據Boundary與Header切割成多個elm檔(JSON格式)。