lib/lifen_fhir/patient.rb in lifen_fhir-0.4.1 vs lib/lifen_fhir/patient.rb in lifen_fhir-0.4.2

- old
+ new

@@ -1,10 +1,8 @@ module LifenFhir - class Patient < Base + class Patient < Element - attribute :uuid, String - attribute :first_name, [String] attribute :last_name, String attribute :birth_date, Date attribute :address, Address @@ -21,30 +19,31 @@ self end def self.find_by_uuid(uuid) patient = new(uuid:uuid) - json = application_client.get("fhir/#{LifenFhir::Reference.new(patient)}") - patient = new + json = application_client.get("fhir/#{patient.reference}") + patient.attributes_from_json(json) patient end def fhir_payload - { + fhir_payload = { id: "patient", resourceType: "Patient", name: [ { family: last_name, given: first_name } - ], - birthDate: birth_date.to_s + ] } + fhir_payload[:birthDate] = birth_date.to_s if birth_date + fhir_payload end def attributes_from_json(json) self.uuid = json["id"] @@ -70,25 +69,18 @@ "given": first_name }] if address filtered_params["address"] = [ - address.create_payload + address.fhir_payload ] end - filtered_params["birthDate"] = birth_date.to_s + if birth_date + filtered_params["birthDate"] = birth_date.to_s + end filtered_params - end - - def application_client - @application_client ||= AppAuthenticatedClient.new - end - - - def self.application_client - @application_client ||= AppAuthenticatedClient.new end end end