fhir-router & mock server routes, resources, opera...
# support
j
Hi team! apologies if this isn't tagged correctly in discord 😅 We've set up a mock server using the
@medplum/fhir-router
(similar to how the mock client is set up) in our development environment as we explore Medplum's FHIR server capabilities. We have it running at
/mock
in development, and we noticed what seem like intentional omissions from the functionality of the handlers. I found the original discussion (https://github.com/medplum/medplum/discussions/1218) so I'm curious about the intentions behind this (i.e. does this handle everything it is intended to as a facade?). Here's some of the things we tried: 1. It stores a Bundle as a Bundle and doesn't decompose it - can't search for the Patient or EOB resource after storing 2. Regular search parameters don't seem to work - searched localhost:3001/mock/Patient?given=Wellington and it returned all Patients in a Bundle 3. _security doesn't seem to work - searched localhost:3001/mock/Patient?_security=test|R and other variations and it returned the same Bundle regardless 4. _include doesn't seem to work - searched localhost:3001/mock/ExplanationOfBenefit?_include:* and other variations and it returned the same Bundle regardless 5. $everything is not implemented (404) These are just the first things we thought to test. If they're out of scope for the fhir-router package, that's totally fine, just wanted to confirm. Thanks!
to get into the weeds a bit more, in my testing I did see that the filter objects were being constructed correctly from the search parameters and correctly added to the search request objects
c
Hey @jakxz - great questions. You're really getting into the guts of things! > so I'm curious about the intentions behind this (i.e. does this handle everything it is intended to as a facade?). Here's some of the things we tried: First, within
@medplum/fhir-router
I'll make a distinction between: 1.
FhirRouter
which is stable, robust, and used in production 2.
MemoryRepository
which primarily exists for unit tests and Storybook (i.e., https://storybook.medplum.com) You're right that
MemoryRepository
has a number of limitations, and is not as complete as the main
Repository
implementation in
@medplum/server
One implementation detail to be aware of is that the behavior of
MemoryRepository
depends on whether
StructureDefinition
and
SearchParameter
resources have been loaded. On server side, you can load everything like this:
Copy code
indexStructureDefinitionBundle(readJson('fhir/r4/profiles-types.json') as Bundle);
indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);
indexStructureDefinitionBundle(readJson('fhir/r4/profiles-medplum.json') as Bundle);
indexSearchParameterBundle(readJson('fhir/r4/search-parameters.json') as Bundle<SearchParameter>);
indexSearchParameterBundle(readJson('fhir/r4/search-parameters-medplum.json') as Bundle<SearchParameter>);
That will fix a bunch of the search parameter issues you're seeing. To be candid, we've been very surprised by the community usage of
MemoryRepository
and
MockClient
. We're trying to add more capabilities, move more functionality out of
server
into
fhir-router
, but that's slow. If you have a particular use case for it, let us know, and we'd be happy to go into more details.
r
I'll just add on, we have some docs on how to use the MockCLient for testing Bots here: https://www.medplum.com/docs/bots/unit-testing-bots#set-up-your-test-framework
j
Thanks @cody and Rahul - we're not using bots just yet but I'll give that a look if we do. I've tried loading the json bundles as you've described but not having any luck yet. going into a meeting soon but I'll try to share some more after the weekend*
158 Views