Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting supported to extension fields? #3616

Closed
Sameer2810 opened this issue Dec 6, 2023 · 11 comments
Closed

Sorting supported to extension fields? #3616

Sameer2810 opened this issue Dec 6, 2023 · 11 comments
Labels
Question Issue is a question?

Comments

@Sameer2810
Copy link

Sameer2810 commented Dec 6, 2023

Question

Does sorting supported for extension fields

Tasks

No tasks being tracked yet.
@Sameer2810 Sameer2810 added the Question Issue is a question? label Dec 6, 2023
@Sameer2810 Sameer2810 changed the title Sorting supported to extension fields Sorting supported to extension fields? Dec 6, 2023
@brendankowitz
Copy link
Member

Hi @Sameer2810. Under Health Data Services/SQL you can sort on string and date search parameters, so if you create a custom search parameter for the extension (then reindex) it would work.
Under ApiForFHIR/Cosmos, it supports creating the custom search parameter, but adding the capability to have it sortable would need a support ticket since that part isn't self-service.

@Sameer2810
Copy link
Author

Sameer2810 commented Dec 11, 2023

Hi @brendankowitz I have created Health Data Services and in that I have added ImagingStudy with date extension and perform reindex on that. The extension field (date field) is now searchable but for sorting it is not giving any result.

Example - fhirurl/ImagingStudy?customdate={actual date}

For searching above is working

Example - fhirurl/ImagingStudy?_sort=customdate

Is above correct or I am missing something here

@EXPEkesheth
Copy link
Collaborator

@Sameer2810 - can you please help clarify if you are getting empty response or result with resources but not sorted?

@Sameer2810
Copy link
Author

Sameer2810 commented Dec 12, 2023

@EXPEkesheth - I am getting empty response below is screen shot for that

image

@mikaelweave
Copy link
Contributor

@Sameer2810 - can you provide the expression for the SearchParameter resource you added for the custom search to drive the sorting?

@Sameer2810
Copy link
Author

@mikaelweave following is the expression

ImagingStudy.extension.where(url = 'CreatedDate').value

@mikaelweave
Copy link
Contributor

mikaelweave commented Dec 12, 2023

@Sameer2810 - The url for the extension is of type uri which must be in a certain format defined in RFC3986. Maybe this is causing the issue?

I'd suggest using a SearchParameter like below. I don't have time to test this now but this is what I'd try.

Also if there are other ways to capture this data without a custom extension I've found that best. For example, if ImagingStudy resources are always part of Procedure resources, you could maybe use Procedure.recorded and a chained search? This may not apply to your scenario but a good think to keep in mind.

{
    "resourceType" : "SearchParameter",
    "id" : "resource-created-date",
    "url" : "http://mycompany.org/fhir/SearchParameter/resource-created-date",
    "version" : "1.0.0",
    "name" : "ResourceCreatedDate",
    "status" : "active",
    "date" : "2023-12-12",
    "publisher" : "My Company",
    "description" : "Returns the created date on resources.",
    "code" : "CreatedDate",
    "base" : [
      "DomainResource"
    ],
    "type" : "date",
    "expression" : "DomainResource.extension.where(url='http://mycompany.org/fhir/StructureDefinition/resource-created-date').value"
  }

@Sameer2810
Copy link
Author

@mikaelweave I did that what you mentioned, getting result but for some reason sorting not applied on result (for date type)

Also when I try with string type extension sorting applied to result (note - It gives result for those record which don't have that extension)

@Sameer2810
Copy link
Author

@mikaelweave and @EXPEkesheth Can you suggest further action

@mikaelweave
Copy link
Contributor

mikaelweave commented Dec 21, 2023

@Sameer2810 - there was an error in the custom search parameter I posted. I updated the above comment and verified it works locally. Make sure the expression is correct and you remove the old search parameter first. Make sure to reindex and that all of your resources get reindexed by inspecting the response.

I find it easier to test on querying the data first vs sorting to ensure the custom search parameter is getting applied correctly (e.g. https://{{hostname}}/Patient?CreatedDate=gt2020-01-1).

Also check out the examples in the linked PR - you can use the :missing=false query parameter to only return resources that have the extension.

@EXPEkesheth
Copy link
Collaborator

Thanks @mikaelweave for addressing the questions! @Sameer2810 - closing this as no further comments post Dec 21st. Please feel free to re-open the issue, if the issue is not addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Issue is a question?
Projects
None yet
Development

No branches or pull requests

4 participants