lib/lifen/user.rb in lifen-1.6.1 vs lib/lifen/user.rb in lifen-1.6.2

- old
+ new

@@ -113,20 +113,26 @@ # users # end def self.find_by_rpps(rpps) - json = application_client.get("fhir/Practitioner/#{rpps}") + json = application_client.get("fhir/Practitioner/?identifier=#{rpps}") - json[:uuid] = json["id"] - user = new(json) - Array(json["telecom"]).each do |telecom_json| + 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::Communication::Channel.from_json(telecom_json, "telecom") end - Array(json["address"]).each do |address_json| + Array(user_json["address"]).each do |address_json| user.channels << Lifen::Communication::Channel.from_json(address_json, "address") end user end \ No newline at end of file