prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Scans with low number of Slices are not properly loaded on Labeling page
  ## Current Behavior
  
  When Scan has less than 10 Slices, Scan Viewer keeps displaying spinner indicator and never gets to displaying actual Scan.
  
  ## Expected Behavior
  
  Scan should be displayed properly, no matter how many Slices it has.
  
  ## Steps to Reproduce the Problem
  
    1. Upload less than 10 Slices.
    2. Go to Labelling page.
    3. Voi'la, Scan is not displayed, instead you're presented with spinner indicator that doesn't dissapear.
  
  ## Additional comment (optional)
  
  Reason for that happening is that `SLICE_BATCH_SIZE` (`validation-page.component.ts`, Line 23) is fixed to 10. When we upload Scan that has less than `SLICE_BATCH_SIZE` slices, method `slice.isLastInBatch()` (`marker-page.component.ts`, Line 101) will always return `false`, because it will never hit slice with id = 9 (because there isn't one...). Therefore, Slice download will never be marked as completed.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `backend/medtagger/api/scans/service_web_socket.py`
  Content:
  ```
  1 """Module responsible for definition of Scans service available via WebSockets."""
  2 from typing import Dict
  3 
  4 from flask_socketio import Namespace, emit
  5 
  6 from medtagger.api import web_socket
  7 from medtagger.database.models import SliceOrientation
  8 from medtagger.types import ScanID
  9 from medtagger.api.exceptions import InvalidArgumentsException
  10 from medtagger.api.scans import business
  11 
  12 
  13 class Slices(Namespace):
  14     """WebSocket handler for /slices namespace."""
  15 
  16     MAX_NUMBER_OF_SLICES_PER_REQUEST = 25
  17 
  18     def on_request_slices(self, request: Dict) -> None:
  19         """Handle slices request triggered  by `request_slices` event."""
  20         assert request.get('scan_id'), 'ScanID is required!'
  21         scan_id = ScanID(str(request['scan_id']))
  22         begin = max(0, request.get('begin', 0))
  23         count = request.get('count', 1)
  24         reversed_order = request.get('reversed', False)
  25         orientation = request.get('orientation', SliceOrientation.Z.value)
  26         self._raise_on_invalid_request_slices(count, orientation)
  27 
  28         orientation = SliceOrientation[orientation]
  29         slices = business.get_slices_for_scan(scan_id, begin, count, orientation=orientation)
  30         slices_to_send = reversed(list(enumerate(slices))) if reversed_order else enumerate(slices)
  31         last_in_batch = begin if reversed_order else begin + count - 1
  32         for index, (_slice, image) in slices_to_send:
  33             emit('slice', {
  34                 'scan_id': scan_id,
  35                 'index': begin + index,
  36                 'last_in_batch': last_in_batch,
  37                 'image': image,
  38             })
  39 
  40     def _raise_on_invalid_request_slices(self, count: int, orientation: str) -> None:
  41         """Validate incoming request and raise an exception if there are issues with given arguments.
  42 
  43         :param count: number of slices that should be returned
  44         :param orientation: Slice's orientation as a string
  45         """
  46         # Make sure that passed orientation is proper one
  47         if orientation not in SliceOrientation.__members__:
  48             raise InvalidArgumentsException('Invalid Slice orientation.')
  49 
  50         # Make sure that nobody will fetch whole scan at once. It could freeze our backend application.
  51         if count > self.MAX_NUMBER_OF_SLICES_PER_REQUEST:
  52             message = 'Cannot return more than {} slices per request.'.format(self.MAX_NUMBER_OF_SLICES_PER_REQUEST)
  53             raise InvalidArgumentsException(message)
  54 
  55 
  56 # Register above namespace
  57 web_socket.on_namespace(Slices('/slices'))
  58
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/backend/medtagger/api/scans/service_web_socket.py b/backend/medtagger/api/scans/service_web_socket.py
  --- a/backend/medtagger/api/scans/service_web_socket.py
  +++ b/backend/medtagger/api/scans/service_web_socket.py
  @@ -26,10 +26,10 @@
           self._raise_on_invalid_request_slices(count, orientation)
   
           orientation = SliceOrientation[orientation]
  -        slices = business.get_slices_for_scan(scan_id, begin, count, orientation=orientation)
  -        slices_to_send = reversed(list(enumerate(slices))) if reversed_order else enumerate(slices)
  -        last_in_batch = begin if reversed_order else begin + count - 1
  -        for index, (_slice, image) in slices_to_send:
  +        slices = list(business.get_slices_for_scan(scan_id, begin, count, orientation=orientation))
  +        slices_to_send = list(reversed(slices)) if reversed_order else slices
  +        last_in_batch = begin if reversed_order else begin + len(slices_to_send) - 1
  +        for index, (_slice, image) in enumerate(slices_to_send):
               emit('slice', {
                   'scan_id': scan_id,
                   'index': begin + index,
  
verification_info: {"golden_diff": "diff --git a/backend/medtagger/api/scans/service_web_socket.py b/backend/medtagger/api/scans/service_web_socket.py\n--- a/backend/medtagger/api/scans/service_web_socket.py\n+++ b/backend/medtagger/api/scans/service_web_socket.py\n@@ -26,10 +26,10 @@\n         self._raise_on_invalid_request_slices(count, orientation)\n \n         orientation = SliceOrientation[orientation]\n-        slices = business.get_slices_for_scan(scan_id, begin, count, orientation=orientation)\n-        slices_to_send = reversed(list(enumerate(slices))) if reversed_order else enumerate(slices)\n-        last_in_batch = begin if reversed_order else begin + count - 1\n-        for index, (_slice, image) in slices_to_send:\n+        slices = list(business.get_slices_for_scan(scan_id, begin, count, orientation=orientation))\n+        slices_to_send = list(reversed(slices)) if reversed_order else slices\n+        last_in_batch = begin if reversed_order else begin + len(slices_to_send) - 1\n+        for index, (_slice, image) in enumerate(slices_to_send):\n             emit('slice', {\n                 'scan_id': scan_id,\n                 'index': begin + index,\n", "issue": "Scans with low number of Slices are not properly loaded on Labeling page\n## Current Behavior\r\n\r\nWhen Scan has less than 10 Slices, Scan Viewer keeps displaying spinner indicator and never gets to displaying actual Scan.\r\n\r\n## Expected Behavior\r\n\r\nScan should be displayed properly, no matter how many Slices it has.\r\n\r\n## Steps to Reproduce the Problem\r\n\r\n  1. Upload less than 10 Slices.\r\n  2. Go to Labelling page.\r\n  3. Voi'la, Scan is not displayed, instead you're presented with spinner indicator that doesn't dissapear.\r\n\r\n## Additional comment (optional)\r\n\r\nReason for that happening is that `SLICE_BATCH_SIZE` (`validation-page.component.ts`, Line 23) is fixed to 10. When we upload Scan that has less than `SLICE_BATCH_SIZE` slices, method `slice.isLastInBatch()` (`marker-page.component.ts`, Line 101) will always return `false`, because it will never hit slice with id = 9 (because there isn't one...). Therefore, Slice download will never be marked as completed.\r\n\n", "before_files": [{"content": "\"\"\"Module responsible for definition of Scans service available via WebSockets.\"\"\"\nfrom typing import Dict\n\nfrom flask_socketio import Namespace, emit\n\nfrom medtagger.api import web_socket\nfrom medtagger.database.models import SliceOrientation\nfrom medtagger.types import ScanID\nfrom medtagger.api.exceptions import InvalidArgumentsException\nfrom medtagger.api.scans import business\n\n\nclass Slices(Namespace):\n    \"\"\"WebSocket handler for /slices namespace.\"\"\"\n\n    MAX_NUMBER_OF_SLICES_PER_REQUEST = 25\n\n    def on_request_slices(self, request: Dict) -> None:\n        \"\"\"Handle slices request triggered  by `request_slices` event.\"\"\"\n        assert request.get('scan_id'), 'ScanID is required!'\n        scan_id = ScanID(str(request['scan_id']))\n        begin = max(0, request.get('begin', 0))\n        count = request.get('count', 1)\n        reversed_order = request.get('reversed', False)\n        orientation = request.get('orientation', SliceOrientation.Z.value)\n        self._raise_on_invalid_request_slices(count, orientation)\n\n        orientation = SliceOrientation[orientation]\n        slices = business.get_slices_for_scan(scan_id, begin, count, orientation=orientation)\n        slices_to_send = reversed(list(enumerate(slices))) if reversed_order else enumerate(slices)\n        last_in_batch = begin if reversed_order else begin + count - 1\n        for index, (_slice, image) in slices_to_send:\n            emit('slice', {\n                'scan_id': scan_id,\n                'index': begin + index,\n                'last_in_batch': last_in_batch,\n                'image': image,\n            })\n\n    def _raise_on_invalid_request_slices(self, count: int, orientation: str) -> None:\n        \"\"\"Validate incoming request and raise an exception if there are issues with given arguments.\n\n        :param count: number of slices that should be returned\n        :param orientation: Slice's orientation as a string\n        \"\"\"\n        # Make sure that passed orientation is proper one\n        if orientation not in SliceOrientation.__members__:\n            raise InvalidArgumentsException('Invalid Slice orientation.')\n\n        # Make sure that nobody will fetch whole scan at once. It could freeze our backend application.\n        if count > self.MAX_NUMBER_OF_SLICES_PER_REQUEST:\n            message = 'Cannot return more than {} slices per request.'.format(self.MAX_NUMBER_OF_SLICES_PER_REQUEST)\n            raise InvalidArgumentsException(message)\n\n\n# Register above namespace\nweb_socket.on_namespace(Slices('/slices'))\n", "path": "backend/medtagger/api/scans/service_web_socket.py"}], "after_files": [{"content": "\"\"\"Module responsible for definition of Scans service available via WebSockets.\"\"\"\nfrom typing import Dict\n\nfrom flask_socketio import Namespace, emit\n\nfrom medtagger.api import web_socket\nfrom medtagger.database.models import SliceOrientation\nfrom medtagger.types import ScanID\nfrom medtagger.api.exceptions import InvalidArgumentsException\nfrom medtagger.api.scans import business\n\n\nclass Slices(Namespace):\n    \"\"\"WebSocket handler for /slices namespace.\"\"\"\n\n    MAX_NUMBER_OF_SLICES_PER_REQUEST = 25\n\n    def on_request_slices(self, request: Dict) -> None:\n        \"\"\"Handle slices request triggered  by `request_slices` event.\"\"\"\n        assert request.get('scan_id'), 'ScanID is required!'\n        scan_id = ScanID(str(request['scan_id']))\n        begin = max(0, request.get('begin', 0))\n        count = request.get('count', 1)\n        reversed_order = request.get('reversed', False)\n        orientation = request.get('orientation', SliceOrientation.Z.value)\n        self._raise_on_invalid_request_slices(count, orientation)\n\n        orientation = SliceOrientation[orientation]\n        slices = list(business.get_slices_for_scan(scan_id, begin, count, orientation=orientation))\n        slices_to_send = list(reversed(slices)) if reversed_order else slices\n        last_in_batch = begin if reversed_order else begin + len(slices_to_send) - 1\n        for index, (_slice, image) in enumerate(slices_to_send):\n            emit('slice', {\n                'scan_id': scan_id,\n                'index': begin + index,\n                'last_in_batch': last_in_batch,\n                'image': image,\n            })\n\n    def _raise_on_invalid_request_slices(self, count: int, orientation: str) -> None:\n        \"\"\"Validate incoming request and raise an exception if there are issues with given arguments.\n\n        :param count: number of slices that should be returned\n        :param orientation: Slice's orientation as a string\n        \"\"\"\n        # Make sure that passed orientation is proper one\n        if orientation not in SliceOrientation.__members__:\n            raise InvalidArgumentsException('Invalid Slice orientation.')\n\n        # Make sure that nobody will fetch whole scan at once. It could freeze our backend application.\n        if count > self.MAX_NUMBER_OF_SLICES_PER_REQUEST:\n            message = 'Cannot return more than {} slices per request.'.format(self.MAX_NUMBER_OF_SLICES_PER_REQUEST)\n            raise InvalidArgumentsException(message)\n\n\n# Register above namespace\nweb_socket.on_namespace(Slices('/slices'))\n", "path": "backend/medtagger/api/scans/service_web_socket.py"}]}