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';
import _ from 'lodash';
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+/, '');
return !content;
};
const Title = ({el, counter}) => {
let iupacs = el.products.map( (p, i) => {
const sampleMoleculeName = (s) => {
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 key2 = `${i}-slash`;
if(p.molecule.iupac_name) {
return [<span key={key1}>{p.molecule.iupac_name}</span>,
const smn = sampleMoleculeName(p);
if (smn) {
return [<span key={key1}>{smn}</span>,
<span key={key2}> / </span>];
} else {
}
return [<span key={key1}>"<b>NAME</b>"</span>,
<span key={key2}> / </span>];
}
});
iupacs = _.flatten(iupacs).slice(0, -1);
......@@ -34,15 +46,15 @@ const Title = ({el, counter}) => {
<span> (<b>xx</b>)</span>
</p>
);
}
};
const deltaIupac = (m) => {
return (
m.iupac_name
? { insert: m.iupac_name }
: { attributes: { bold: "true" }, insert: "\"NAME\""}
);
}
const deltaSampleMoleculeName = (s) => {
const smn = sampleMoleculeName(s);
if (smn) {
return { insert: smn };
}
return { attributes: { bold: 'true' }, insert: '"NAME"' };
};
const boldXX = () => {
return { attributes: { bold: "true" }, insert: "xx" };
......@@ -70,7 +82,7 @@ const ProductsInfo = ({products = []}) => {
const pMMass = `Molecular Mass: ${digit(m.molecular_weight, 4)}; `;
const pEMass = `Exact Mass: ${digit(m.exact_molecular_weight, 4)}; `;
const pEA = `EA: ${ea}.`;
content = [...content, { insert: "Name: " }, deltaIupac(m),
content = [...content, { insert: "Name: " }, deltaSampleMoleculeName(p),
{ insert: "; " },
{ insert: pFormula + pCAS + pSmiles +
pInCHI + pMMass + pEMass + pEA },
......@@ -85,12 +97,11 @@ const stAndReContent = (el, prev_counter, prev_content) => {
let content = prev_content;
[...el.starting_materials, ...el.reactants].forEach(el => {
counter += 1;
const m = el.molecule;
content = [...content,
{ insert: `{${Alphabet(counter)}|` },
boldXX(),
{ insert: "} " },
deltaIupac(m),
deltaSampleMoleculeName(el),
{ insert: ` (${el.amount_g} g, ${digit(el.amount_mol * 1000, 4)} mmol, ${digit(el.equivalent, 2)} equiv.); ` }];
});
return { counter: counter, content: content };
......@@ -101,11 +112,10 @@ const solventsContent = (el, prev_counter, prev_content) => {
let content = prev_content;
el.solvents.forEach(el => {
counter += 1;
const m = el.molecule;
content = [...content,
{ insert: `{${Alphabet(counter)}` },
{ insert: "} " },
deltaIupac(m),
deltaSampleMoleculeName(el),
{ insert: ` (${digit(el.amount_l * 1000, 2)} mL); ` }];
});
return { counter: counter, content: content };
......
......@@ -75,7 +75,7 @@ module Reporter
delta = [{"insert"=>"[4.#{@index + 1}] "}]
obj.products.each do |p|
delta = delta +
iupac_delta(p[:molecule][:iupac_name]) +
sample_molecule_name_delta(p) +
[{"insert"=>" / "}]
end
delta.pop
......@@ -99,7 +99,7 @@ module Reporter
m = p[:molecule]
cas = (p[:xref] && p[:xref][:cas] && p[:xref][:cas][:label]) || "- "
delta += [{"insert"=> "Name: " }] +
iupac_delta(m[:iupac_name]) +
sample_molecule_name_delta(p) +
[{"insert"=> "; " }]
delta += sum_formular_delta(m)
delta += misc_delta(cas, m)
......@@ -226,7 +226,8 @@ module Reporter
vol: fixed_digit(s.amount_ml, digit),
density: fixed_digit(s.density, 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
......@@ -235,7 +236,8 @@ module Reporter
mass: fixed_digit(s.real_amount_g, digit),
vol: fixed_digit(s.real_amount_ml, digit),
mol: fixed_digit(s.real_amount_mmol, digit),
equiv: equiv
equiv: equiv,
molecule_name_hash: s[:molecule_name_hash]
})
end
......@@ -396,7 +398,7 @@ module Reporter
delta += [{"insert"=>"{#{alphabet(counter)}|"},
{"attributes"=>{"bold"=>"true"}, "insert"=>"xx"},
{"insert"=>"} "},
*iupac_delta(m[:iupac_name]),
*sample_molecule_name_delta(m),
{"insert"=>" (#{m[:mass]} g, #{m[:mol]} mmol, " +
"#{fixed_digit(m[:equiv], 2)} equiv.); "}]
end
......@@ -405,7 +407,7 @@ module Reporter
counter += 1
delta += [{"insert"=>"{#{alphabet(counter)}"},
{"insert"=>"} "},
*iupac_delta(m[:iupac_name]),
*sample_molecule_name_delta(m),
{"insert"=>" (#{fixed_digit(m[:vol], 2)} mL); "}]
end
delta += [{"insert"=>"Yield "}]
......@@ -436,13 +438,18 @@ module Reporter
])
end
def iupac_delta(iupac)
if iupac
return [{"insert"=>"#{iupac}"}]
def sample_molecule_name_delta(sample)
mnh = sample[:molecule_name_hash]
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
return [{"insert"=>"\""},
{"attributes"=>{"bold"=>"true"}, "insert"=>"NAME"},
{"insert"=>"\""}]
[{ 'insert' => '"' },
{ 'attributes' => { 'bold' => 'true' }, 'insert' => 'NAME' },
{ 'insert' => '"' }]
end
end
......
......@@ -130,9 +130,9 @@ describe 'Reporter::Docx::DetailReaction instance' do
expect(target.send(:synthesis_title_delta)).to eq(
[
{"insert"=>"[4.#{prev_index + 1}] "},
{"insert"=>"#{s2.molecule.iupac_name}"},
{"insert"=>"#{s2.molecule_name_hash[:label]}"},
{"insert"=>" / "},
{"insert"=>"#{s3.molecule.iupac_name}"},
{"insert"=>"#{s3.molecule_name_hash[:label]}"},
{"insert"=>" ("},
{"attributes"=>{"bold"=>"true"}, "insert"=>"xx"},
{"insert"=>")"}
......@@ -141,7 +141,7 @@ describe 'Reporter::Docx::DetailReaction instance' do
expect(target.send(:products_delta)).to eq(
[
{"insert"=>"Name: "},
{"insert"=>"#{s2.molecule.iupac_name}"},
{"insert"=>"#{s2.molecule_name_hash[:label]}"},
{"insert"=>"; "},
{"insert"=>"Formula: "},
{"insert"=>"H"},
......@@ -157,7 +157,7 @@ describe 'Reporter::Docx::DetailReaction instance' do
{"insert"=>"."},
{"insert"=>"\n"},
{"insert"=>"Name: "},
{"insert"=>"#{s3.molecule.iupac_name}"},
{"insert"=>"#{s3.molecule_name_hash[:label]}"},
{"insert"=>"; "},
{"insert"=>"Formula: "},
{"insert"=>"H"},
......@@ -181,7 +181,7 @@ describe 'Reporter::Docx::DetailReaction instance' do
{"insert"=>"{A|"},
{"attributes"=>{"bold"=>"true"}, "insert"=>"xx"},
{"insert"=>"} "},
{"insert"=>"#{s2.molecule.iupac_name}"},
{"insert"=>"#{s2.molecule_name_hash[:label]}"},
{"insert"=>" (1.000 g, 55.508 mmol, 0.88 equiv.); "},
{"insert"=>"{B"},
{"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