I'm parsing out a bunch of employee incident reports for reporting purposes.
The incident reports themselves are free text, and I have to categorize the injuries by body location. I'm trying to avoid if{}elseif{}elseif{}....}else{}
.
Example incident reports:
Employee slipped on wet stairs and injured her knee and right arm, and struck her head on the handrail.
Should add "knee", "arm", and "head" to affected area.
Employee was lifting boxes without approved protective equipment resulting in a back strain.
Should add "back" to affected area.
While attempting to unjam copier, employee got right index finger caught in machinery resulting in a 1-inch cut.
Should add "finger" to affected area.
Right now, I have:
private static StaffInjuryData setAffectedAreas(String incident, StaffInjuryData sid){
incident = incident.toUpperCase(); //eliminate case issues
if(incident.contains("HEAD")){
sid.addAffectedArea("HEAD");
}else if(incident.contains("FACE")){
sid.addAffectedArea("FACE");
}else if(incident.contains("EYE")){
sid.addAffectedArea("EYE");
}else if(incident.contains("NOSE")){
sid.addAffectedArea("NOSE");
}
//etc, etc, etc
return sid;
}
Is there an easier/more efficient way then if-elseif-ad inifinitum to do this?