Commit 5307212f authored by pierre.tremouilhac's avatar pierre.tremouilhac
Browse files

Merge branch '256-report-shows-sample-molecule-name' into 'development'

Report - use sample molecule name

Closes #256

See merge request !451
parents 9deeb0f2 3aa9b1f9
...@@ -8,22 +8,34 @@ import { Alphabet } from '../utils/ElementUtils'; ...@@ -8,22 +8,34 @@ import { Alphabet } from '../utils/ElementUtils';
import _ from 'lodash'; import _ from 'lodash';
const insertBlank = (target) => { const insertBlank = (target) => {
if(target.length === 0) return true; if (target.length === 0) return true;
const content = target.map(t => t.insert).join('').replace(/\s+/, ''); const content = target.map(t => t.insert).join('').replace(/\s+/, '');
return !content; return !content;
}; };
const Title = ({el, counter}) => { const sampleMoleculeName = (s) => {
let iupacs = el.products.map( (p, i) => { const mnh = s.molecule_name_hash;
const mnLabel = mnh ? mnh.label : null;
const iupac = s.molecule.iupac_name;
if (mnLabel) {
return mnLabel;
} else if (iupac) {
return iupac;
}
return null;
};
const Title = ({ el, counter }) => {
let iupacs = el.products.map((p, i) => {
const key1 = `${i}-text`; const key1 = `${i}-text`;
const key2 = `${i}-slash`; const key2 = `${i}-slash`;
if(p.molecule.iupac_name) { const smn = sampleMoleculeName(p);
return [<span key={key1}>{p.molecule.iupac_name}</span>, if (smn) {
<span key={key2}> / </span>]; return [<span key={key1}>{smn}</span>,
} else { <span key={key2}> / </span>];
return [<span key={key1}>"<b>NAME</b>"</span>,
<span key={key2}> / </span>];
} }
return [<span key={key1}>"<b>NAME</b>"</span>,
<span key={key2}> / </span>];
}); });
iupacs = _.flatten(iupacs).slice(0, -1); iupacs = _.flatten(iupacs).slice(0, -1);
...@@ -34,15 +46,15 @@ const Title = ({el, counter}) => { ...@@ -34,15 +46,15 @@ const Title = ({el, counter}) => {
<span> (<b>xx</b>)</span> <span> (<b>xx</b>)</span>
</p> </p>
); );
} };
const deltaIupac = (m) => { const deltaSampleMoleculeName = (s) => {
return ( const smn = sampleMoleculeName(s);
m.iupac_name if (smn) {
? { insert: m.iupac_name } return { insert: smn };
: { attributes: { bold: "true" }, insert: "\"NAME\""} }
); return { attributes: { bold: 'true' }, insert: '"NAME"' };
} };
const boldXX = () => { const boldXX = () => {
return { attributes: { bold: "true" }, insert: "xx" }; return { attributes: { bold: "true" }, insert: "xx" };
...@@ -70,7 +82,7 @@ const ProductsInfo = ({products = []}) => { ...@@ -70,7 +82,7 @@ const ProductsInfo = ({products = []}) => {
const pMMass = `Molecular Mass: ${digit(m.molecular_weight, 4)}; `; const pMMass = `Molecular Mass: ${digit(m.molecular_weight, 4)}; `;
const pEMass = `Exact Mass: ${digit(m.exact_molecular_weight, 4)}; `; const pEMass = `Exact Mass: ${digit(m.exact_molecular_weight, 4)}; `;
const pEA = `EA: ${ea}.`; const pEA = `EA: ${ea}.`;
content = [...content, { insert: "Name: " }, deltaIupac(m), content = [...content, { insert: "Name: " }, deltaSampleMoleculeName(p),
{ insert: "; " }, { insert: "; " },
{ insert: pFormula + pCAS + pSmiles + { insert: pFormula + pCAS + pSmiles +
pInCHI + pMMass + pEMass + pEA }, pInCHI + pMMass + pEMass + pEA },
...@@ -85,12 +97,11 @@ const stAndReContent = (el, prev_counter, prev_content) => { ...@@ -85,12 +97,11 @@ const stAndReContent = (el, prev_counter, prev_content) => {
let content = prev_content; let content = prev_content;
[...el.starting_materials, ...el.reactants].forEach(el => { [...el.starting_materials, ...el.reactants].forEach(el => {
counter += 1; counter += 1;
const m = el.molecule;
content = [...content, content = [...content,
{ insert: `{${Alphabet(counter)}|` }, { insert: `{${Alphabet(counter)}|` },
boldXX(), boldXX(),
{ insert: "} " }, { insert: "} " },
deltaIupac(m), deltaSampleMoleculeName(el),
{ insert: ` (${el.amount_g} g, ${digit(el.amount_mol * 1000, 4)} mmol, ${digit(el.equivalent, 2)} equiv.); ` }]; { insert: ` (${el.amount_g} g, ${digit(el.amount_mol * 1000, 4)} mmol, ${digit(el.equivalent, 2)} equiv.); ` }];
}); });
return { counter: counter, content: content }; return { counter: counter, content: content };
...@@ -101,11 +112,10 @@ const solventsContent = (el, prev_counter, prev_content) => { ...@@ -101,11 +112,10 @@ const solventsContent = (el, prev_counter, prev_content) => {
let content = prev_content; let content = prev_content;
el.solvents.forEach(el => { el.solvents.forEach(el => {
counter += 1; counter += 1;
const m = el.molecule;
content = [...content, content = [...content,
{ insert: `{${Alphabet(counter)}` }, { insert: `{${Alphabet(counter)}` },
{ insert: "} " }, { insert: "} " },
deltaIupac(m), deltaSampleMoleculeName(el),
{ insert: ` (${digit(el.amount_l * 1000, 2)} mL); ` }]; { insert: ` (${digit(el.amount_l * 1000, 2)} mL); ` }];
}); });
return { counter: counter, content: content }; return { counter: counter, content: content };
......
...@@ -75,7 +75,7 @@ module Reporter ...@@ -75,7 +75,7 @@ module Reporter
delta = [{"insert"=>"[4.#{@index + 1}] "}] delta = [{"insert"=>"[4.#{@index + 1}] "}]
obj.products.each do |p| obj.products.each do |p|
delta = delta + delta = delta +
iupac_delta(p[:molecule][:iupac_name]) + sample_molecule_name_delta(p) +
[{"insert"=>" / "}] [{"insert"=>" / "}]
end end
delta.pop delta.pop
...@@ -99,7 +99,7 @@ module Reporter ...@@ -99,7 +99,7 @@ module Reporter
m = p[:molecule] m = p[:molecule]
cas = (p[:xref] && p[:xref][:cas] && p[:xref][:cas][:label]) || "- " cas = (p[:xref] && p[:xref][:cas] && p[:xref][:cas][:label]) || "- "
delta += [{"insert"=> "Name: " }] + delta += [{"insert"=> "Name: " }] +
iupac_delta(m[:iupac_name]) + sample_molecule_name_delta(p) +
[{"insert"=> "; " }] [{"insert"=> "; " }]
delta += sum_formular_delta(m) delta += sum_formular_delta(m)
delta += misc_delta(cas, m) delta += misc_delta(cas, m)
...@@ -226,7 +226,8 @@ module Reporter ...@@ -226,7 +226,8 @@ module Reporter
vol: fixed_digit(s.amount_ml, digit), vol: fixed_digit(s.amount_ml, digit),
density: fixed_digit(s.density, digit), density: fixed_digit(s.density, digit),
mol: fixed_digit(s.amount_mmol, digit), mol: fixed_digit(s.amount_mmol, digit),
equiv: fixed_digit(s.equivalent, digit) equiv: fixed_digit(s.equivalent, digit),
molecule_name_hash: s[:molecule_name_hash]
} }
if is_product if is_product
...@@ -235,7 +236,8 @@ module Reporter ...@@ -235,7 +236,8 @@ module Reporter
mass: fixed_digit(s.real_amount_g, digit), mass: fixed_digit(s.real_amount_g, digit),
vol: fixed_digit(s.real_amount_ml, digit), vol: fixed_digit(s.real_amount_ml, digit),
mol: fixed_digit(s.real_amount_mmol, digit), mol: fixed_digit(s.real_amount_mmol, digit),
equiv: equiv equiv: equiv,
molecule_name_hash: s[:molecule_name_hash]
}) })
end end
...@@ -396,7 +398,7 @@ module Reporter ...@@ -396,7 +398,7 @@ module Reporter
delta += [{"insert"=>"{#{alphabet(counter)}|"}, delta += [{"insert"=>"{#{alphabet(counter)}|"},
{"attributes"=>{"bold"=>"true"}, "insert"=>"xx"}, {"attributes"=>{"bold"=>"true"}, "insert"=>"xx"},
{"insert"=>"} "}, {"insert"=>"} "},
*iupac_delta(m[:iupac_name]), *sample_molecule_name_delta(m),
{"insert"=>" (#{m[:mass]} g, #{m[:mol]} mmol, " + {"insert"=>" (#{m[:mass]} g, #{m[:mol]} mmol, " +
"#{fixed_digit(m[:equiv], 2)} equiv.); "}] "#{fixed_digit(m[:equiv], 2)} equiv.); "}]
end end
...@@ -405,7 +407,7 @@ module Reporter ...@@ -405,7 +407,7 @@ module Reporter
counter += 1 counter += 1
delta += [{"insert"=>"{#{alphabet(counter)}"}, delta += [{"insert"=>"{#{alphabet(counter)}"},
{"insert"=>"} "}, {"insert"=>"} "},
*iupac_delta(m[:iupac_name]), *sample_molecule_name_delta(m),
{"insert"=>" (#{fixed_digit(m[:vol], 2)} mL); "}] {"insert"=>" (#{fixed_digit(m[:vol], 2)} mL); "}]
end end
delta += [{"insert"=>"Yield "}] delta += [{"insert"=>"Yield "}]
...@@ -436,13 +438,18 @@ module Reporter ...@@ -436,13 +438,18 @@ module Reporter
]) ])
end end
def iupac_delta(iupac) def sample_molecule_name_delta(sample)
if iupac mnh = sample[:molecule_name_hash]
return [{"insert"=>"#{iupac}"}] smn = mnh ? mnh[:label] : nil
iupac = sample[:molecule] ? sample[:molecule][:iupac_name] : nil
if smn.present?
[{ 'insert' => smn.to_s }]
elsif iupac.present?
[{ 'insert' => iupac.to_s }]
else else
return [{"insert"=>"\""}, [{ 'insert' => '"' },
{"attributes"=>{"bold"=>"true"}, "insert"=>"NAME"}, { 'attributes' => { 'bold' => 'true' }, 'insert' => 'NAME' },
{"insert"=>"\""}] { 'insert' => '"' }]
end end
end end
......
...@@ -130,9 +130,9 @@ describe 'Reporter::Docx::DetailReaction instance' do ...@@ -130,9 +130,9 @@ describe 'Reporter::Docx::DetailReaction instance' do
expect(target.send(:synthesis_title_delta)).to eq( expect(target.send(:synthesis_title_delta)).to eq(
[ [
{"insert"=>"[4.#{prev_index + 1}] "}, {"insert"=>"[4.#{prev_index + 1}] "},
{"insert"=>"#{s2.molecule.iupac_name}"}, {"insert"=>"#{s2.molecule_name_hash[:label]}"},
{"insert"=>" / "}, {"insert"=>" / "},
{"insert"=>"#{s3.molecule.iupac_name}"}, {"insert"=>"#{s3.molecule_name_hash[:label]}"},
{"insert"=>" ("}, {"insert"=>" ("},
{"attributes"=>{"bold"=>"true"}, "insert"=>"xx"}, {"attributes"=>{"bold"=>"true"}, "insert"=>"xx"},
{"insert"=>")"} {"insert"=>")"}
...@@ -141,7 +141,7 @@ describe 'Reporter::Docx::DetailReaction instance' do ...@@ -141,7 +141,7 @@ describe 'Reporter::Docx::DetailReaction instance' do
expect(target.send(:products_delta)).to eq( expect(target.send(:products_delta)).to eq(
[ [
{"insert"=>"Name: "}, {"insert"=>"Name: "},
{"insert"=>"#{s2.molecule.iupac_name}"}, {"insert"=>"#{s2.molecule_name_hash[:label]}"},
{"insert"=>"; "}, {"insert"=>"; "},
{"insert"=>"Formula: "}, {"insert"=>"Formula: "},
{"insert"=>"H"}, {"insert"=>"H"},
...@@ -157,7 +157,7 @@ describe 'Reporter::Docx::DetailReaction instance' do ...@@ -157,7 +157,7 @@ describe 'Reporter::Docx::DetailReaction instance' do
{"insert"=>"."}, {"insert"=>"."},
{"insert"=>"\n"}, {"insert"=>"\n"},
{"insert"=>"Name: "}, {"insert"=>"Name: "},
{"insert"=>"#{s3.molecule.iupac_name}"}, {"insert"=>"#{s3.molecule_name_hash[:label]}"},
{"insert"=>"; "}, {"insert"=>"; "},
{"insert"=>"Formula: "}, {"insert"=>"Formula: "},
{"insert"=>"H"}, {"insert"=>"H"},
...@@ -181,7 +181,7 @@ describe 'Reporter::Docx::DetailReaction instance' do ...@@ -181,7 +181,7 @@ describe 'Reporter::Docx::DetailReaction instance' do
{"insert"=>"{A|"}, {"insert"=>"{A|"},
{"attributes"=>{"bold"=>"true"}, "insert"=>"xx"}, {"attributes"=>{"bold"=>"true"}, "insert"=>"xx"},
{"insert"=>"} "}, {"insert"=>"} "},
{"insert"=>"#{s2.molecule.iupac_name}"}, {"insert"=>"#{s2.molecule_name_hash[:label]}"},
{"insert"=>" (1.000 g, 55.508 mmol, 0.88 equiv.); "}, {"insert"=>" (1.000 g, 55.508 mmol, 0.88 equiv.); "},
{"insert"=>"{B"}, {"insert"=>"{B"},
{"insert"=>"} "}, {"insert"=>"} "},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment