Skip to content

Commit

Permalink
Fix fill back DN numbers for procedure 2077
Browse files Browse the repository at this point in the history
  • Loading branch information
maatinito committed Oct 17, 2023
1 parent 45f23f6 commit e1f219c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/tasks/deployment/20231017170220_fill_back_dn.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace :after_party do
desc 'Deployment task: Fill back DNs for procedure 2077'
task fill_back_dn: :environment do
puts "Running deploy task 'fill_back_dn'"

DN_PATH = "storage/numeros_dn.json"
next unless File.exist?(DN_PATH)

numeros_dn = JSON.parse(File.read(DN_PATH))
procedure_id = 2077

progress = ProgressReport.new(1)
repetitions = Champ.joins(dossier: :procedure)
.where(type: "Champs::RepetitionChamp",
dossiers: { procedure_revisions: { procedure_id: procedure_id } })
.flat_map(&:rows)
progress.inc
progress.finish
progress = ProgressReport.new(repetitions.count)

repetitions.each do |row|
champ_dn = champ(row, 'Numero DN')
if champ_dn&.numero_dn.blank?
key = "#{champ(row, "Nom de l'enfant")&.value}:#{champ(row, "Prénom de l'enfant")&.value}"
if numeros_dn.key?(key)
(dn, ddn) = numeros_dn[key].split(':')
champ_dn.numero_dn = dn
champ_dn.date_de_naissance = ddn
champ_dn.save
end
end
progress.inc
end
progress.finish

# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end

def champ(row, label) = row.find { |c| c.type_de_champ.libelle == label }
end

0 comments on commit e1f219c

Please sign in to comment.