APIs

Show:

Abstract version of a model to use.

Please use this model instead of directly extending the backbone model. This is will help minimize the amount of reused code needed to handle various factors (i.e. ahis session id, multiple backend protocols)

See the following for parent class definition: http://backbonejs.org/#Model See awa.mvc.ModelAttributeTypes and awa.mvc.ModelAttributeTypes.ModelAttributeType for examples and descriptions of possible attributes

An example Model definition

define(
['awa'],
function(awa){
    var ExampleModel = awa.mvc.Model.extend({

        //this function returns the base url for the model's concepts.
        //depending on the api type, this url is expanded based on the server action
        urlRoot: function(){
            return awa.url.BAREBONES + "V1/examples";
        },

        //specifies which ajax strategy to use. can also be 'api'
        api: 'barebones',

        //This is used to build the url and to determine if the model isNew
        idAttribute: 'exp_id',

        //This is used by grids and the isDisabled function
        disabledAttribute: 'exa_disabled',

        //This defines the initial values of certain properties when initializing a new model
        defaults:{
            exa_string: 'default string'
        },

        //Gets preferred display name of property
        //ie. PatientModel => pat_fname + ' ' + pat_lname
        //ie. InsuranceModel => ins_mnemonic || ins_name
        displayName: function(){
            return this.get('exa_name');
        },

        //Defined properties in all models.
        //awa.mvc.ModelAttributeTypes
        //awa.mvc.ModelAttributeTypes.ModelAttributeType
        attributeProps:{
            exa_string: {
                name: "Example String",
                rules:{
                    require: true,
                    date: true
                }
            },
            exa_date: {
                name: "Example Date (8 digit VARCHAR or DATE)",
                type: 'date',
                rules:{
                    require: true
                }
            },
            exa_phone: {
                name: "Example Phone (10~20 character VARCHAR)",
                type: 'phone',
                rules:{
                    usPhoneFormat: true
                }
            },
            exa_ts: {
                name: "Example Timestamp (Local to client, 12 digit VARCHAR)",
                type: 'timestamp',
                rules:{
                    require: true
                }
            },
            exa_datetime: {
                name: "Example Timestamp (ALWAYS EST, DATETIME)",
                type: 'mysql_timestamp',
                rules:{
                    require: true
                }
            },
            exp_foreign_key_id: {
                name: "Example foreign key property",
                type: 'listValue',
                //collection can be the collection or a function that returns a collection
                collection: someCollection
            },
            exp_boolean: {
                name: "Example Boolean (like disabled)",
                type: 'boolean'
            }
        }
    });
    return ExampleModel;
});

//events
update
lock

Similar to normal classes, each attribute should be defined in the attributeProps. This allows naming, rules, formatting, etc. to be centralized into one area. i.e. the above property exp_string has the name "Example String". This will be used (by default) in grids, model displays, and edit views. See awa.mvc.ModelAttributeTypes for more details.

Validation also takes place in the model (for the most part). Each attribute has it's own set of rules. See awa.mvc.ModelRules for existing rules and how they apply.

Methods

_validateChildCollection

(
  • key
  • collection
  • errors
)
Boolean

CAUTION errors param will be modified

Parameters:

  • key String

    Attribute key

  • collection awa.mvc.Collection

    Collection to check

  • errors Object

    Object of errors

Returns:

Boolean:

Indicates this method found errors in the collection

add

(
  • attribute
  • value
  • [id]
  • [options]
)
type

The add method is used primarily for arrays.

Parameters:

  • attribute String

    attribute name

  • value Object

    value to be added to the array

  • [id] Integer optional

    the specific index

  • [options] Object | String optional

    refer to Backbone.js

Returns:

type:

[description]

addAttributeProp

(
  • args
)
Object static

Allows for the addition of

Parameters:

  • args Object

    desc

Returns:

Object:

Collection

addAttributeProp

(
  • attr
  • prop
)
Null static

Allows for the addition of

Parameters:

  • attr String

    desc

  • prop Object

    desc

Returns:

Null:

not available

addRules

(
  • key
  • rules
)
type

appends rules to the model

Parameters:

  • key Object | String

    desc

  • rules Object | String

    desc

Returns:

type:

[description]

createCollection

(
  • initialCollection
  • options
)
awa.mvc.Collection static

Generates a new collection from the given model

Parameters:

  • initialCollection Array

    initial collection to start with.

  • options Object

    Parameter bag

Returns:

awa.mvc.Collection:

prototype chain - Collection

destroy

(
  • options
)
type

Stolen from backbone and completely overridden. Look in method for change

Parameters:

  • options Object

    configuration object with various properties

Returns:

type:

[description]

difference

(
  • obj
)
type

Parameters:

  • obj Object

    configuration object with various properties

Returns:

type:

[description]

displayName

() type

Override to return the name of the model (i.e. for a patient, it would be their last name, comma, space, and then first name). By default, this returns attribute name, id, then cid.

Returns:

type:

[description]

enable

(
  • [options]
)
type

If the model has a disabledAttribute, this method will automatically re-enable by setting the property to 0

Parameters:

  • [options] Object optional

    configuration object with various properties

Returns:

type:

[description]

fetch

(
  • id
  • options
)
Promise static

Global repository

Parameters:

  • id String | Integer

    desc

  • options Object

    desc

Returns:

Promise:

returns resolve promise

fetchAll

(
  • options
)
Object static

Global repository

Parameters:

  • options Object

    desc

Returns:

Object:

Collection

fillAttributeProp

(
  • attr
  • prop
)
Null static

adds attribute prop data but does not override existing key values

Parameters:

  • attr String

    desc

  • prop Object

    desc

Returns:

Null:

not available

get

(
  • attr
)
type

Get the current value of an attribute from the model Overwritten to create collections and sub models only when needed.

Parameters:

  • attr String

    desc

Returns:

type:

[description]

getAPI

() String static

Returns the api for the given model class

Returns:

String:

api Api for model. directs sync functionality

getAttributeProp

(
  • attr
  • prop
)
type

Gets the attribute property for a specified attribute.

Parameters:

  • attr String

    Attribute key (i.e pat_fname)

  • prop String

    Property key (i.e displayMethod)

Returns:

type:

[description]

getAttributeProps

(
  • attr
  • prop
)
Object static

Parameters:

  • attr Object

    Attribute key

  • prop Object

    Property

Returns:

Object:

prop desc

getCollection

(
  • options
)
Object static

Global repository. This can be affected by uses outside of your own.

Parameters:

  • options String

    desc

Returns:

Object:

prototype chain - Collection

getDisplay

(
  • attr
  • options
)
type

Like get, but this uses the displayMethod.

Parameters:

  • attr String

    desc

  • options Object

    desc

Returns:

type:

[description]

getDisplayMethod

(
  • attr
)
type

returns the displayMethod for a given attribute

Parameters:

  • attr String

    desc

Returns:

type:

[description]

getFilters

(
  • options
)
awa.mvc.Collection static

get filters collection for model collection

Parameters:

  • options Object

    desc

Returns:

awa.mvc.Collection:

Collection

getIDAttribute

() String static

Return id attribute key

Returns:

String:

ID attribute of model

getModelDescription

() String static

Returns a description of the model. You can set this in the model with property modelDescription i.e. Patient Class would be "Labels that provide a means to better organize patients"

Returns:

String:

desc of model

getModelName

() String static

Returns plural name of model class. by default it appends an 's' to the name. override in cases where needed. (i.e. diagnosis => diagnoses) i.e. Patient model would be Patients

Returns:

String:

desc of name

getModelName

() String static

Returns name of model class. you can set this in the model i.e. Patient model would be Patient

Returns:

String:

desc

getName

(
  • attr
  • fullName
)
String

Gets the name of an attribute. This can be set by an attribute's attributeProp name. An attribute property can have a getName function to define how to name nested portions NOTE: The containing object of a property should decide the properties name. i.e. if a model has a "period" attribute prop, that should be named in the model, not the period attributeProps returns the attribute if not set.

Parameters:

  • attr String

    Attribute key desired. If nothing is provided, the model's displayName is returned.

  • fullName Boolean

    If true returns the full name for nested properties from the context of the root model. i.e. "Encounter Primary Insurance Period Start" v. "Start"

Returns:

String:

attribute name

getScope

(
  • options
)
type

Id this is a nested model inside of a collection or another model, this will provide the extended id to grab it from the root model.

Parameters:

  • options Object

    desc

    • [cssSafe] Boolean optional

      replaces attribute separator with dashes for css selection if true

    • [cid] Boolean optional

      by default uses cid. if set to false, will use ID instead

Returns:

type:

[description]

getSearchCollection

(
  • options
)
Object static

Collection used for searching in this model. columns and filters should be provided in the collection for grids.

Parameters:

  • options String

    desc

Returns:

Object:

prototype chain - Collection

getTip

(
  • attr
)
type

Gets the tip for an attribute. This can be set by an attribute's attributeProp tip. returns the attribute if not set.

Parameters:

  • attr String

    desc

Returns:

type:

[description]

getType

(
  • attr
)
type

Gets the attribute type (i.e. string, collection, date), the default type is string

Parameters:

  • attr String

    desc

Returns:

type:

[description]

getURLRoot

() String static

Returns the url root for the given model class

Returns:

String:

urlRoot for model

hasExport

() Boolean static

Returns:

Boolean:

desc

isDisabled

() Boolean

Tells whether or not an individual has disabled status.

Returns:

Boolean:

desc

isIncomplete

() Boolean

Tells whether or not an individual has incomplete status. Override this method if you want to use it in a model.

Returns:

Boolean:

desc

isNotDone

() Boolean

Tells whether or not an item was not done. Primarily for medical events (i.e. procedures, care plans, prescriptions)

Returns:

Boolean:

desc

isValid

(
  • Refer
)
type

A convenience function for returning boolean values instead of objects

Parameters:

  • Refer Object

    to validate() for parameter list and notes.

Returns:

type:

[description]

objectAccess

(
  • obj
  • property
)
Object | Undefined

Parameters:

  • obj Object

    Object to retrieve nested property from

  • property String

    Property string to access

Returns:

Object | Undefined:

returns the nested property or undefined

objectFilter

(
  • object
  • iterator
)
type

this does something....

Parameters:

  • object Object

    desc

  • iterator Function

    desc

Returns:

type:

[description]

removeRules

(
  • key
  • rules
)
type

Replaces all rules for an individual key in a model

Parameters:

  • key Object | String

    desc

  • rules Object | String

    desc

Returns:

type:

[description]

restore

(
  • options
)
type

The restore method rewinds back to the last created store point.

Parameters:

  • options Object

    desc

Returns:

type:

[description]

set

(
  • attributes
  • [options]
)
type

The set method does everything outlined in Backbone.js library. It has been overridden to handle building inferred attributes that are outlined in the child class. Sometimes you may want another attribute to update another set in a model. In this case, you may override the set method. If you do, be sure to call super on set so that these processes are handled.

Parameters:

  • attributes Object | String

    refer to Backbone.js

  • [options] Object | String optional

    refer to Backbone.js

Returns:

type:

[description]

setRules

(
  • key
  • rules
)
type

set rules to the model for an attribute

Parameters:

  • key Object | String

    desc

  • rules Object | String

    desc

Returns:

type:

[description]

store

() type

The store method sets a store point for the model in a stack. Use restore to rewind the model to previous store points. FIFO

Returns:

type:

[description]

subAction

(
  • options
)
XHRObject

Call a subaction of a model. (i.e. if you have a document that has a copy action) The url should follow the pattern of resource/:id/:action (documents/2/copy)

var PatientModel = awa.mvc.Model.extend({ urlRoot: awa.url.BAREBONES + 'V1/patients', idAttribute: 'pat_id' });

var model = new PatientModel({pat_id: 75});

//the following will make a GET request to //[barebones_root]V1/patients/75/sync

model.subAction({ type: 'GET', action: 'sync', success: function(){

}
                    

});

Parameters:

  • options Object

    configuration object with various properties

    • action String

      name of action

    • type String

      http method to use (POST, GET, DELETE, etc)

    • success Function

      desc

    • error Function

      desc

    • data Object

      desc

Returns:

XHRObject:

Avoid using this as it is subject to change.

sync

(
  • method
  • model
  • options
)
Object

Overridden from Backbone.Model.fetch to handle not so restful backend.

Parameters:

  • method Object

    configuration object with various properties

  • model Object

    desc

  • options Object

    desc

Returns:

Object:

result of api_sync

toDisplayJSON

() type

Uses the displayRules/Methods that are set in either the displayRules property or the attributeProps to generate a javascript object (w/o getters and setters) that represents the model's data in a displayable format.

Returns:

type:

[description]

toJSON

(
  • [options]
)
type

Overwritten to provide more control on the resulting json output

Parameters:

  • [options] Object optional

    Options object

    • [skipKeys] Array optional

      Set of keys to skip.

    • [sync] String optional

      If calling for syncing purposes. see awa.mvc.Model.SYNC

Returns:

type:

[description]

url

() String

stolen from backbone and altered to not throw exception in case of no urlRoot

Returns:

String:

URL for model instance

validate

(
  • attributes
  • [options]
)
type

The validate method does everything outlined in Backbone.js library. It has been overridden to handle the rules set in the attributeProps and the rules property. In some cases, you may want to do extensive validating on attributes that dont fit the model rules functions (i.e. making sure a date of birth is not in the future). Be sure to call the super version of validate to handle the other rules. !!!PLEASE NOTE!!! This method will evaluate all rules if you don't pass in attributes but if you do, then it only validates the ones you pass in. Keep this in mind when overriding this method. passing in a small set of attributes will cause all of the unset variables to be ignored.

Parameters:

  • attributes Object | String

    refer to Backbone.js

  • [options] Object | String optional

    refer to Backbone.js

Returns:

type:

[description]

Properties

__attributePropsProcessed

Boolean

just leave it alone.

Default: false

_stores

Array

Used by the model object to set and access store points.

Default: empty

api

String

Specifies what backend protocol to use to communicate with the server. 'api' will use the old standard of adding the method in the URL. 'barebones' will accomodate barebones

Default: api

className

String

Specifies what backend protocol to use to communicate with the server. 'api' will use the old standard of adding the method in the URL. 'barebones' will accomodate barebones

Default: Model

disabledAttribute

String

Specifies the disabled attribute in the model

Default: undefined

displayRules

Object keys: attribute/field names, value: name of the function outline in awa.func that will be called to format the data for output.

Rule set for validation. Used by Form validators.

Default: undefined

inferred

Object keys: attribute/field names, value: Objects that specify the rules to follow. Used in conjuction with model rule functions

Any attributes that are built with primary data goes here. i.e. a patients full name is derived from the combination of it's first, middle, and last name and the suffix

Default: undefined

name

String

Override to return the name of the model (i.e. for the patient model, it would be Patient).

Default: undefined

pluralName

String

Override to return the plural name of the model. You should only use this if the plural does not just append a 's' (i.e. for the Diagnosis model, it would be Diagnoses).

Default: undefined

rules

Object keys: attribute/field names, value: Objects that specify the rules to follow. Used in conjuction with jquery forms.

Rule set for validation. Used by Form validators.

Default: undefined

syncBlackList

Array

Lists the attributes that will not be synced back. doesn't prevent anything from being sent if empty or undefined. Given priority of over syncWhiteList

Default: undefined

syncWhiteList

Array

Lists the attributes that can be synced back. sends back all attributes if the list is empty or undefined

Default: undefined

Events

rules

Called when rules change on an individual model