Class: Lifen::User
- Inherits:
-
Object
- Object
- Lifen::User
- Defined in:
- lib/lifen/user.rb
Constant Summary collapse
- @@create_lock =
Mutex.new
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
- #create(persisted_lifen_uuid: ->(user) {}, save_to_db: ->(user) {}) ⇒ Object
- #create_channel(params) ⇒ Object
- #fhir_payload ⇒ Object
- #flows ⇒ Object
- #reload ⇒ Object
- #save ⇒ Object
- #settings ⇒ Object
- #status ⇒ Object
- #token ⇒ Object
- #token=(token) ⇒ Object
- #unread_messages ⇒ Object
Class Method Details
.find(uuid) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lifen/user.rb', line 48 def self.find(uuid) json = application_client.get("docbook/api/thirdParty/person/#{uuid}") json[:uuid] = json["uuid"] json[:email] = json["emailAddress"] json[:first_name] = json["firstName"] json[:last_name] = json["lastName"] json[:profile_picture_url] = json["profilePicUrl"] new(json) end |
.find_by_rpps(rpps) ⇒ Object
users end
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/lifen/user.rb', line 117 def self.find_by_rpps(rpps) json = application_client.get("fhir/Practitioner/?identifier=#{rpps}") raise "User not found" if Array(json["entry"]).size != 1 user_json = Array(json["entry"]).first.fetch("resource") { {} } user_json[:uuid] = user_json["id"] user = new(user_json) Array(user_json["telecom"]).each do |telecom_json| user.channels << Lifen::Channel.from_json(telecom_json, "telecom") end Array(user_json["address"]).each do |address_json| user.channels << Lifen::Channel.from_json(address_json, "address") end user end |
.from_json(json) ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/lifen/user.rb', line 162 def self.from_json(json) reference = json["reference"] uuid = reference.gsub("Practitioner/", "") new(uuid: uuid) end |
Instance Method Details
#client ⇒ Object
99 100 101 |
# File 'lib/lifen/user.rb', line 99 def client UserAuthenticatedClient.new(token) end |
#create(persisted_lifen_uuid: ->(user) {}, save_to_db: ->(user) {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lifen/user.rb', line 23 def create(persisted_lifen_uuid: ->(user) {}, save_to_db: ->(user) {}) params = {emailAddress: email, lastName: last_name, firstName: first_name, profilePicUrl: profile_picture_url} @@create_lock.synchronize do exisiting_uuid = persisted_lifen_uuid.call(self) if exisiting_uuid.nil? json = application_client.post("authentication/api/register/third_party", params) self.uuid = json["accountUuid"] else self.uuid = exisiting_uuid end save_to_db.call(self) end end |
#create_channel(params) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/lifen/user.rb', line 141 def create_channel(params) filtered_params = {"resourceType" => "Practitioner"} address = { "line": Array(params[:lines]), "city": params[:city], "postalCode": params[:postal_code], "country": params[:country] } filtered_params[params[:type]] = address json = application_client.post("fhir/Practitioner/#{uuid}/$add-address", filtered_params) channel = Channel.new(uuid: json["issue"][0]["id"], type: params[:type], value: "#{Array(params[:lines]).join(", ")}, #{params[:postal_code]} #{params[:city]}") self.channels << channel channel end |
#fhir_payload ⇒ Object
103 104 105 |
# File 'lib/lifen/user.rb', line 103 def fhir_payload { reference: uuid } end |
#flows ⇒ Object
19 20 21 |
# File 'lib/lifen/user.rb', line 19 def flows Lifen::Flows.new(user: self).all end |
#reload ⇒ Object
60 61 62 |
# File 'lib/lifen/user.rb', line 60 def reload self.class.find(uuid) end |
#save ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lifen/user.rb', line 64 def save params = {emailAddress: email, lastName: last_name, firstName: first_name, profilePicUrl: profile_picture_url} params[:uuid] = uuid json = application_client.put("docbook/api/thirdParty/person/", params) self.email = json["emailAddress"] self.first_name = json["firstName"] self.last_name = json["lastName"] self.profile_picture_url = json["profilePicUrl"] self end |
#settings ⇒ Object
95 96 97 |
# File 'lib/lifen/user.rb', line 95 def settings @settings ||= Lifen::Settings.new(user: self).reload end |
#status ⇒ Object
91 92 93 |
# File 'lib/lifen/user.rb', line 91 def status @status ||= Lifen::Status.new(user: self).reload end |
#token ⇒ Object
82 83 84 |
# File 'lib/lifen/user.rb', line 82 def token @token ||= Lifen::Token.new(user: self) end |
#token=(token) ⇒ Object
86 87 88 89 |
# File 'lib/lifen/user.rb', line 86 def token=(token) token.user = self @token = token end |
#unread_messages ⇒ Object
78 79 80 |
# File 'lib/lifen/user.rb', line 78 def status.unread end |