Skip to main content

Writing Resources

Creating Resources

To create a resource, construct the object and then call the API.

const father = new Resources.r4.FamilyMemberHistory(patientId, "Father");
father.name = "John";

await plasma.create<r4.FamilyMemberHistory>(father);
tip

For help with constructing resources, see the Resources page.

Create Multiple Resources

If you want to create multiple resources at once, there is a shortcut method for this that takes an array of resources of the same type.

tip

If you need to create multiple resources of different types, take a look at the Bundle documentation.

const father = new Resources.FamilyMemberHistory(patientId, "Father");
father.name = "John";

const mother = new Resources.FamilyMemberHistory(patientId, "Mother");
mother.name = "Mary";

const family = [father, mother];

const bundle: r4.Bundle = await plasma.createResources<r4.FamilyMemberHistory>("FamilyMemberHistory", family);

Updating Resources

To update a resource, ensure that the object you are passing already exists and has an Id.

myFamilyMember.name = "J";
await plasma.update<r4.FamilyMemberHistory>(myFamilyMember);

Deleting Resources

To delete a resource, ensure that the object you are passing already exists and has an Id. You can either pass in the object itself or only the ID to delete the object.

Delete by Object

await plasma.delete<r4.FamilyMemberHistory>(myFamilyMember);

Delete by ID

await plasma.deleteById("FamilyMemberHistory", myFamilyMember.id);