great-crayon-86888
11/04/2023, 2:54 PMchilly-king-10285
11/04/2023, 2:54 PMchilly-king-10285
11/04/2023, 2:54 PMtypescript import { Namespace, Context } from "@ory/keto-namespace-types" class Appointment implements Namespace { // All relationships for a single appointment. related: { creators: User[] deleters: User[] updaters: User[] } // The permissions derived from the relationships and context. permits = { create: (ctx: Context): boolean => this.related.creators.includes(ctx.subject), delete: (ctx: Context): boolean => this.related.deleters.includes(ctx.subject), update: (ctx: Context): boolean => this.related.updaters.includes(ctx.subject), } } class Patient implements Namespace { // All relationships for a single patient. related: { refundAdders: User[] caseManagers: User[] appAccessors: User[] caseCreators: User[] authorizationCreators: User[] } // The permissions derived from the relationships and context. permits = { addRefund: (ctx: Context): boolean => this.related.refundAdders.includes(ctx.subject), accessCaseManagement: (ctx: Context): boolean => this.related.caseManagers.includes(ctx.subject), accessPatientApp: (ctx: Context): boolean => this.related.appAccessors.includes(ctx.subject), createClinicalCase: (ctx: Context): boolean => this.related.caseCreators.includes(ctx.subject), createAuthorization: (ctx: Context): boolean => this.related.authorizationCreators.includes(ctx.subject), } } // Similar classes can be created for Billing and Claims modules
This is a simplified example and you might need to adjust it according to your specific needs. The User[]
array should contain the users who have the respective permissions. The permits
object defines the permissions for each module. Each permission is a function that checks if the user (the subject
) is included in the respective array of users who have that permission. For more details on how to define a permission model, you can refer to the [Ory documentation](https://www.ory.sh/docs/keto/modeling/create-permission-model). For more information on the Ory Permission Language, you can read the [OPL specification](https://www.ory.sh/docs/keto/reference/ory-permission-language).great-crayon-86888
11/04/2023, 3:19 PMchilly-king-10285
11/04/2023, 3:19 PMchilly-king-10285
11/04/2023, 3:20 PMgreat-crayon-86888
11/04/2023, 11:20 PMchilly-king-10285
11/04/2023, 11:20 PMchilly-king-10285
11/04/2023, 11:20 PMUser
class should also implement a Namespace
. This is shown in the examples provided in the extracts. Here's a simplified example: typescript import { Namespace, Context } from "@ory/keto-namespace-types" class User implements Namespace {}
In this context, User
is a namespace that scopes objects and subjects. It can contain rules that define which relationships are looked up as part of a permission check. For more details, you can refer to the [Ory documentation on namespaces](https://www.ory.sh/docs/keto/concepts/namespaces).