Skip to content

Commit 98bafc0

Browse files
omelaoCarlos Zillnerstraight-shoota
authored
Feature/printing labels #1725 and #1747 (#1746)
* enabled printing label * isolate name blinded in every purposes * removed apparently unnecessary logic of blinded columns on CSV * put back specs * generic blinded columns spec * blinded specs on sample forms * isolate name blinded in every purposes * removed apparently unnecessary logic of blinded columns on CSV * put back specs * generic blinded columns spec * blinded specs on sample forms * blinded value on Samples index table * fixed blinded value on label was breaking the line changed from div to span * WIP: error when column wasnt blinded, but still there a 4 showing beside the field value * fixed the haml to show correctly the value of isolate name column * WIP: showing print label and ordering * WIP: showing print label and ordering * blinded ordered by uuid, unblided ordered by batch id, concentration, replicate and replicate column after concentration on CSV * order in untransfered boxes * adding comment and removing duplicated logic for blinded sample * changed blinded columns position on box specs * blinded I.N. on labels and changed I.M. to Purpose * printing buttons on transfer details and ordering rules * print button on transfer details * specs ready for the changes * removing debug from spec, blocking resending the same box, adjusting logic to query after boolean check * spliting blueprints samples filled/overfilled and receiver_confirmed version of TransferPackage * adding data to samples to check CSV rows order * Fix Reviews Remove unused CSS Refactor Printing Buttons CSS Positioning Refactor is_sender method using any? instead of present? Refactor the way SamplePresenter map is used Fix Showing Buttons Conditions Refactor Executing is_sender just one time * Fix load_box_print logic * Remove TransferPackages from Printing Boxes Removed it in controllers, haml links and specs * Fix Sample Map has a remaining } * Fix Sample Map has a remaining } * Refactor Print and Inventory Code Improved sender verification, authorize resource and Add Specs to verify if multiple transfers are blocked * Fix Load Box Samples Reassigning Samples samples.scrambled needs to be reassigned the order of samples was wrong on CSV inventory * Fix Confirmed Box Specs Confirmed Box Specs impacted the index spec * Fix force_unblind Verification Changed the sintax of force_unblind verification. Co-authored-by: Johannes Müller <straightshoota@gmail.com> * Refactor The Way to Execute load_box Before Action Co-authored-by: Johannes Müller <straightshoota@gmail.com> * Fix load_box before_action * Refator before_action loadbox * Remove delete method on load_box before_action Co-authored-by: Carlos Zillner <cz@rock.com.br> Co-authored-by: Johannes Müller <straightshoota@gmail.com>
1 parent 7100246 commit 98bafc0

File tree

14 files changed

+202
-61
lines changed

14 files changed

+202
-61
lines changed

app/assets/stylesheets/_barcode_card.scss

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
background: $white;
1212
padding: 5px 7px;
13-
margin: 15px 15px 7px;
13+
margin: 15px 15px;
1414

1515
.title {
1616
font-size: 14px;
@@ -66,17 +66,6 @@
6666
}
6767
}
6868

69-
.barcode-after {
70-
margin: 7px 15px 0;
71-
72-
.btn-icon {
73-
margin: -3px 0 0;
74-
font-size: 24px;
75-
background: none !important;
76-
color: inherit;
77-
}
78-
}
79-
8069
// Print Barcode style
8170

8271
.barcode-card-print {

app/assets/stylesheets/_box_preview.scss

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
.box-preview {
22
display: grid;
33
grid-template-areas:
4-
"uuid uuid uuid uuid uuid"
5-
"data data data data data";
6-
grid-template-columns: auto 1fr auto;
4+
"uuid uuid uuid btns"
5+
"purpose samples time btns";
6+
grid-template-columns: auto auto auto 1fr;
77
grid-gap: 5px;
88

99
.box__uuid {
1010
font-weight: bold;
1111
margin-right: 15px;
1212
grid-area: uuid;
13+
padding-top: 8px;
1314

1415
> a {
1516
color: inherit;
1617
}
1718
}
19+
.box__btns {
20+
grid-area: btns;
21+
display: flex;
22+
flex-direction: column;
23+
align-items: flex-end;
24+
}
25+
.box__created_at {
26+
grid-area: time;
27+
}
28+
.box__purpose {
29+
grid-area: purpose;
30+
}
31+
.box__samples {
32+
grid-area: samples;
33+
}
34+
.btn-link {
35+
display: block;
36+
}
1837
}
1938

2039
.qc-info-message {

app/controllers/boxes_controller.rb

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class BoxesController < ApplicationController
2-
before_action :load_box, except: %i[index new create bulk_destroy]
2+
before_action :load_box, only: %i[show destroy]
3+
before_action :load_box_print, only: %i[print inventory]
34
helper_method :samples_data
45

56
def index
@@ -22,9 +23,9 @@ def show
2223
end
2324

2425
def inventory
25-
return unless authorize_resource(@box, READ_BOX)
26+
return unless authorize_resource( box_resource(@box), READ_BOX )
2627

27-
@samples = load_box_samples
28+
@samples = load_box_samples( sender? )
2829

2930
respond_to do |format|
3031
format.csv do
@@ -34,14 +35,16 @@ def inventory
3435
end
3536

3637
def print
37-
return unless authorize_resource(@box, READ_BOX)
38+
return unless authorize_resource( box_resource(@box), READ_BOX )
39+
40+
@samples = load_box_samples
3841

3942
render pdf: "cdx_box_#{@box.uuid}",
4043
template: "boxes/print.pdf",
4144
layout: "layouts/pdf.html",
4245
locals: {
4346
box: @box,
44-
samples: @box.samples.preload(:batch, :sample_identifiers),
47+
samples: @samples,
4548
},
4649
margin: { top: 0, bottom: 0, left: 0, right: 0 },
4750
page_width: "1in",
@@ -100,10 +103,36 @@ def load_box
100103
end
101104
end
102105

103-
def load_box_samples
106+
def load_box_print
107+
@box = Box.where(institution: @navigation_context.institution, id: params.fetch(:id)).take
108+
if @box.nil?
109+
@box = Box
110+
.joins(box_transfers: :transfer_package)
111+
.merge( TransferPackage.within( @navigation_context.institution ) )
112+
.where(id: params.fetch(:id))
113+
.take
114+
end
115+
end
116+
117+
def load_box_samples( force_unblind = false )
104118
samples = @box.samples.preload(:batch, :sample_identifiers)
105-
samples = samples.scrambled if @box.blinded?
106-
SamplePresenter.map(samples, request.format)
119+
if !@box.blinded or sender?
120+
samples = samples.sort_by{ |sample| [sample.batch_number, sample.concentration, sample.replicate ] }
121+
else
122+
samples = samples.scrambled
123+
end
124+
unless force_unblind
125+
samples = SamplePresenter.map(samples, request.format)
126+
end
127+
samples
128+
end
129+
130+
def sender?
131+
return @sender unless @sender.nil?
132+
@sender = BoxTransfer
133+
.joins(:transfer_package)
134+
.where( box_id: params.fetch(:id), transfer_packages: { sender_institution_id: @navigation_context.institution } )
135+
.exists?
107136
end
108137

109138
def load_batches
@@ -139,4 +168,16 @@ def samples_data(samples)
139168
}
140169
end
141170
end
171+
172+
def box_resource(box)
173+
return box if box.institution_id == @navigation_context.institution.id || !sender?
174+
175+
# the box is being transferred or the user is the sender:
176+
{
177+
resource_type: "box",
178+
resource_id: box.id,
179+
institution_id: @navigation_context.institution.id,
180+
site_id: @navigation_context.site.try(&:uuid),
181+
}
182+
end
142183
end

app/controllers/samples_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def index
3030
@samples = perform_pagination(@samples)
3131
.preload(:batch, :sample_identifiers)
3232

33-
@samples = @samples.map { |sample| SamplePresenter.new(sample, request.format ) }
33+
@samples = SamplePresenter.map(@samples, request.format )
3434
end
3535

3636
def autocomplete
@@ -119,6 +119,7 @@ def print
119119
@sample = Sample.find(params[:id])
120120
return unless authorize_resource(@sample, READ_SAMPLE)
121121

122+
@sample = SamplePresenter.new(@sample, request.format)
122123
render pdf: "cdx_sample_#{@sample.uuid}",
123124
template: "samples/barcode.pdf",
124125
layout: "layouts/pdf.html",

app/controllers/transfer_packages_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def show
3636
.within(@navigation_context.institution)
3737
.includes(:box_transfers, :boxes)
3838
.find(params[:id])
39-
39+
@show_print_buttons = true
4040
@transfer_package = TransferPackagePresenter.new(transfer_package, @navigation_context)
4141

4242
@view_helper = view_helper({ save_back_path: true })
@@ -76,8 +76,10 @@ def find_box
7676
full_uuid = uuid.size == 36
7777
@boxes = Box
7878
.within(@navigation_context.entity, @navigation_context.exclude_subsites)
79+
.left_joins(:box_transfers)
80+
.where(box_transfers: {id: nil})
7981
.autocomplete(uuid)
80-
.order("created_at DESC")
82+
.order("boxes.created_at DESC")
8183
.count_samples
8284
.limit(5)
8385

app/views/boxes/_barcode_card.haml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,3 @@
1212
.logo
1313
= image_tag 'cdx-logo-bw.png'
1414
.label https://cdx.io
15-
16-
17-
.row.actions
18-
- unless @box.blinded?
19-
= link_to print_box_path(@box), target: "_blank", class: 'btn-link' do
20-
.icon-print.btn-icon
21-
%span Print box and sample labels

app/views/boxes/_preview.haml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
.box-preview
22
.box__uuid{title: "UUID"}
33
= box.uuid
4+
5+
.box__created_at{title: "Creation date"}
6+
= time_tag box.created_at, I18n.l(box.created_at, format: I18n.t("date.formats.long"))
7+
48
.box__purpose{title: "Purpose"}
59
= box.purpose
610
.box__samples{title: "Samples"}
711
= box.samples_count
812
samples
9-
.box__created_at{title: "Creation date"}
10-
= time_tag box.created_at, I18n.l(box.created_at, format: I18n.t("date.formats.long"))
13+
14+
.box__btns{title: "Actions"}
15+
- if @show_print_buttons and !@can_confirm
16+
= link_to print_box_path(box), target: "_blank", class: 'btn-link' do
17+
.icon-print.btn-icon
18+
%span Print box and sample labels
19+
20+
= link_to inventory_box_path(box, format: "csv"), target: "_blank", class: 'btn-link' do
21+
.icon-download.btn-icon
22+
%span Download inventory

app/views/boxes/inventory.csv.csvbuilder

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ csv << [
44
"Label ID (QR code)",
55
"Batch ID",
66
"Virus Lineage",
7-
"Replicate",
87
"Production Date",
98
"Concentration",
9+
"Replicate",
1010
"Inactivation Method",
1111
"Media",
1212
]
@@ -18,9 +18,9 @@ csv << [
1818
sample.uuid,
1919
sample.batch_number,
2020
sample.virus_lineage,
21-
sample.replicate,
2221
sample.date_produced.to_date,
2322
sample.concentration_formula,
23+
sample.replicate,
2424
sample.inactivation_method,
2525
sample.media,
2626
]

app/views/boxes/show.haml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
.col
3131
= render "barcode_card"
3232

33-
.barcode-after
34-
= link_to inventory_box_path(@box, format: "csv"), target: "_blank", class: 'btn-link' do
35-
.icon-download.btn-icon
36-
%span Download inventory
37-
3833
.row
3934
.col
4035
.row

app/views/samples/barcode.pdf.haml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
#{sample.uuid}
1010
.code
1111
I.N. #{sample.isolate_name}
12-
.code
13-
I.M. #{sample.inactivation_method}
12+
- if sample.box
13+
.code
14+
Purpose: #{sample.box.purpose}
15+
- else
16+
.code
17+
I.M. #{sample.inactivation_method}
1418
.code
1519
P.D. #{sample.date_produced_description}
1620
.logo

0 commit comments

Comments
 (0)