module LifenFhir class Element < Base attribute :uuid, String def reference "#{resource_type}/#{uuid}" end def attributes_from_json(json) self.uuid = extract_uuid(json["reference"]) self end def fhir_payload_as_reference { reference: reference } end private def extract_uuid(uuid_or_reference) if m = uuid_or_reference.match(/^#(.*)/) # "#1234-abcd-5678' return m[1] elsif m = uuid_or_reference.match(/(.*)\/(.*)/) # "Binary/1234-abcd-5678' return m[2] else return uuid_or_reference end end def resource_type self.class.name.gsub!('LifenFhir::', '') end end end