I have this map that contains a list of maps inside and I want to remove specific values from this.
%{
"id" => 1
"rxs" => [
%{
"antibiotic" => %{
"id" => 6042,
"is_active" => true,
"name" => "Christy",
},
"antibiotic_prescription_changed_to" => %{
"antibiotic" => %{
"id" => 6042,
"is_active" => true,
"name" => "Christy",
},
"antibiotic_prescription_changed_to" => %{
"antibiotic" => %{
"id" => 6042,
"is_active" => true,
"name" => "Christy",
},
"antibiotic_prescription_changed_to" => nil,
"date_end" => nil,
"date_prescribed" => nil,
"date_start" => "2019-03-11",
"dose" => "10mg/mL",
"encounter" => nil,
"frequency" => nil,
"id" => 5751,
"modified_at" => "2019-08-01T13:04:09",
"modified_by" => nil,
"notes" => nil,
"prescribed_before_admission" => false,
"prescribing_clinician" => nil,
"prophylaxis" => false,
"prophylaxis_indications" => [],
...
},
"date_end" => nil,
"date_prescribed" => nil,
"date_start" => "2019-03-11",
"dose" => nil,
"id" => 5752,
"modified_at" => "2019-08-01T13:04:09",
"modified_by" => nil,
"notes" => nil,
"prescribed_before_admission" => false,
"prophylaxis" => false,
"prophylaxis_indications" => []
},
"date_end" => nil,
"date_prescribed" => nil,
"date_start" => "2019-03-11",
"dose" => "2 pills a day",
"encounter" => %{
"admission_date" => "2017-01-01T00:00:00Z",
"id" => 3636,
"is_active" => true,
"notes" => "A9Q1KGKq",
"patient_id" => 4862
},
"frequency" => nil,
"id" => 5753,
"modified_at" => "2019-08-01T13:04:09",
"modified_by" => nil,
"notes" => nil,
"prescribed_before_admission" => false,
"prescribing_clinician" => nil,
"prophylaxis" => false,
"prophylaxis_indications" => [],
"route" => nil
}
],
"schema_version" => 10
}
I want to remove
all the key-value pairs of id
and modified_at
from antibiotic_prescription_changed_to
. It is deeply nested and may contain multiple nested antibiotic_prescription_changed_to
.
Some generic approach that will remove these values no matter how many nested maps I get.
I am thinking about some recursion function. which will keep looping in these antibiotic_prescription_changed_to
and return the final result once it gets nil
.
But the main problem I think is removing all these values and then placed them inside the original map.
Any help will be much appreciated
Thanks