Module: Lab::AccessionNumberService

Defined in:
app/services/lab/accession_number_service.rb

Overview

Responsible for the generation of tracking numbers

Class Method Summary collapse

Class Method Details

.next_accession_number(date = nil) ⇒ Object

Returns the next accession number on the given date or today.

Throws:

RangeError - If date is greater than system date


11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/lab/accession_number_service.rb', line 11

def next_accession_number(date = nil)
  date = validate_date(date || Date.today)
  counter = find_counter(date)

  counter.with_lock do
    accession_number = format_accession_number(date, counter.value)
    counter.value += 1
    counter.save!

    return accession_number
  end
end