Placeholder Reference Using FHIR Types
# support
j
I'm using typescript and the @medplum/fhirtypes to create a relationship between two organizations using the
partOf
reference. It is possible that both will be created at the same time, so I want to commit them both as part of the same transaction. I understand that Placeholder IDs using `BatchEntry`'s
fullUrl
and a reference that uses the
urn:uuid
string can handle this. However, with the FHIR types, the type enforcement requires a
Reference<ResourceType>
. How can I set the
partOf
attribute on the Organization to the Placeholder ID? So, basically something like:
Copy code
const entries: BundleEntry[] = []
const parentOrgPlaceholderId = `urn:uuid:61ebe359-bfdc-4613-8bf2-c5e300945f0a`

const parentOrg: Organization = {
  resourceType: 'Organization',
  name: 'Parent Org'
}

entries.push({
  parentOrg,
  fullUrl: parentOrgPlaceholderId,
  request: {
    url: parentOrg.resourceType,
    method: 'POST'
})

const childOrg: Organization = {{
  resourceType: 'Organization',
  name: 'Parent Org'
  partOf: ??????? <-- This requires a Reference<Organization> type I want to use { reference: parentOrgPlaceholderId } 
}

entries.push({
  childOrg,
  request: {
    url: childOrg.resourceType,
    method: 'POST'
})

await medplumClient.executeBatch({
  resourceType: 'Bundle',
  type: 'transaction',
  entry: entries
})
I just ended up creating an enhanced
createReference
function:
Copy code
export function createReferenceWithPlaceholder<T extends Resource>(
  resource: T,
  overrideReference?: string
): Reference<T> & { reference: string } {
  const reference =
    overrideReference ?? getReferenceString(resource) ?? 'undefined/undefined'
  const display = getDisplayString(resource)

  return display === reference ? { reference } : { reference, display }
}
i
@Jim Fiorato if you are still having issues, here's a little script that batch inserts the parent/child organizations using partOf with a reference
343 Views