Repository navigation
Report a filter a code system can't do as a 4xx, not 500 - #383
Conversation
LOINC, SNOMED CT, RxNorm, NDC, CPT and the country, currency and area code providers threw a plain Error from filter() for a filter they don't support or a filter value they can't use (e.g. LOINC_NUM regex, SNOMED CT code regex). $expand reported that as a 500 with a stack trace. A property or operator a provider doesn't support now throws the Issue the ICD-11 provider does (not-supported, FILTER_NOT_UNDERSTOOD, 422). A supported filter whose value can't be used (SNOMED CT "Invalid concept ID" / "Invalid filter value", country "Invalid regex pattern") is 400 invalid / vs-invalid, as for an unknown SNOMED CT concept in a filter. The messages are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Whether a filter value naming an unknown or malformed concept is an error or is dropped is still open, so SNOMED CT "Invalid concept ID" / "Invalid filter value" and country "Invalid regex pattern" go back to the plain Error they are on main. SNOMED CT checked the value before the operator, so an unsupported operator with a value that isn't a concept id (concept regex 1234.*) was still a 500. The concept, inactive, moduleId and attribute filters now turn down an operator they don't support before looking at the value: 422 not-supported, FILTER_NOT_UNDERSTOOD. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I've narrowed this PR to the part nobody disputes: a filter property or operator a code system doesn't support now gets 422 not-supported |
|
Thanks, the direction is right, and doing the SNOMED CT operator check before the value is a good catch. A few things before merging:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Every provider that refuses a filter it can't do now reports FILTER_NOT_UNDERSTOOD with the message from the messages file (i18n.translate with prop, op, value), not hard-coded English - UCUM, OMOP, mime types, BCP-47 and HGVS now refuse an unsupported property or operator as a 422 not-supported issue, not a plain Error (500). HGVS inherits the base getPrepContext so its filter() is reached - cs-cs.js and cs-icf.js: issue code not-supported instead of exception - ICD-11's existing refusal uses the translated message too Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. Done; upstream main merged in (merge commit), new commits on top.
Tests: each newly covered provider has a test for an unsupported filter (422, |
Problem
A
$expandwhose compose uses a filter the code system doesn't support gets an HTTP 500 and a stack trace in the log, as if the server had failed. The request is what's wrong, and the tx-ecosystem IG says so: "A filter the server does not understand, or a filter with no value where one is required, SHALL produce an error - not an empty or a partial expansion" (requirements). The cause:filter()in several providers throws a plainError, and the$expandhandler maps anything that isn't anIssueto 500. ($validate-codechecksdoesFilter()first and already answers 400FILTER_NOT_UNDERSTOOD.$expandcallsfilter()directly.)Repro, on a server with LOINC, SNOMED CT and RxNorm loaded:
LOINC_NUM regex .*code regex 1234.*code regex 1.*language regex enError; not measured)concept = 1234.*,inactive = maybeChange
Where
filter()turns down a property or operator in LOINC, SNOMED CT, RxNorm, NDC, CPT, UCUM, OMOP, mime types, BCP-47, HGVS and the country, currency and area code providers, it now throws the issuecs-cs.jsthrows for a filter it doesn't understand, with the translated message:cs-cs.jsandcs-icf.jsused issue codeexceptionfor this; they now usenot-supported. ICD-11's existing refusal now uses the translated message instead of hard-coded English.HGVS threw "Filters are not supported" from
getPrepContext(), which$expandcalls beforefilter(). It now inherits the basegetPrepContext(), andfilter()refuses the filter.SNOMED CT's
concept,inactive,moduleIdand attribute filters checked the value before the operator, soconcept regex 1234.*failed as "Invalid concept ID". They now check the operator first.Bad filter values (e.g. an unknown or malformed SNOMED concept id) are left as they are: whether they are an error or dropped is being discussed (Filter on an invalid Concept, and #357). So SNOMED CT "Invalid concept ID" and "Invalid filter value", country "Invalid regex pattern", an invalid mime type
base, an unknown BCP-47 subtag and BCP-47existswith a value other than true/false still throw the plainErrorthey throw on main.LOINC, RxNorm, NDC, CPT, OMOP, currency and area code each have one catch-all that turns down any filter they can't do, and that becomes the 422. The 422 is the status
$expandalready uses for this error (ICD-11,cs-cs.js, supplement filters);$validate-codestill answers 400 from itsdoesFilter()check. Only the error paths infilter()change. ECL errors (constraint =) and the other plainErrors in these files aren't touched.Tests
cause: 'not-supported',msgId: 'FILTER_NOT_UNDERSTOOD',statusCode: 422and the translated message.STY regex) incs-rxnorm-filtersvariant = xcs-cs: an unknown property gives 422 not-supportedtests/tx/expand.test.js: a countrydisplay regexand a BCP-47language regexfilter give 422 not-supported with the translated messagetests/cs: 41 suites passed, 5 skipped (1,547 tests passed, 80 skipped).tests/tx: 131 suites, 6,970 tests passed, 7 skipped.test-cases.test.js: 5,251 passed.🤖 Generated with Claude Code