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_address(params) ⇒ Object (also: #create_channel)
- #create_telecom(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
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lifen/user.rb', line 49 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
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/lifen/user.rb', line 118 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
165 166 167 168 169 170 171 |
# File 'lib/lifen/user.rb', line 165 def self.from_json(json) reference = json["reference"] uuid = reference.gsub("Practitioner/", "") new(uuid: uuid) end |
Instance Method Details
#client ⇒ Object
100 101 102 |
# File 'lib/lifen/user.rb', line 100 def client UserAuthenticatedClient.new(token) end |
#create(persisted_lifen_uuid: ->(user) {}, save_to_db: ->(user) {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lifen/user.rb', line 24 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_address(params) ⇒ Object Also known as: create_channel
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/lifen/user.rb', line 142 def create_address(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 |
#create_telecom(params) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/lifen/user.rb', line 173 def create_telecom(params) filtered_params = {"resourceType" => "Practitioner"} telecom = { "system": params[:system], "value": params[:value] } filtered_params[params[:type]] = telecom json = application_client.post("fhir/Practitioner/#{uuid}/$add-telecom", filtered_params) channel = Channel.new(uuid: json["issue"][0]["id"], type: params[:type], value: params[:value]) self.channels << channel channel end |
#fhir_payload ⇒ Object
104 105 106 |
# File 'lib/lifen/user.rb', line 104 def fhir_payload { reference: "Practitioner/#{uuid}" } end |
#flows ⇒ Object
20 21 22 |
# File 'lib/lifen/user.rb', line 20 def flows Lifen::Flows.new(user: self).all end |
#reload ⇒ Object
61 62 63 |
# File 'lib/lifen/user.rb', line 61 def reload self.class.find(uuid) end |
#save ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/lifen/user.rb', line 65 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
96 97 98 |
# File 'lib/lifen/user.rb', line 96 def settings @settings ||= Lifen::Settings.new(user: self).reload end |
#status ⇒ Object
92 93 94 |
# File 'lib/lifen/user.rb', line 92 def status @status ||= Lifen::Status.new(user: self).reload end |
#token ⇒ Object
83 84 85 |
# File 'lib/lifen/user.rb', line 83 def token @token ||= Lifen::Token.new(user: self) end |
#token=(token) ⇒ Object
87 88 89 90 |
# File 'lib/lifen/user.rb', line 87 def token=(token) token.user = self @token = token end |
#unread_messages ⇒ Object
79 80 81 |
# File 'lib/lifen/user.rb', line 79 def status.unread end |