Syntax error in formula from a newbie

if field(‘DiagnosisCode’) == ‘D1234’
‘Chronic Lower Back Pain’
elsif field(‘DiagnosisCode’) == ‘E5678’
‘Type 2 Diabetes Mellitus’
elsif field(‘DiagnosisCode’) == ‘F91011’
‘Essential Hypertension’
elsif field(‘DiagnosisCode’) == ‘G1213’
‘Acute Bronchitis’
elsif field(‘DiagnosisCode’) == ‘H1415’
‘Generalised Anxiety Disorder’
elsif field(‘DiagnosisCode’) == ‘I1617’
‘Iron Deficiency Anaemia’
elsif field(‘DiagnosisCode’) == ‘J1819’
‘Migraine without Aura’
elsif field(‘DiagnosisCode’) == ‘K2021’
‘Hyperlipidemia’
elsif field(‘DiagnosisCode’) == ‘L2223’
‘Chronic Kidney Disease Stage 3’
elsif field(‘DiagnosisCode’) == ‘M2425’
‘Asthma, Unspecified’
else
‘Other Diagnosis’
end
please kindly help

Two things;

  1. The syntax error is likely from the use of non-standard quote marks. Mockaroo expects straight quotes (' and "), but it looks like you’re using curly quotes ( and ).
  2. You need to use return for each output line.
if field('DiagnosisCode') == 'D1234'
  return 'Chronic Lower Back Pain'
elsif field('DiagnosisCode') == 'E5678'
  return 'Type 2 Diabetes Mellitus'
elsif field('DiagnosisCode') == 'F91011'
  return 'Essential Hypertension'
elsif field('DiagnosisCode') == 'G1213'
  return 'Acute Bronchitis'
elsif field('DiagnosisCode') == 'H1415'
  return 'Generalised Anxiety Disorder'
elsif field('DiagnosisCode') == 'I1617'
  return 'Iron Deficiency Anaemia'
elsif field('DiagnosisCode') == 'J1819'
  return 'Migraine without Aura'
elsif field('DiagnosisCode') == 'K2021'
  return 'Hyperlipidemia'
elsif field('DiagnosisCode') == 'L2223'
  return 'Chronic Kidney Disease Stage 3'
elsif field('DiagnosisCode') == 'M2425'
  return 'Asthma, Unspecified'
else
  return 'Other Diagnosis'
end
1 Like

I would also consider using a case statement like below

case field(‘DiagnosisCode’)
when ‘D1234’
return ‘Chronic Lower Back Pain’
when ‘E5678’
return ‘Type 2 Diabetes Mellitus
when ‘F91011’
return ‘Essential Hypertension’

else
return ‘Other Diagnosis’
end

1 Like

thank you @BilltheCat

1 Like