@medplum/core: isResourceType() is broken
# support
z
isResourceType(resourceType)
from the
core
package seems to be broken. Its documentation gives this as an example:
isResourceType('Patient')
. However, running that in my Foo Medical-based app returns undefined. Digging into it, it appears to depend on the
core/src/base-schema.json
file, which doesn't seem to include a "Patient" entry. Am I using this function wrong?
i
@Zira , you need to pass the json representation of a resource into that method.
instead of 'Patient' you would pass something like
Copy code
{
  "resourceType": "Patient",
  "name": [
    {
      "family": "Test",
      "given": [
        "Patient"
      ]
    }
  ],
  "id": "d462f407-48c4-4f33-876a-b549b683fc21",
  "meta": {
    "versionId": "e6456ff9-7808-4498-8b73-3dd44542f152",
    "lastUpdated": "2025-11-18T18:26:07.563Z",
    "author": {
      "reference": "Practitioner/0194702a-c167-740d-8e95-f7c9338de5c5",
      "display": "Ian Plunkett"
    },
    "project": "0194702a-c12f-77bb-9109-7510aff58757",
    "compartment": [
      {
        "reference": "Project/0194702a-c12f-77bb-9109-7510aff58757"
      },
      {
        "reference": "Patient/d462f407-48c4-4f33-876a-b549b683fc21"
      }
    ]
  }
}
z
Hi Ian, thanks for your response. I don't think that's correct. I believe your example object would be used for the
isResource()
method which accepts an
unknown
value. The
isResourceType()
function I'm talking about is in
packages/core/src/typeschema/types.ts
. It accepts a string called "resourceType"
i
🤦‍♂️ sorry about that. I misread it initially. The
isResourceType
function requires the FHIR schema to be loaded first, but it's not automatically initialized when you import
@medplum/core.
To test it out, you could do something like this directly from node
Copy code
const medplumCore = require('@medplum/core');
const fhirDefinitions = require('@medplum/definitions');

// Load the FHIR structure definitions
const structureDefs = fhirDefinitions.readJson('fhir/r4/profiles-resources.json');

// Index the schema
medplumCore.indexStructureDefinitionBundle(structureDefs);

// Now you can use isResourceType
const { isResourceType } = medplumCore;
console.log(isResourceType('Patient')); // true
console.log(isResourceType('Invalid')); // false
This assumes you are running node from the base of the medplum directory and you have run build on the repo
48 Views