Your question is Code Review for Readability and Performance. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
CereCore provides IT services for hospital systems, including a patient lookup service used by front-desk staff. New engineers on the team say this class takes them far too long to understand.
public class PatientLookupService {
private List<Patient> a;
public Patient findByMrn(String x1) {
for (int i = 0; i < a.size(); i++) {
Patient tmp = a.get(i);
for (int j = 0; j < a.size(); j++) {
if (a.get(j).getMrn().equals(x1) && a.get(j).getStatus().equals("ACTIVE")) {
return a.get(j);
}
}
}
return null;
}
public Patient findByName(String name) {
String query = "SELECT * FROM patients WHERE name = '" + name + "' AND status = 'ACTIVE'";
return executeQuery(query);
}
}
Review this snippet and suggest improvements for readability and performance. Name specific problems and explain how you would fix each one.