microsoft / microsoft/fhir-server
Export operation fails to parse _typeFilter with OR search expression
Nobody has claimed this yet.
- Dominant language
- TSQL
- Stars
- 1.4k
- Forks
- 592
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 41
Description
**Describe the bug**
When trying to `$export` data using a `_typeFilter` which contains an OR search expression, the `The _typeFilter segment '{0}' could not be parsed.` error is returned.
E.g. when `_typeFilter` contains the 2 expressions below (separated with a comma):
```http
GET /Observation?combo-code=sys1|code1,sys2|code2
GET /Patient?_has:Observation:patient:combo-code=sys1|code1,sys2|code2
```
**FHIR Version?**
Stu3/R4/R5
**Data provider?**
CosmosDB/SQL Server
**To Reproduce**
Steps to reproduce the behavior:
1. Start export operation
```http
GET /$export?_type=Patient,Observation&_typeFilter=Observation?combo-code=sys1|code1,sys2|code2,Patient?_has:Observation:patient:combo-code=sys1|code1,sys2|code2
```
**Expected behavior**
Export operation successfully started, and resources matching either of the queries are exported.
**Actual behavior**
Request fails with `400 Bad Request` with a message: `The _typeFilter segment '{0}' could not be parsed.`
**Fix suggestion**
Relevant source: [src/Microsoft.Health.Fhir.Core/Features/Operations/Export/CreateExportRequestHandler.cs#L119-L157](https://github.com/microsoft/fhir-server/blob/main/src/Microsoft.Health.Fhir.Core/Features/Operations/Export/CreateExportRequestHandler.cs#L119-L157)
```javascript
// This is TypeScript, just to illustrate the idea
const typeFilter: string[] = [];
if (typeFilterCsv) {
let queryStart = 0;
let lastComma = -1;
for (let i = 0; i < typeFilterCsv.length; i++) {
const char = typeFilterCsv[i];
if (char == ',') {
lastComma = i;
} else if (char == '?') {
if (lastComma == -1) {
continue;
}
const query = typeFilterCsv.substring(queryStart, lastComma);
typeFilter.push(query);
queryStart = lastComma + 1;
} else {
continue;
}
}
const query = typeFilterCsv.substring(queryStart);
typeFilter.push(query);
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/Microsoft.Health.Fhir.Core/Features/Operations/Export/CreateExportRequestHandler.cs around lines 119-157 and trace how _typeFilter segments are split. Reproduce the supplied $export request with comma-separated OR expressions, then verify that the operation starts successfully and accepts both resource queries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100