CQL WorkbenchDocs
Docs contents
CQL primer

Reading an NHI pre-check rule in CQL

Taiwan’s NHI pre-check rule guide writes the reimbursement criteria for cancer drugs as CQL libraries. This page takes one lung cancer immunotherapy rule and reads it from the header to the final decision: which modules and codes it includes, which fields it pulls from the TWPAS request, and how the criteria combine into pass or fail.

A guided read, not an official document: This page follows the continuous build as checked on 2026-10-28. All code on this page is illustrative, written to explain the patterns, and is not the official text; read the official pages for the full rules. For reimbursement criteria, the NHI Administration’s announcements take precedence.

The library

The guide currently holds 77 libraries: 66 reimbursement rules for breast, colorectal, lung, liver and prostate cancer, one code set and one shared module per cancer type, and FHIRHelpers for type conversion. This page reads LCPembrAtezoRule1, a lung cancer rule.

We chose it because this one library uses most of the patterns in the guide: two drugs share one rule, first use and continued use are judged separately, the criteria cover diagnosis, gene tests, PD-L1, lab values, imaging reports and a treatment plan document, and the library ends by producing a text report. The original runs to just over 900 lines and more than 100 defines. This page covers the structure, so keep the official page open for the line-by-line detail.

Library
LCPembrAtezoRule1
Title
Pembrolizumab、Atezolizumab給付規定(鱗狀、非鱗狀非小細胞肺癌第一線用藥(單用))Pembrolizumab and atezolizumab criteria: first-line monotherapy for squamous and non-squamous non-small cell lung cancer
Version
1.0.0, status Draft
Includes
FHIRHelpers 4.0.1, LCCodeConcept 1.0.0 (lung cancer code set), LCReusable 1.0.0 (lung cancer shared module)

What the rule reads

The rules read request data as TWPAS defines it. Under TWPAS, a hospital packages each prior authorization request as a Bundle: the claim (Claim) plus resources for the patient, medications, tests and reports. This library’s data requirements (dataRequirement) list five resource types, and it reads the patient through context Patient:

ResourceWhat it readsUsed for
PatientDate of birthWhether the patient is 18 or older at the time of the request
ClaimPrincipal diagnosis (the ICD-10-CM code at diagnosis sequence 1), the free text of the case summary (簡要病摘), order type, continuation flag, line of therapy, reimbursement indication code, supporting informationLung cancer diagnosis, NSCLC and histology, first line, indication, first or continued use
MedicationRequestIntent plan marks the drug being requested and intent order marks medication history; treatment start and end datesCurrent and previous requests, treatment length, concurrent drugs
ObservationLab tests, gene information, patient status assessments, cancer stage, response assessmentsWild-type genes, PD-L1, liver and kidney function, ECOG, NYHA, M stage, i-RECIST
DiagnosticReportImaging reports, molecular or pathology reportsImaging within 12 weeks, presence of a test report
DocumentReferenceThe treatment plan document referenced from the claim’s supporting informationImmune checkpoint inhibitor treatment plan

TWPAS also has a Condition profile, but this rule reads every diagnosis from Claim.diagnosis and never queries Condition. When you read an official rule, check which resource and field it actually queries rather than guessing from the criteria text.

The rules we opened all start with the same few lines; only the name and the cancer type of the includes change:

Illustrative: the library name is made up; the structure matches the official rules
library LCExampleRule version '1.0.0'
Name and version. Official names are usually a cancer prefix plus the drug name, then Rule and a number. The prefixes are BC (breast), CRC (colorectal), LC (lung), HCC (liver) and PC (prostate).
using FHIR version '4.0.1'
The data model is FHIR 4.0.1 (R4), the same as TWPAS.
include FHIRHelpers version '4.0.1' called FHIRHelpers
Helper functions that convert FHIR R4 data types, such as dates and numbers, into CQL types so they can be compared.
include LCCodeConcept version '1.0.0' called CodeConcept
The code set for the cancer type, under the alias CodeConcept. CodeConcept.EGFR in a rule means the code list named EGFR in that library.
include LCReusable version '1.0.0' called Reusable
The shared module for the cancer type, under the alias Reusable: common defines and functions for request type, line of therapy, age, lab checks and so on. Rules call them like Reusable."初次申請" (first-use request).
context Patient
Every define after this line is evaluated for one patient.

Besides this lung cancer rule, we opened one rule each for colorectal, breast, liver and prostate cancer, and their headers follow the same structure. There is no parameter in the header: everything the rule needs is queried from the request data.

Code sets: the codes a rule uses

LCCodeConcept has no context and no logic. It only holds codes, in three groups:

  • Code systems: the international SNOMED CT, LOINC and HL7 observation interpretation codes; the NHI code systems defined by TWPAS, such as line of therapy, NHI drugs, order type, continuation flag, response assessment, supporting information type and reimbursement indication; and TW Core’s Taiwan editions of ICD-10-CM and ICD-10-PCS (2014 and 2023).
  • Lab and test codes, listed as strings with define: the LOINC codes for EGFR, ALK, ROS1 and the PD-L1 assays, the LOINC codes for GOT, GPT, T-bilirubin, creatinine and eGFR, and the ICD-10-PCS codes for imaging.
  • Drug codes: each list is named by its ATC code and holds NHI drug codes. L01FF02 is pembrolizumab and L01FF05 is atezolizumab.
Illustrative, not the official text
// Code set library: declare code systems, then list the codes
codesystem "LOINC": 'http://loinc.org'
codesystem "NHILOT": 'https://nhicore.nhi.gov.tw/pas/CodeSystem/nhi-line-of-therapy'

define "Some gene test": { 'code-A', 'code-B' }

The code set has no valueset declarations. The code lists sit in the library itself, so nothing needs to expand a FHIR ValueSet at run time. When a rule says CodeConcept followed by a name, look up the define with that name on the code set page to see which codes it covers.

Pulling data from the request

A rule uses a retrieve (the resource type in square brackets, such as [Observation]) to get this patient’s resources of one type, then filters them with where. Four patterns come up again and again in this rule:

Finding a test by category and codeFor an Observation, the rule first checks the supporting information category (lab test, gene information, patient status assessment), then whether the LOINC code is in a list from the code set, and finally compares the value or the text.
Drilling down into the claimThe continuation flag, line of therapy and reimbursement indication all sit under the claim’s requested items (item). The rule digs down with nested exists, and one matching entry is enough.
Finding the current, previous and first requestAmong MedicationRequests with intent plan, sorted by treatment start date, the last is the current request, the earliest is the first request, and the latest one before the current request is the previous one. Age is also calculated as of the current treatment start date.
Matching textConditions such as NSCLC, squamous or non-squamous are checked with Matches, a regular expression search over the case summary text, and some wild-type gene results are matched as text too. What the hospital writes in the request therefore affects the result directly.
Illustrative, not the official text
// Pattern 1: a lab value below a threshold
define "Some lab below threshold":
  exists (
    [Observation] O
      where Reusable."IsTestObservation"(O)        // category is "lab test"
        and exists (
          O.code.coding C
            where C in CodeConcept.LOINC             // code system is LOINC
              and C.code in CodeConcept."Some lab"   // code is in the list
        )
        and O.value is FHIR.Quantity
        and (O.value as FHIR.Quantity).value < 2.0   // value below the threshold
  )

The criteria: defines in layers

The hierarchy of the reimbursement criteria becomes the hierarchy of defines: conditions make up rules, and rules make up main rules. Official define names put the number and the wording of the clause together, such as 1規則1-3=成人 (rule 1-3 = adult), which makes them easy to match against the criteria text.

Illustrative, not the official text
// Conditions make up rules, rules make up main rules, joined with and / or
define "Rule 1":
  "Rule 1-1" and "Rule 1-2" and "Rule 1-3"

// The same rule checks a different condition depending on the drug requested
define "Rule 3":
  if "Drug A requested" then "Drug A PD-L1 condition"
  else if "Drug B requested" then "Drug B PD-L1 condition"
  else false

define "Main rule 1":
  "Rule 1" and "Rule 2" and "Rule 3" and "Rule 4"

The rule has three main rules. Main rule 1 (first use) is made of four rules:

RuleWhat it checksResources read
1規則1Metastatic NSCLC, first line: principal diagnosis C34, order type drug, NSCLC noted in the case summary, M stage not 0, first line of therapy, a molecular or pathology report, indication code P013; EGFR and ALK wild type for the histology, plus ROS1 for non-squamous; 18 or older at the time of the request.Claim, Observation, DiagnosticReport, Patient
1規則2Performance status and liver and kidney function: ECOG ≤ 1, NYHA class I or II, GOT and GPT < 60 U/L, T-bilirubin < 1.5 mg/dL, creatinine < 1.5 mg/dL and eGFR > 60 mL/min/1.73m².Observation
1規則3PD-L1, depending on the drug: for pembrolizumab, TPS ≥ 50% on Dako 22C3 or Ventana SP263; for atezolizumab, TC ≥ 50% or IC ≥ 10% on Ventana SP142.MedicationRequest, Observation
1規則4An imaging report within 12 weeks before the current treatment start date, and an immune checkpoint inhibitor treatment plan.DiagnosticReport, Claim, DocumentReference

Main rule 2 (continued use) requires a continuation flag of 2 and a response on i-RECIST, or stable disease (SD) as long as the current and previous assessments are not both SD; no confirmed progression (iCPD), no moderate, severe or life-threatening adverse drug reaction, and no break in treatment longer than 24 weeks; and the patient must still pass the performance status and organ function checks of 1規則2 and have imaging within 12 weeks.

Main rule 3 (drug use rules) holds four limits: one immune checkpoint inhibitor per patient per indication, with no switching; no concurrent use of the listed targeted drugs during treatment; no more than 2 years in total; and at most 12 weeks per request. The report labels these four as reference information (參考資訊), and they do not affect the final result.

The final decision

The last few defines turn everything above into output:

Request type
The shared module reads the continuation flag on the claim: 1 is first use and 2 is continued use (the TWPAS code table calls it a repeat request). With neither, the type cannot be determined.
Boolean result
Its name ends in _布林 (Boolean). First use is judged on main rule 1, continued use on main rule 2, and an undetermined request type gives false.
Text result
Pass or fail, together with the request type.
Report summary (報告總結)
A text report: request type, items met, items not met, and finally the result. Items not met are split into two groups: required data missing, and conditions or codes not met.
Illustrative, not the official text
// The request type decides which main rule applies; an unknown type fails
define "Result (Boolean)":
  case
    when Reusable."First use" then "Main rule 1"
    when Reusable."Continued use" then "Main rule 2"
    else false
  end

How does the report tell “not provided” apart from “provided but not met”? The rule has a separate set of defines that check whether each piece of data was provided, named “… data exists” (…資料存在), such as ECOG資料存在. The conditions themselves mostly ask whether matching data can be found, so missing data makes them false, not null. Looking only at the Boolean result, missing data and unmet criteria both fail; these extra defines are what let the report tell the hospital which item is missing.

Compared with the workbench

The CQL the workbench exports handles the same kind of question as the official rules, but it is written differently:

AspectOfficial pre-check rulesThe workbench’s CQL
Where data comes fromThe CQL queries the TWPAS FHIR resources itself with retrievesAn adapter checks the record first and passes each condition’s answer in as a parameter
One conditionA define containing the query, codes and thresholdsA Boolean parameter; defines only combine them
CodesOne code set library per cancer typeNone in the CQL; checking the record is the adapter’s job
Missing dataThe condition is false; separate “data exists” defines flag it in the reportThe parameter is null, three-valued logic carries it upward, and the result is insufficient-data
OutputA Boolean result, a pass or fail text, and a reporteligible, ineligible or insufficient-data

For why the workbench uses parameters, see Parameter-based CQL in Core concepts; for how parameters and three-valued logic work, see Parameters and Three-valued logic in the CQL primer; for how the two fit together, see Where the workbench fits on the Taiwan guidance page.

To compare, treat each official condition define as one atomic condition. For example, 1規則1-3=成人 corresponds to the condition “18 or older at the time of the request”. Going through them one by one shows whether the conditions the workbench extracted miss anything or add anything. Also watch the details of the official checks, such as age being calculated at the current treatment start date and imaging having to fall within 12 weeks: both the conditions you split out in the workbench and the parameters the adapter fills in need to match them.

Reading checklist

Whichever rule in the guide you open, you can read it in this order:

  1. Check the metadata at the top of the page: official URL, version, status, and the code set and shared module listed under Dependency.
  2. Read the title and the opening comment to confirm the cancer type, the drug and the indication. Look up the reimbursement indication code (such as P013) in the TWPAS indication code table.
  3. Read the includes. For CodeConcept followed by a name, find the define with that name on the code set page for that cancer type; for Reusable followed by a name, look on the shared module page.
  4. Use the comment dividers to find each main rule, then match the rule and condition numbers to the reimbursement criteria text.
  5. Go through the condition defines one by one: which resource and field each reads, and which codes or thresholds it uses. Pay particular attention to conditions that match text with Matches.
  6. Find the defines that check whether data was provided (in this rule, the ones ending in 資料存在) to see what counts as missing data.
  7. Finish with the results: the Boolean result, the text result and the report. Items marked as reference information (參考資訊) do not affect the result.
  8. Note the date you checked. The guide is still a draft, and the same library may have changed the next time you open it.

Version and status

As checked on 2026-10-28, consistent with the Taiwan guidance page:

  • The guide is a continuous integration (CI) build, 0.0.1, marked as a draft. Its header says it is not an authorized publication and changes regularly.
  • This library is version 1.0.0, status Draft.
  • The official URLs the guide declares, under the NHI Administration’s nhicore.nhi.gov.tw/cql/, were not live when we checked. For now you read it on build.fhir.org, and the guide’s download page offers the whole package as package.tgz.
  • The guide’s dependencies list TWPAS 1.2.4, while the NHI Administration currently publishes TWPAS 1.2.7. Before testing with real request data, check what changed in fields and codes between the two.

Official pages

Read the official pages for the full CQL. All links were checked on 2026-10-28.

  1. Taiwan NHI Clinical Quality Language Implementation Guide (臺灣健保預檢規則實作指引)
  2. Library list, grouped by cancer type
  3. LCPembrAtezoRule1: the lung cancer rule read on this page
  4. LCReusable: lung cancer shared module
  5. LCCodeConcept: lung cancer code set
  6. FHIRHelpers
  7. Taiwan NHI Prior Authorization Support Implementation Guide (TWPAS) (臺灣健保事前審查實作指引)
  8. The TWPAS Claim profile
  9. The TWPAS reimbursement indication code table