Opal Schemas

Opal schemas provide a JSON representation of the structure of subrecords. Opal uses these schemas internally to construct the Item classes in AngularJS on the client side.

The Schema for an Opal application is available at the url /api/v0.1/record/ and contains the serialized representation of all subrecords and their fields.

Subrecord information

Individual subrecords are serialized to the schema using the function opal.core.schemas.serialize_model.

Schema Subrecord fields

Optional fields:

  class Colour(models.EpisodeSubrecord):
      _advanced_searchable = False
      _exclude_from_extract = True
      _angular_service = 'Colour'
      _icon = "fa fa-comments"
      name = dmodels.CharField(max_length=200)

# becomes:...
    'advanced_searchable': False,
    'angular_service': 'Colour',
    'display_name': 'Colour',
    'fields': [
      # field information as noted below
    'form_url': u'/templates/forms/colour.html',
    'icon': 'fa fa-comments',
    'name': 'colour',
    'single': False

Subrecord Field information

Opal makes the most out of the rich Django model interface by delivering much of the derivable metadata about the structure of fields straight from the model.

class Birthday(models.PatientSubrecord):
    party = dmodels.DateTimeField(verbose_name="Party Time!" blank=True)
    name = dmodels.CharField(default='Dave', blank=True, null=True)

    # becomes...
        'default': "Dave",
        'lookup_list': None,
        'model': 'Birthday',
        'name': 'name',
        'title': u'Name',
        'type': 'string'
        'default': None,
        'lookup_list': None,
        'model': 'Birthday',
        'name': 'party',
        'title': u'Party Time!',
        'type': 'date_time'