diff --git a/designcter/_utils.py b/designcter/_utils.py index 1a4116d..5999145 100644 --- a/designcter/_utils.py +++ b/designcter/_utils.py @@ -1,5 +1,23 @@ +import os + def bool_yesno(x: bool) -> str: return "Yes" if x else "No" def dash_if_blank(x: str) -> str: - return "-" if x == "" else x \ No newline at end of file + return "-" if x == "" else x + + +def newlineFormatOS(text): + """ + Adjusts the newline characters in the given text to match the operating system's format. + + Parameters: + text (str): The input text with newlines. + + Returns: + str: The text with adjusted newline characters. + """ + if os.name == 'nt': # Windows + return text.replace('\n', '\r\n') + else: # macOS and other Unix-based systems + return text.replace('\r\n', '\n') diff --git a/designcter/design.py b/designcter/design.py index 90ddd35..28ee60c 100644 --- a/designcter/design.py +++ b/designcter/design.py @@ -1,7 +1,7 @@ import datetime from ._designTemp import design_template from .proto import protocols -from ._utils import bool_yesno +from ._utils import bool_yesno, newlineFormatOS @@ -46,5 +46,7 @@ def design_ct(protocol_id: str, ref_phy_name_text = ref_phy_name, ref_phy_tel_text = ref_phy_tel ) + # Format newline for macOS or Windows + str_design_fmt = newlineFormatOS(str_design) - return str_design \ No newline at end of file + return str_design_fmt \ No newline at end of file diff --git a/dev/testing.ipynb b/dev/testing.ipynb index 8de2165..0ccf5aa 100644 --- a/dev/testing.ipynb +++ b/dev/testing.ipynb @@ -31,6 +31,81 @@ "## Main Test" ] }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Exam: CTWA\\nProtocol name: Routine WA\\n- Venous (whole)\\n- Delay (liver)\\nContrast route: Oral (limited water), Rectal (water)\\nNPO time: -\\neGFR (03/06/2024): -\\nRenal premed: -\\nAllergy premed: -\\nPregnancy: Yes\\nET tube: No\\nC1: No\\nPrecaution: -\\nSpecial instructions: -\\nRef physician name: -\\nRef physician tel: -\\n'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "e1 = designcter.design_ct(\"ct_wa_routine\", pregnancy=True)\n", + "e1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Newline Problem Fix" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "def newlineFormatOS(text):\n", + " \"\"\"\n", + " Adjusts the newline characters in the given text to match the operating system's format.\n", + " \n", + " Parameters:\n", + " text (str): The input text with newlines.\n", + "\n", + " Returns:\n", + " str: The text with adjusted newline characters.\n", + " \"\"\"\n", + " if os.name == 'nt': # Windows\n", + " return text.replace('\\n', '\\r\\n')\n", + " else: # macOS and other Unix-based systems\n", + " return text.replace('\\r\\n', '\\n')\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello \\r\\n world'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "newlineFormatOS(\"Hello \\n world\")\n", + "newlineFormatOS(\"Hello \\r\\n world\")\n", + "\n", + "\"Hello \\n world\".replace('\\n', '\\r\\n')\n" + ] + }, { "cell_type": "code", "execution_count": 2, @@ -46,11 +121,12 @@ "- Delay (liver)\n", "Contrast route: Oral (limited water), Rectal (water)\n", "NPO time: -\n", - "eGFR (23/05/2024): -\n", + "eGFR (03/06/2024): -\n", "Renal premed: -\n", "Allergy premed: -\n", "Pregnancy: Yes\n", "ET tube: No\n", + "C1: No\n", "Precaution: -\n", "Special instructions: -\n", "Ref physician name: -\n", diff --git a/main.py b/main.py index 2a7fdf6..bdf58b2 100644 --- a/main.py +++ b/main.py @@ -191,8 +191,8 @@ def theme_changed(e): # Page Size page.window_min_width = 780 page.window_width = 780 - page.window_min_height = 790 - page.window_height = 790 + page.window_min_height = 800 + page.window_height = 800 # App Bar page.appbar = ft.CupertinoAppBar( leading=ft.Icon(ft.icons.PALETTE),