From 6c7a27f2588471bfcb31c82f75ca7e20c1c7fe8d Mon Sep 17 00:00:00 2001 From: frankknoll Date: Fri, 24 Mar 2023 18:07:59 +0100 Subject: [PATCH] refactoring --- src/BatchcodeCompletion.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/BatchcodeCompletion.py b/src/BatchcodeCompletion.py index 6027cc683cc..23371ac9775 100644 --- a/src/BatchcodeCompletion.py +++ b/src/BatchcodeCompletion.py @@ -6,6 +6,11 @@ class BatchcodeCompletion: self.ADR_by_Batchcode = ADR_by_Batchcode.sort_values(by = 'Adverse Reaction Reports', ascending = False) def completeBatchcode(self, partialBatchcode): + return self._getBatchcodeHavingMostADRs(self._filterBy(partialBatchcode)) + + def _filterBy(self, partialBatchcode): smartRegexp = SmartRegexpFactory().createSmartRegexp(partialBatchcode) - filteredBbatchCodeTable = self.ADR_by_Batchcode[self.ADR_by_Batchcode.index.str.contains(smartRegexp, na=False, regex=True)] - return filteredBbatchCodeTable.index[0] if not filteredBbatchCodeTable.empty else None + return self.ADR_by_Batchcode[self.ADR_by_Batchcode.index.str.contains(smartRegexp, na = False, regex = True)] + + def _getBatchcodeHavingMostADRs(self, ADR_by_Batchcode): + return ADR_by_Batchcode.index[0] if not ADR_by_Batchcode.empty else None