diff --git a/phc/easy/query/fhir_dsl_query.py b/phc/easy/query/fhir_dsl_query.py
index c1ecc3b..2d8a5b2 100644
--- a/phc/easy/query/fhir_dsl_query.py
+++ b/phc/easy/query/fhir_dsl_query.py
@@ -8,6 +8,7 @@ FHIR_WHERE = lens.Get("where", {})
 FHIR_WHERE_TYPE = FHIR_WHERE.Get("type", "")
 FHIR_SIMPLE_QUERY = FHIR_WHERE.Get("query", {})
 FHIR_BOOL_QUERY = FHIR_SIMPLE_QUERY.Get("bool", {})
+FHIR_BOOL_MUST_QUERY = FHIR_BOOL_QUERY.Get("must", [])
 
 
 @curry
@@ -45,6 +46,11 @@ def and_query_clause(query: dict, query_clause: dict):
             query
         )
 
+    if len(bool_keys) == 1 and "must" in bool_keys:
+        return FHIR_BOOL_MUST_QUERY.modify(lambda must: [*must, query_clause])(
+            query
+        )
+
     raise ValueError("Could not add clause to query", query_clause, query)
 
 

Merge patient_ids with "must" query
Currently, `patient_ids` cannot be auto-merged with this type of custom query:

```python
phc.Procedure.get_date_frame(patient_ids=["a", "b"], query_overrides={
    "where": {
        "type": "elasticsearch",
        "query": {
            "bool": {
                "must": [
                    {"term": {"code.coding.code.keyword": "blah"}},
                    {"term": {"code.coding.system.keyword": "http://loinc.org"}}
                ]
            }
        }
    }
})
```
diff --git a/tests/test_fhir_dsl_query.py b/tests/test_fhir_dsl_query.py
index 0fc3ecf..c71b9cf 100644
--- a/tests/test_fhir_dsl_query.py
+++ b/tests/test_fhir_dsl_query.py
@@ -65,6 +65,35 @@ def test_add_patient_id_with_query_term():
     }
 
 
+def test_add_patient_id_with_bool_must_query():
+    result = build_query(
+        {
+            "where": {
+                "type": "elasticsearch",
+                "query": {
+                    "bool": {"must": [{"term": {"gender.keyword": "male"}}]}
+                },
+            }
+        },
+        patient_ids=["a"],
+        patient_key="id",
+    )
+
+    assert result == {
+        "where": {
+            "type": "elasticsearch",
+            "query": {
+                "bool": {
+                    "must": [
+                        {"term": {"gender.keyword": "male"}},
+                        {"terms": {"id.keyword": ["Patient/a", "a"]}},
+                    ],
+                }
+            },
+        }
+    }
+
+
 def test_add_patient_id_with_bool_should_query():
     result = build_query(
         {

pip install -e .[dev]
parse_log_pytest
requirements.txt
nose nose-cov pytest
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
aiohappyeyeballs==2.6.1
aiohttp==3.11.14
aiosignal==1.3.2
async-timeout==5.0.1
attrs==25.3.0
backoff==1.10.0
cov-core==1.15.0
coverage==7.8.0
exceptiongroup==1.2.2
frozenlist==1.5.0
funcy==2.0
idna==3.10
iniconfig==2.1.0
lenses==1.2.0
multidict==6.2.0
nest-asyncio==1.6.0
nose==1.3.7
nose-cov==1.6
numpy==2.0.2
packaging==24.2
pandas==2.2.3
-e git+https://github.com/lifeomic/phc-sdk-py.git@31adf1f7f451013216071c2d8737e3512e5b56e8#egg=phc
pluggy==1.5.0
propcache==0.3.1
PyJWT==2.10.1
pytest==8.3.5
python-dateutil==2.9.0.post0
pytz==2025.2
six==1.17.0
tomli==2.2.1
toolz==1.0.0
typing_extensions==4.13.0
tzdata==2025.2
yarl==1.18.3

name: phc-sdk-py
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - aiohappyeyeballs==2.6.1
      - aiohttp==3.11.14
      - aiosignal==1.3.2
      - async-timeout==5.0.1
      - attrs==25.3.0
      - backoff==1.10.0
      - cov-core==1.15.0
      - coverage==7.8.0
      - exceptiongroup==1.2.2
      - frozenlist==1.5.0
      - funcy==2.0
      - idna==3.10
      - iniconfig==2.1.0
      - lenses==1.2.0
      - multidict==6.2.0
      - nest-asyncio==1.6.0
      - nose==1.3.7
      - nose-cov==1.6
      - numpy==2.0.2
      - packaging==24.2
      - pandas==2.2.3
      - phc==0.16.0
      - pluggy==1.5.0
      - propcache==0.3.1
      - pyjwt==2.10.1
      - pytest==8.3.5
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - six==1.17.0
      - tomli==2.2.1
      - toolz==1.0.0
      - typing-extensions==4.13.0
      - tzdata==2025.2
      - yarl==1.18.3
prefix: /opt/conda/envs/phc-sdk-py

tests/test_fhir_dsl_query.py::test_add_patient_id_with_bool_must_query
tests/test_fhir_dsl_query.py::test_no_modification tests/test_fhir_dsl_query.py::test_throws_with_non_elasticsearch_where tests/test_fhir_dsl_query.py::test_add_patient_ids_with_no_where_clause tests/test_fhir_dsl_query.py::test_add_patient_id_with_query_term tests/test_fhir_dsl_query.py::test_add_patient_id_with_bool_should_query tests/test_fhir_dsl_query.py::test_add_single_patient_id_to_query tests/test_fhir_dsl_query.py::test_add_single_patient_id_with_prefix
phc/easy/query/fhir_dsl_query.py
phc/easy/query/fhir_dsl_query.py