KevinIsInCoding claude[bot] KevinIsInCoding commited on
Commit
4c8ffca
Β·
unverified Β·
1 Parent(s): 083d098

fix: handle EAP+phase combinations in aggFilters search logic (#11)

Browse files

Implements all 5 search cases from issue #10:
1. Specific stages only β†’ phase:X Y
2. All stages incl. NA β†’ studyType:int
3. EAP only β†’ studyType:exp
4. EAP + specific stages β†’ studyType:exp,phase:X Y (combined filter)
5. EAP + all stages β†’ studyType:exp

Previously, EAP searches always ignored any phase preference. The fix
adds phase-aware branching inside the is_eap block, combining
studyType:exp with the numbered phase list when specific phases are
requested.

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: KevinIsInCoding <KevinIsInCoding@users.noreply.github.com>

Files changed (1) hide show
  1. clinical_trials_guru.py +17 -2
clinical_trials_guru.py CHANGED
@@ -328,12 +328,25 @@ def search_trials_api(
328
  "pageSize": 200, # max page size; we paginate until exhausted
329
  "format": "json",
330
  }
331
- # aggFilters accepts only one value; studyType and phase can't be combined.
332
  # RECRUITING status already excludes EAPs, so studyType:int is only needed
333
  # when no phase filter is applied. studyType:int returns all phases including N/A.
334
  # Observational studies use studyType:obs; phases don't apply to them.
 
 
 
 
 
 
 
335
  if is_eap:
336
- params["aggFilters"] = "studyType:exp"
 
 
 
 
 
 
337
  elif is_observational:
338
  params["aggFilters"] = "studyType:obs"
339
  elif phases:
@@ -343,8 +356,10 @@ def search_trials_api(
343
  if numbered:
344
  params["aggFilters"] = "phase:" + " ".join(numbered)
345
  else:
 
346
  params["aggFilters"] = "studyType:int"
347
  else:
 
348
  params["aggFilters"] = "studyType:int"
349
 
350
  _logger.info(
 
328
  "pageSize": 200, # max page size; we paginate until exhausted
329
  "format": "json",
330
  }
331
+ # aggFilters supports comma-separated keys (e.g. "studyType:exp,phase:3 4").
332
  # RECRUITING status already excludes EAPs, so studyType:int is only needed
333
  # when no phase filter is applied. studyType:int returns all phases including N/A.
334
  # Observational studies use studyType:obs; phases don't apply to them.
335
+ #
336
+ # Case matrix:
337
+ # EAP only β†’ studyType:exp
338
+ # EAP + specific phases β†’ studyType:exp,phase:X Y (combine both filters)
339
+ # EAP + all phases β†’ studyType:exp (no phase filter needed)
340
+ # Interventional, specific β†’ phase:X Y
341
+ # Interventional, all/NA β†’ studyType:int (returns NA trials too)
342
  if is_eap:
343
+ numbered = [p for p in (phases or []) if p != "na"]
344
+ if numbered:
345
+ # EAP + specific phases: combine studyType:exp with phase filter
346
+ params["aggFilters"] = "studyType:exp,phase:" + " ".join(numbered)
347
+ else:
348
+ # EAP only or EAP + all phases (no phase restriction)
349
+ params["aggFilters"] = "studyType:exp"
350
  elif is_observational:
351
  params["aggFilters"] = "studyType:obs"
352
  elif phases:
 
356
  if numbered:
357
  params["aggFilters"] = "phase:" + " ".join(numbered)
358
  else:
359
+ # Only "na" was requested β€” use studyType:int (all phases including N/A appear)
360
  params["aggFilters"] = "studyType:int"
361
  else:
362
+ # No phase preference β€” return all interventional studies including N/A phase
363
  params["aggFilters"] = "studyType:int"
364
 
365
  _logger.info(