Are system-level custom FHIR operations supported?
# support
g
It seems that system-level custom FHIR operations (e.g. /fhir/R4/$my-custom-operation) are not currently supported. The FHIR router request handler evaluates a system-level operation as invalid, instead of not-found:
Copy code
{
  "resourceType": "OperationOutcome",
  "issue": [
    {
      "severity": "error",
      "code": "invalid",
      "details": {
        "text": "Incorrect resource type: expected $my-custom-operation, but found <EMPTY>"
      }
    }
  ]
}
Which doesn't [match the condition](https://github.com/medplum/medplum/blob/main/packages/server/src/fhir/routes.ts#L439-L444) to try the custom operation. Is this a known issue?
f
Hmm, could you send your OperationDefinition?
It could be a misconfiguration of your [OperationDefinition](https://www.medplum.com/docs/api/fhir/resources/operationdefinition)'s type, system or instance which determines where in your FHIR url
$my-custom-operation
should be
g
I'm creating the
OperationDefinition
with the following body:
Copy code
{
  "resourceType": "OperationDefinition",
  "code": "my-custom-operation",
  "name": "my-custom-operation",
  "kind": "operation",
  "system": true,
  "type": false,
  "instance": false,
  "status": "active",
  "extension": [
    {
      "url": "https://medplum.com/fhir/StructureDefinition/operationDefinition-implementation",
      "valueReference": {
        "reference": "Bot/80935fcc-9c24-4e3c-9851-8cce613f71ca"
      }
    }
  ]
}
If I then try to exectute the operation with a
POST /fhir/R4/$my-custom-operation
I get a Bad Request with:
Copy code
{
  "resourceType": "OperationOutcome",
  "issue": [
    {
      "severity": "error",
      "code": "invalid",
      "details": {
        "text": "Incorrect resource type: expected $my-custom-operation, but found <EMPTY>"
      }
    }
  ],
  "extension": [
    {
      "url": "https://medplum.com/fhir/StructureDefinition/tracing",
      "extension": [
        {
          "url": "requestId",
          "valueId": "605722d4-4890-4530-a1a0-d44b698b9d68"
        },
        {
          "url": "traceId",
          "valueId": "bc8aa396-b1a1-45db-8355-5d3165e98b76"
        }
      ]
    }
  ]
}
Do you see anything wrong with the OperationDefinition @finnbergquist ?
r
The OperationDefinition should have a base resource, for example Patient/$everything vs being a free standing function.
g
But if you want it to be a system-level operation, .e.g .
/$my-custom-operation
, what would be the base resource in that case @reshma ?
f
Hi @Gonzalo , unfortunately that is not supported at the moment
g
Oh, ok. @finnbergquist are there any plans to support this? Also, please note that [the docs](https://www.medplum.com/docs/bots/custom-fhir-operations#operation-types) for custom FHIR operation state that system-level operation are supported.
f
Hey @Gonzalo , You are welcome to file an issue or open a PR to support this. Otherwise, the workaround would be making it a
type
level operation,
g
Sure! I think supporting system-level operations in a desirable feature, specially when some operation don't really apply to any specific resource and are more system-wide. Thanks for the responses.
f
Agreed!
n
@Gonzalo I haven't set up bots locally so I'm not able to validate and submit but it may be as simple as this- https://github.com/medplum/medplum/compare/main...nate-watkins:system-level-custom-operations?expand=1
g
Amazing! I will test. Thanks
Thanks @nathan-watkins-unityai Created the PR https://github.com/medplum/medplum/pull/8258 You did all the work, really. I just added some coverage and tested it functionally 😉 Hopes this gets merged soon!
n
Nice- wouldn’t be surprised if they suggest a more explicit implementation (than the immediate
notFound
like I had) but looking forward to system level operations!
45 Views