Last active
August 29, 2015 14:03
-
-
Save mackwic/e5d6d61e3a2056920b6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('feetmeApp').factory 'Patient', () -> | |
| class Patient | |
| constructor: (object) -> | |
| @id = object.id | |
| @firstname = object.firstname | |
| @lastname = object.lastname | |
| @birthdate = Date.create(object.birthdate) | |
| @tel = object.tel | |
| @gender = object.gender | |
| @address = object.address | |
| @zipcode = object.zipcode | |
| @city = object.city | |
| @email = object.email | |
| @foot_type = object.foot_type | |
| @last_visit = null | |
| @created_at = Date.create() | |
| @updated_at = Date.create() | |
| fullName: () -> "#{@firstname} #{@lastname}" | |
| shortGender: () -> if @gender is 'm' then 'M.' else 'Mme' | |
| longGender: () -> if @gender is 'm' then 'Monsieur' else 'Madame' | |
| prettyName: () -> "#{@shortGender()} #{@fullName()}" | |
| prettyLastVisit: (format) -> | |
| if @last_visit is null then 'Jamais venu' else @last_visit.format(format) | |
| prettyBirthdate: (format) -> | |
| @birthdate.format(format) | |
| updateLastVisit: () -> | |
| @update() | |
| @last_visit = Date.create() | |
| update: () -> @updated_at = Date.create() | |
| constraints: | |
| id : | |
| presence: true | |
| numericality: true | |
| firstname: | |
| presence: true | |
| format: | |
| pattern: "^[a-zA-Z]*$" | |
| lastname: | |
| presence: true | |
| format: | |
| pattern: "^[a-zA-Z]*$" | |
| #tel: | |
| # format: | |
| # pattern: "^(?:0|\(?\+33\)?\s?|0033\s?)[1-79](?:[\.\-\s]?\d\d){4}$" | |
| gender: | |
| presence: true | |
| inclusion: ['m', 'f'] | |
| address: | |
| format: | |
| pattern: "^[a-zA-Z0-9]*$" | |
| city: | |
| format: | |
| pattern: "^[a-zA-Z0-9]*$" | |
| #zipcode: | |
| # onlyInteger: true | |
| # greaterThan: 9999 | |
| # lessThan: 100000 | |
| email: | |
| email: true | |
| foot_type: | |
| presence: true | |
| inclusion: ['E', 'L', 'G'] | |
| validate_all: () -> | |
| validate | |
| id: @id | |
| firstname: @firstname | |
| lastname: @lastname | |
| gender: @gender | |
| address: @address | |
| city: @city | |
| zipcode: @zipcode | |
| email: @email | |
| foot_type: @foot_type | |
| @constraints | |
| dump: () -> | |
| $log.log "id: #{@id}\n\ | |
| firstname: #{@firstname}\n\ | |
| lastname: #{@lastname}\n\ | |
| birthdate: #{@birthdate}\n\ | |
| tel: #{@tel}\n\ | |
| gender: #{@gender}\n\ | |
| address: #{@address}\n\ | |
| zipcode: #{@zipcode}\n\ | |
| city: #{@city}\n\ | |
| email: #{@email}\n\ | |
| foot_type: #{@foot_type}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Generated by CoffeeScript 1.6.3 | |
| angular.module('feetmeApp').factory('Patient', function() { | |
| var Patient; | |
| return Patient = (function() { | |
| function Patient(object) { | |
| this.id = object.id; | |
| this.firstname = object.firstname; | |
| this.lastname = object.lastname; | |
| this.birthdate = Date.create(object.birthdate); | |
| this.tel = object.tel; | |
| this.gender = object.gender; | |
| this.address = object.address; | |
| this.zipcode = object.zipcode; | |
| this.city = object.city; | |
| this.email = object.email; | |
| this.foot_type = object.foot_type; | |
| this.last_visit = null; | |
| this.created_at = Date.create(); | |
| this.updated_at = Date.create(); | |
| } | |
| Patient.prototype.fullName = function() { | |
| return "" + this.firstname + " " + this.lastname; | |
| }; | |
| Patient.prototype.shortGender = function() { | |
| if (this.gender === 'm') { | |
| return 'M.'; | |
| } else { | |
| return 'Mme'; | |
| } | |
| }; | |
| Patient.prototype.longGender = function() { | |
| if (this.gender === 'm') { | |
| return 'Monsieur'; | |
| } else { | |
| return 'Madame'; | |
| } | |
| }; | |
| Patient.prototype.prettyName = function() { | |
| return "" + (this.shortGender()) + " " + (this.fullName()); | |
| }; | |
| Patient.prototype.prettyLastVisit = function(format) { | |
| if (this.last_visit === null) { | |
| return 'Jamais venu'; | |
| } else { | |
| return this.last_visit.format(format); | |
| } | |
| }; | |
| Patient.prototype.prettyBirthdate = function(format) { | |
| return this.birthdate.format(format); | |
| }; | |
| Patient.prototype.updateLastVisit = function() { | |
| this.update(); | |
| return this.last_visit = Date.create(); | |
| }; | |
| Patient.prototype.update = function() { | |
| return this.updated_at = Date.create(); | |
| }; | |
| Patient.prototype.constraints = { | |
| id: { | |
| presence: true, | |
| numericality: true | |
| }, | |
| firstname: { | |
| presence: true, | |
| format: { | |
| pattern: "^[a-zA-Z]*$" | |
| } | |
| }, | |
| lastname: { | |
| presence: true, | |
| format: { | |
| pattern: "^[a-zA-Z]*$" | |
| } | |
| }, | |
| gender: { | |
| presence: true, | |
| inclusion: ['m', 'f'] | |
| }, | |
| address: { | |
| format: { | |
| pattern: "^[a-zA-Z0-9]*$" | |
| } | |
| }, | |
| city: { | |
| format: { | |
| pattern: "^[a-zA-Z0-9]*$" | |
| } | |
| }, | |
| email: { | |
| email: true | |
| }, | |
| foot_type: { | |
| presence: true, | |
| inclusion: ['E', 'L', 'G'] | |
| } | |
| }; | |
| Patient.prototype.validate_all = function() { | |
| return validate({ | |
| id: this.id, | |
| firstname: this.firstname, | |
| lastname: this.lastname, | |
| gender: this.gender, | |
| address: this.address, | |
| city: this.city, | |
| zipcode: this.zipcode, | |
| email: this.email, | |
| foot_type: this.foot_type | |
| }, this.constraints); | |
| }; | |
| Patient.prototype.dump = function() { | |
| return $log.log("id: " + this.id + "\n firstname: " + this.firstname + "\n lastname: " + this.lastname + "\n birthdate: " + this.birthdate + "\n tel: " + this.tel + "\n gender: " + this.gender + "\n address: " + this.address + "\n zipcode: " + this.zipcode + "\n city: " + this.city + "\n email: " + this.email + "\n foot_type: " + this.foot_type); | |
| }; | |
| return Patient; | |
| })(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment