Search…
Object Types
Sub-classing objects
In your data modeling, you may find that you want to define an object class that inherits all properties from another. For example, you might have a generic c_assessment class with properties like c_patient and more specific classes like c_blood_test that has all the properties of c_assessment but also a set of more specific properties like c_blood_type.
To create an object type, you simply add the object type definitions into the objectTypes array of an object's definition. These types will inherit all the properties from the super-class (or super-type).
The properties that define an object type are as follows:

Object Type Properties

Name
Type
Description
name
String
The API name for the object type
label
String
The human readable label for the object type
properties
Property Definition Array
The array of property definitions for properties specific to this object type
Once an object type is defined, the type property becomes required when creating instances of the object. The type property is populated with the name of the object type you are creating.

Examples

In this example, we've created the object class c_assessment and set the proper ACL's. We've also added a property to this object that all of this object's types will share: c_patient. This is because all assessments will be made on a particular patient, no matter what kind of assessment it is.
Request
Assessment Object Definition
1
GET /objects/5951719d514ef101000216cf
Copied!
1
{
2
"_id": "5951719d514ef101000216cf",
3
"access": 7,
4
"allowConnections": true,
5
"allowTransfers": true,
6
"connectionOptions": {
7
"requireAccept": true,
8
"requiredAccess": 5,
9
"sendNotifications": true
10
},
11
"createAcl": [
12
{
13
"_id": "5951719dfc65ed0100e62068",
14
"allow": 1,
15
"target": "000000000000000000000003",
16
"type": 1
17
}
18
],
19
"created": "2017-06-26T20:42:05.183Z",
20
"creator": {
21
"_id": "5771495a1d0c03a53ce83f1a",
22
"object": "account",
23
"path": "/accounts/5771495a1d0c03a53ce83f1a"
24
},
25
"defaultAcl": [
26
{
27
"_id": "5951719dfc65ed0100e62069",
28
"allow": 7,
29
"target": null,
30
"type": 4
31
}
32
],
33
"favorite": false,
34
"feedDefinition": [],
35
"label": "Assessment",
36
"lookup": "5951719d514ef101000216cf",
37
"name": "c_assessment",
38
"object": "object",
39
"objectTypes": [],
40
"pluralName": "c_assessments",
41
"properties": [
42
{
43
"_id": "595171e811f6710100683480",
44
"acl": [],
45
"auditable": false,
46
"autoCreate": false,
47
"cascadeDelete": true,
48
"creatable": false,
49
"expandable": true,
50
"grant": 0,
51
"indexed": true,
52
"label": "Patient",
53
"name": "c_patient",
54
"optional": false,
55
"pacl": [],
56
"paths": [],
57
"readAccess": 4,
58
"readable": true,
59
"referenceAccess": 5,
60
"removable": false,
61
"sourceObject": "account",
62
"type": "Reference",
63
"unique": false,
64
"validators": [
65
{
66
"_id": "595171e811f6710100683481",
67
"name": "required"
68
}
69
],
70
"writable": true,
71
"writeAccess": 6
72
}
73
],
74
"shareChain": [
75
5,
76
4,
77
2
78
],
79
"updated": "2017-06-26T20:43:21.022Z",
80
"updater": {
81
"_id": "5771495a1d0c03a53ce83f1a",
82
"object": "account",
83
"path": "/accounts/5771495a1d0c03a53ce83f1a"
84
}
85
}
Copied!
You'll notice that the objectTypes value in the JSON result above is an empty array. We're going to add a c_blood_test object type to this array.
Request
Object Type Request Body
1
POST /objects/5951719d514ef101000216cf/objectTypes
Copied!
1
{
2
"label":"Blood Test",
3
"name":"c_blood_test",
4
"properties": [
5
{
6
"label":"Blood Type",
7
"name":"c_blood_type",
8
"type": "String",
9
"validators": [
10
{
11
"name": "required"
12
}
13
]
14
}
15
]
16
}
Copied!
Now, the objectTypes array contains the c_blood_test definition we just created.
Request
objectTypes array
1
GET /objects/5951719d514ef101000216cf/objectTypes
Copied!
1
{
2
"data": [
3
{
4
"_id": "5951751611f6710100683fdc",
5
"label": "Blood Test",
6
"name": "c_blood_test",
7
"properties": [
8
{
9
"_id": "5951751611f6710100683fdd",
10
"acl": [],
11
"array": false,
12
"auditable": false,
13
"canPull": true,
14
"canPush": true,
15
"creatable": false,
16
"indexed": false,
17
"label": "Blood Type",
18
"lowercase": false,
19
"maxItems": 100,
20
"maxShift": false,
21
"minItems": 0,
22
"name": "c_blood_type",
23
"optional": false,
24
"readAccess": 4,
25
"readable": true,
26
"removable": false,
27
"trim": false,
28
"type": "String",
29
"unique": false,
30
"uniqueValues": false,
31
"uppercase": false,
32
"validators": [
33
{
34
"_id": "5951751611f6710100683fde",
35
"name": "required"
36
}
37
],
38
"writable": true,
39
"writeAccess": 6,
40
"writeOnCreate": true
41
}
42
]
43
}
44
],
45
"hasMore": false,
46
"object": "list"
47
}
Copied!
We can now create a c_assessment object instance of type c_blood_test:
Request
Request Body
1
POST /c_assessments
Copied!
1
{
2
"c_patient":"5771495a1d0c03a53ce83f1a",
3
"type":"c_blood_test",
4
"c_blood_type":"Type A"
5
}
Copied!
The resulting instance of c_assessment is of type: c_blood_test and contains both the base property of c_patient and the c_blood_test type property c_blood_type.Request
Result
1
{
2
"_id": "59517718cfc40501006da501",
3
"access": 7,
4
"c_blood_type": "Type A",
5
"c_patient": {
6
"_id": "5771495a1d0c03a53ce83f1a",
7
"object": "account",
8
"path": "/accounts/5771495a1d0c03a53ce83f1a"
9
},
10
"created": "2017-06-26T21:05:28.068Z",
11
"creator": {
12
"_id": "5771495a1d0c03a53ce83f1a",
13
"object": "account",
14
"path": "/accounts/5771495a1d0c03a53ce83f1a"
15
},
16
"favorite": false,
17
"object": "c_assessment",
18
"owner": {
19
"_id": "5771495a1d0c03a53ce83f1a",
20
"object": "account",
21
"path": "/accounts/5771495a1d0c03a53ce83f1a"
22
},
23
"shared": false,
24
"type": "c_blood_test"
25
}
Copied!
Last modified 1mo ago