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
- #drawer_date ⇒ Object
-
#initialize(order_id) ⇒ OrderLabel
constructor
A new instance of OrderLabel.
- #patient ⇒ Object
- #print(use_small_specimen = false, number_of_copies = nil) ⇒ 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
134 135 136 |
# File 'app/services/lab/labelling_service/order_label.rb', line 134 def auto12epl Auto12Epl.new end |
#drawer ⇒ Object
94 95 96 97 |
# File 'app/services/lab/labelling_service/order_label.rb', line 94 def drawer return 'N/A' if order.concept_id == unknown_concept.concept_id (order.discontinued_date || order.start_date).strftime('%d/%^b/%Y') end |
#drawer_date ⇒ Object
99 100 101 102 103 104 |
# File 'app/services/lab/labelling_service/order_label.rb', line 99 def drawer_date return 'N/A' if order.concept_id == unknown_concept.concept_id draw_date = (order.discontinued_date || order.start_date).strftime('%d/%^b/%Y %H:%M:%S') "#{draw_date}" || 'N/A' end |
#patient ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/services/lab/labelling_service/order_label.rb', line 73 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 arv_identifier = PatientIdentifier.where(type: PatientIdentifierType.where(name: 'ARV Number'), 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', arv: arv_identifier&.identifier || '' ) end |
#print(use_small_specimen = false, number_of_copies = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/services/lab/labelling_service/order_label.rb', line 16 def print(use_small_specimen = false, number_of_copies = nil) # 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. zpl = if use_small_specimen auto12epl.generate_small_specimen_label( patient.family_name, patient.given_name, patient.gender, drawer, tests, order.accession_number, patient.arv, number_of_copies ) else 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, patient.arv, number_of_copies ) end { zpl:, data: { accession_number: order.accession_number, given_name: patient.given_name, family_name: patient.family_name, nhid: patient.nhid, birthdate: patient.birthdate.strftime('%d/%^b/%Y'), gender: patient.gender, drawer:, tests:, reason_for_test: } } end |
#reason_for_test ⇒ Object
67 68 69 70 71 |
# File 'app/services/lab/labelling_service/order_label.rb', line 67 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
124 125 126 127 128 |
# File 'app/services/lab/labelling_service/order_label.rb', line 124 def short_concept_name(concept_id) ConceptName.where(concept_id:) .min_by { |concept| concept.name.size } &.name end |
#specimen ⇒ Object
106 107 108 109 110 |
# File 'app/services/lab/labelling_service/order_label.rb', line 106 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
112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/services/lab/labelling_service/order_label.rb', line 112 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
130 131 132 |
# File 'app/services/lab/labelling_service/order_label.rb', line 130 def unknown_concept ConceptName.find_by_name('Unknown') end |