Class: Lab::LabellingService::OrderLabel
- Inherits:
-
Object
- Object
- Lab::LabellingService::OrderLabel
- Defined in:
- app/services/lab/labelling_service/order_label.rb
Overview
Prints an order label for order with given accession number.
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #auto12epl ⇒ Object
- #drawer ⇒ Object
-
#initialize(order_id) ⇒ OrderLabel
constructor
A new instance of OrderLabel.
- #patient ⇒ Object
- #print ⇒ Object
- #reason_for_test ⇒ Object
- #short_concept_name(concept_id) ⇒ Object
- #specimen ⇒ Object
- #tests ⇒ Object
- #unknown_concept ⇒ Object
Constructor Details
#initialize(order_id) ⇒ OrderLabel
Returns a new instance of OrderLabel.
12 13 14 |
# File 'app/services/lab/labelling_service/order_label.rb', line 12 def initialize(order_id) @order = Lab::LabOrder.find(order_id) end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
10 11 12 |
# File 'app/services/lab/labelling_service/order_label.rb', line 10 def order @order end |
Instance Method Details
#auto12epl ⇒ Object
101 102 103 |
# File 'app/services/lab/labelling_service/order_label.rb', line 101 def auto12epl Auto12Epl.new end |
#drawer ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/services/lab/labelling_service/order_label.rb', line 60 def drawer return 'N/A' if order.concept_id == unknown_concept.concept_id drawer_id = User.find(order.discontinued_by || order.creator).person_id draw_date = (order.discontinued_date || order.start_date).strftime('%d/%^b/%Y %H:%M:%S') name = PersonName.find_by_person_id(drawer_id) return "#{name.given_name} #{name.family_name} #{draw_date}" if name user = User.find_by_user_id(drawer_id) user ? "#{user.username} #{draw_date}" : 'N/A' end |
#patient ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/lab/labelling_service/order_label.rb', line 42 def patient return @patient if @patient person = Person.find(order.patient_id) person_name = PersonName.find_by_person_id(order.patient_id) patient_identifier = PatientIdentifier.where(type: PatientIdentifierType.where(name: 'National id'), patient_id: order.patient_id) .first @patient = OpenStruct.new( given_name: person_name.given_name, family_name: person_name.family_name, birthdate: person.birthdate, gender: person.gender, nhid: patient_identifier&.identifier || 'Unknown' ) end |
#print ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/lab/labelling_service/order_label.rb', line 16 def print # NOTE: The arguments are passed into the method below not in the order # the method expects (eg patient_id is passed to middle_name field) # to retain compatibility with labels generated by the `lab test controller` # application of the NLIMS suite. auto12epl.generate_epl(patient.given_name, patient.family_name, patient.nhid, patient.birthdate.strftime('%d/%^b/%Y'), '', patient.gender, '', drawer, '', tests, reason_for_test, order.accession_number, order.accession_number) end |
#reason_for_test ⇒ Object
36 37 38 39 40 |
# File 'app/services/lab/labelling_service/order_label.rb', line 36 def reason_for_test return 'Unknown' unless order.reason_for_test short_concept_name(order.reason_for_test.value_coded) || 'Unknown' end |
#short_concept_name(concept_id) ⇒ Object
91 92 93 94 95 |
# File 'app/services/lab/labelling_service/order_label.rb', line 91 def short_concept_name(concept_id) ConceptName.where(concept_id: concept_id) .min_by { |concept| concept.name.size } &.name end |
#specimen ⇒ Object
73 74 75 76 77 |
# File 'app/services/lab/labelling_service/order_label.rb', line 73 def specimen return 'N/A' if order.concept_id == unknown_concept.concept_id ConceptName.find_by_concept_id(order.concept_id)&.name || 'Unknown' end |
#tests ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/services/lab/labelling_service/order_label.rb', line 79 def tests tests = order.tests.map do |test| name = short_concept_name(test.value_coded) || 'Unknown' next 'VL' if name.match?(/Viral load/i) name.size > 7 ? name[0..6] : name end tests.join(', ') end |
#unknown_concept ⇒ Object
97 98 99 |
# File 'app/services/lab/labelling_service/order_label.rb', line 97 def unknown_concept ConceptName.find_by_name('Unknown') end |