Skip to content

OpenConceptLab/ocl_issues#2558 | Divert target-repo concept fetch to custom lookup source#41

Merged
snyaggarwal merged 1 commit into
mainfrom
issues#2558-divert-target-repo-fetch-to-lookup
Jun 4, 2026
Merged

OpenConceptLab/ocl_issues#2558 | Divert target-repo concept fetch to custom lookup source#41
snyaggarwal merged 1 commit into
mainfrom
issues#2558-divert-target-repo-fetch-to-lookup

Conversation

@paynejd
Copy link
Copy Markdown
Member

@paynejd paynejd commented Jun 3, 2026

Fixes the symptom in ocl_issues#2558. @snyaggarwal for review.

⚠️ Not 100% certain this is the right approach — posting for your judgment. The diagnosis is solid; the fix location/shape is the open question (see below). Happy to move it elsewhere or scope it differently.

Problem

When a map project uses a custom lookup source because its target repo is a definition/metadata-only canonical repo (e.g. the public WHO ICD-11-WHO repo, kept content-empty under WHO's license), some concept-detail GETs still hit the empty target repo and 404.

ensureLoaded resolves not-yet-full ConceptDefinitions two ways:

  • Branch 2 (no ocl_url$resolveReference) already honors lookupConfig.url.
  • Branch 1 (has ocl_url → direct GET) fetched the ocl_url verbatim, never consulting lookupConfig.

ocl-bridge / ocl-ciel-bridge cascade targets resolve against the target repo (concept_identity.cascade_target.reference_source: 'target_repo') and arrive with an ocl_url that points into the target repo → they take Branch 1 → fetch the empty repo → 404.

Evidence

ICD-11 IMO eval run (target WHO/ICD-11-WHO, lookup OpenMRS-OCL-Squad/ICD-11-WHO-Mapper): 6 GETs hit /orgs/WHO/sources/ICD-11-WHO/concepts/<code>/ and 404'd; the same codes return 200 from the lookup source. Failing URLs were not double-encoded → confirms Branch 1 (only Branch 2 double-encodes). The fetch is state-driven (mergeIntoRowMatchStateensureLoaded on not-full arrival), not triggered by opening the details panel.

Change

In Branch 1, when the concept belongs to the target repo and a lookup source is configured, fetch the lookup source by code instead of the target-repo ocl_url:

const tr = ctx?.target_repo
const divertedUrl = (lookupConfig?.url && tr && conceptBelongsToTargetRepo(def, tr.canonical_url, tr.relative_url))
  ? buildLookupConceptUrl(lookupConfig.url, def.reference?.code)
  : null
directFetches.push({key, oclUrl: divertedUrl || def.ocl_url})
  • Reuses the existing conceptBelongsToTargetRepo predicate (canonical-equal OR ocl_url starts with the target relative URL) rather than a hand-rolled equality.
  • New buildLookupConceptUrl (normalizers) shares the Branch 2 double-encode so a code resolves to the same URL on both paths. Pure + unit-tested.
  • fetchConceptByOclUrl's existing URL-dedup + 404-retry apply unchanged.

npm test 145/145, eslint clean.

Why no server-side change

WHO/ICD-11-WHO being empty is by design (definition-only canonical repo, WHO license). Content lives in the lookup source. So this is purely client-side routing.

Open questions for review (the "not certain" parts)

  1. Right layer? This fixes the direct-fetch branch in ensureLoaded. Should the diversion instead live where the cascade-target ConceptDefinition.ocl_url is minted (normalizers cascadeTargetToConceptDefinition), so the stub never carries a target-repo ocl_url in the first place? That might be the more principled fix.
  2. Scope. The predicate diverts all target-repo concepts, not just bridge cascade targets. Standard $match candidates already carry a lookup-source ocl_url, so rebuilding lands at the same place (harmless) — but confirm that's acceptable vs. narrowing to bridge targets only.
  3. Versioning. I deliberately fetch lookupConfig.url as configured and don't graft the target's pinned version onto it (matches Branch 2). Correct for your intended semantics?
  4. Relation to #2515 ("separate lookup sources per algorithm / fallback to target repo") — should this fold into that work instead of landing standalone?

Background analysis (HAR forensics + repro) lives in the ocl-mapper-eval 2026-06-02-imo-prepub run notes; happy to share.

…custom lookup source

ensureLoaded's direct-fetch branch fetched a concept's ocl_url verbatim, so
concepts resolving to the project's target repo -- notably ocl-bridge cascade
targets, whose ocl_url points into the target repo -- were fetched from the
target repo even when a custom lookup source is configured. When the target
repo is definition-only (e.g. the public WHO ICD-11 repo, kept content-empty
under WHO's license), those GETs 404.

Divert the direct fetch to the configured lookup source when the concept
belongs to the target repo, reusing the existing conceptBelongsToTargetRepo
predicate. Branch 2 ($resolveReference) already honored lookupConfig.url; this
brings the direct-fetch branch in line. Adds buildLookupConceptUrl (shares the
Branch 2 double-encode) + unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@snyaggarwal
Copy link
Copy Markdown
Contributor

  1. I feel ensureLoaded is the right place for this fix, we dont want to change ConceptDefinition. Also if/when tomorrow we have license it should work with existing definitions
  2. Its ok.
  3. Yes thats correct
  4. That should be separate work

@snyaggarwal
Copy link
Copy Markdown
Contributor

LGTM, merging

@snyaggarwal snyaggarwal merged commit 77b92f5 into main Jun 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants