class Iamspe::Bossy::Chairs
Classe de aguardo de repouso no leito
Public Class Methods
Source
# File lib/iamspe/bossy/chairs.rb 13 def initialize 14 # Inicializar TTY::Prompt 15 @prompt = TTY::Prompt.new 16 # Inicializar TTY::Config 17 @config = TTY::Config.new 18 @config.filename = '.iamspe' 19 @config.append_path Dir.home 20 raise new Error, 'Arquivo de configuração não encontrado' unless @config.exist? 21 22 @config.read 23 # Obter chefe de plantão 24 @chief = @config.fetch(:nome) 25 # Coletar pacientes e interpretar dados 26 interpret_patients 27 # Compilar texto de "output" 28 @out = start_out 29 @out.gsub!('LIST', parse_patients) 30 end
Inicializador
Public Instance Methods
Source
# File lib/iamspe/bossy/chairs.rb 33 def to_s 34 Clipboard.copy(@out) 35 @out.prepend "<< Texto copiado! >>\n\n" 36 end
Converter em String, no caso sendo o texto de “output”
Private Instance Methods
Source
# File lib/iamspe/bossy/chairs.rb 41 def interpret_patients 42 @patients = @prompt.multiline('Colar abaixo Ctrl+C do Censo, colunas D-M, sem linhas em branco ou de título:') do |q| 43 q.help 'Use Ctrl+D para finalizar.' 44 end 45 @patients = @patients.map do |patient| 46 patient = I18n.transliterate(patient.strip) 47 patient = patient.split("\t") 48 age, dx, prior = parse_pt_data(patient) 49 # - `$2`, *Tit.:* $5, *HD:* $10, *Prior.:* $1; 50 "- `#{patient[1].strip}`#{age}, *Tit.:* #{patient[4]}, *HD:* #{dx}, *Prior.:* #{prior}" 51 end 52 end
Coletar pacientes e interpretar dados
Source
# File lib/iamspe/bossy/chairs.rb 78 def parse_patients 79 if @patients.length.positive? 80 "#{@patients.join(";\n")}." 81 else 82 '- Sem pacientes aguardando.' 83 end 84 end
Finalizar formatação da lista de pacientes
Source
# File lib/iamspe/bossy/chairs.rb 55 def parse_pt_data(patient) 56 age = patient[2].empty? ? '' : " #{patient[2]}a" 57 dx = patient[9].nil? ? '?' : patient[9].strip 58 prior = case patient[0] 59 when 'A', 'B' 60 'Alta' 61 when 'D' 62 'Baixa' 63 else 64 'Média' 65 end 66 [age, dx, prior] 67 end
Processar campos comumente não preenchidos e traduzir prioridade
Source
# File lib/iamspe/bossy/chairs.rb 87 def parse_time 88 tz = TZInfo::Timezone.get('America/Sao_Paulo') 89 now = Time.now 90 now = tz.to_local(now) 91 now.strftime('%e/%b') 92 end
Obter tempo em formato configurado para região
Source
# File lib/iamspe/bossy/chairs.rb 70 def start_out 71 out = "\x2a⏳ \x60ATUALIZAÇÃO - CHEFIA DE PLANTÃO\x60 🛏\x2a\n" 72 out += "\x2aPlantão:\x2a TODAY - #{@chief}\n" 73 out += "\x2aSituação atual:\x2a\nLIST" 74 out.gsub('TODAY', parse_time) 75 end
Pré-compilar texto de “output”