如何将结构化的 LaTeX 文件转换为 CSV 数据

如何将结构化的 LaTeX 文件转换为 CSV 数据

我正在使用结构化格式通过 LaTeX 打印患者的文档。结构如下:

人口统计 名字 姓氏
年龄/性别
地址

临床详情 历史、既往史、个人史、家族史及其他(作为小节)er:

考试

诊断 临时决赛

调查 可用和建议

治疗

我使用了 koma article class ( scrartcl) 和section, subsection, enumerate。我知道datatool我可以使用哪个包来完成这些事情,同时我会将访问记录到 csv/excel/calc 中。我无法弄清楚如何过滤 csv 条目,以便我可以打印单个患者记录。我的问题是,如果我遵循上面提到的简单结构,是否有任何方法可以将所有患者的数据导出到 csv 文件/excel/calc 进行分析?

我正在输入文件的结构tex

\documentclass[12pts]{scrartcl}
\usepackage{fontspec}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=1cm,rmargin=1cm}
\usepackage{array}
\usepackage{fixltx2e}
\setmainfont[Script=Devanagari]{Sanskrit 2003}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\usepackage{enumitem}       % customizable list environments
\newlength{\lyxlabelwidth}      % auxiliary length 
\@ifundefined{lettrine}{\usepackage{lettrine}}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.

\usepackage[us,24hr]{datetime}

\makeatother

\usepackage{xunicode}
\usepackage{polyglossia}
\title{Consultation Report}
\begin{document}
\maketitle

\section*{Clinical details}

\subsection*{Present history}

\subsection*{Past History}

\subsection*{Personal history}

\subsection*{Family history }

\subsection*{Examination}
examination finding 
\section*{Diagnosis}
\begin{enumerate}
\item  Disease
\end{enumerate}

\section*{Rx}
\begin{enumerate}
\item here goes teatment
\item tab abc दिवसातून दोनदा 
\end{enumerate}
\begin{flushright}
My Name \\
{\footnotesize Qualification
}\\
{\footnotesize designation}\\
{\footnotesize Ph: }
\par\end{flushright}{\footnotesize \par}

\end{document}

我想我需要详细说明一下。到目前为止,我一直在使用提供的模板来创建定期咨询。接待员过去常常创建一个以患者命名的文件夹,并插入一个demography.tex包含

Name surname \\\ dob\\\address\\\Phone.

我曾经创建名为的小型 tex 文件,用于yymmdd.tex输入临床数据。临床数据包括病史、检查和诊断。我们曾经创建第三个小文件,Rx.tex用于存放逐项治疗。这三个文件过去是通过\input在提供的模板中放置命令来编译的。拥有三个小文件的好处是我可以在后续访问中使用人口统计学。治疗大多需要稍作修改。临床数据过去经常变化,所以我每次都必须在模板中更改输入文件。总的来说,生成的文本具有一致的模式。我可以在内部网上共享文件夹。但可能有更好的方法使用数据工具来做到这一点。我在使用数据工具时遇到了两个问题。

  1. 虽然我理解如何使用数据工具创建表格,但我不明白如何使用单个条目。例如,在已提供的模板中显示历史记录,在过去的历史模板中显示过去的历史。

  2. 如果我对每位患者和每次就诊都使用唯一的识别号,那么我怎样才能仅将就诊当天的数据导出到乳胶模板中。

如果我能搞清楚,那么我的所有患者数据都可以输入到 excel 中并导出到 latex 模板以创建所需的文档。问题是,为什么不使用类似 MySQL 的数据库?学习新工具似乎超出了我的能力和可用时间,尽管它可能值得。我绝不会创建 emr。那太过分了。如果您能帮助我将 cvs 转换为我提供的 LaTeX 模板,我将不胜感激。出于技术原因,我希望|是分隔符而不是逗号。

答案1

我同意这些评论,您需要一种脚本语言来从现有文档中提取信息,但是一旦您将信息存储在数据库中,您就可以使用 datatool 包为特定患者生成报告。对于您想要保存的信息类型,我不建议使用 csv,因为我发现编辑起来很棘手(但这取决于您使用什么来编辑它)。以下是它在 csv 格式中的样子(使用 | 作为分隔符,正如您所要求的那样):

Patient Number|Name|Surname|DoB|Sex|Address|Phone|History|Past History|Personal History|Family History|Examination|Diagnosis|Treatment
0001|Joe|Bloggs|1974-12-06|Male|"1 The Street, The Town"|0123456|Joe's patient history here|Joe's past history here|Joe's personal history|Joe's family history|Joe's examination|\begin{enumerate}\item Joe's diagnosis\end{enumerate}|\begin{enumerate}\item Joe's treatment\end{enumerate}
0002|Jane|Doe|1970-05-18|Female|"2 The Street, The Town"|0123457|Mary's patient history here|Mary's past history here|Mary's personal history|Mary's family history|Mary's examination|\begin{enumerate}\item Mary's diagnosis\end{enumerate}|\begin{enumerate}\item Mary's treatment\end{enumerate}
0003|John|Smith|1969-01-20|Male|"3 The Street, The Town"|01234568|John's patient history here|John's past history here|John's personal history|John's family history|John's examination|\begin{enumerate}\item John's diagnosis\end{enumerate}|\begin{enumerate}\item John's treatment\end{enumerate}

或者,可以使用 datatool 格式将相同的信息存储在 .tex 文件中:

\DTLnewdb{patients}
% Patient Joe Bloggs (patient number 0001)
\DTLnewrow*{patients}
\DTLnewdbentry*{patients}{Patient Number}{0001}
\DTLnewdbentry*{patients}{Name}{Joe}
\DTLnewdbentry*{patients}{Surname}{Bloggs}
\DTLnewdbentry*{patients}{DoB}{1974-12-06}
\DTLnewdbentry*{patients}{Sex}{Male}
\DTLnewdbentry*{patients}{Address}{1 The Street, The Town}
\DTLnewdbentry*{patients}{Phone}{0123456}
\DTLnewdbentry*{patients}{History}{Joe's patient history here}
\DTLnewdbentry*{patients}{Past History}{Joe's past history here}
\DTLnewdbentry*{patients}{Personal History}{Joe's personal history}
\DTLnewdbentry*{patients}{Family History}{Joe's family history}
\DTLnewdbentry*{patients}{Examination}{Joe's examination}
\DTLnewdbentry*{patients}{Diagnosis}
{%
  \begin{enumerate}
    \item Joe's diagnosis
  \end{enumerate}
}
\DTLnewdbentry*{patients}{Treatment}
{%
  \begin{enumerate}
    \item Joe's treatment
  \end{enumerate}
}
% Patient Jane Doe (patient number 0002)
\DTLnewrow*{patients}
\DTLnewdbentry*{patients}{Patient Number}{0002}
\DTLnewdbentry*{patients}{Name}{Jane}
\DTLnewdbentry*{patients}{Surname}{Doe}
\DTLnewdbentry*{patients}{DoB}{1970-05-18}
\DTLnewdbentry*{patients}{Sex}{Female}
\DTLnewdbentry*{patients}{Address}{2 The Street, The Town}
\DTLnewdbentry*{patients}{Phone}{0123457}
\DTLnewdbentry*{patients}{History}{Mary's patient history here}
\DTLnewdbentry*{patients}{Past History}{Mary's past history here}
\DTLnewdbentry*{patients}{Personal History}{Mary's personal history}
\DTLnewdbentry*{patients}{Family History}{Mary's family history}
\DTLnewdbentry*{patients}{Examination}{Mary's examination}
\DTLnewdbentry*{patients}{Diagnosis}
{%
  \begin{enumerate}
    \item Mary's diagnosis
  \end{enumerate}
}
\DTLnewdbentry*{patients}{Treatment}
{%
  \begin{enumerate}
    \item Mary's treatment
  \end{enumerate}
}
% Patient John Smith (patient number 0003)
\DTLnewrow*{patients}
\DTLnewdbentry*{patients}{Patient Number}{0003}
\DTLnewdbentry*{patients}{Name}{John}
\DTLnewdbentry*{patients}{Surname}{Smith}
\DTLnewdbentry*{patients}{DoB}{1969-01-20}
\DTLnewdbentry*{patients}{Sex}{Male}
\DTLnewdbentry*{patients}{Address}{3 The Street, The Town}
\DTLnewdbentry*{patients}{Phone}{0123458}
\DTLnewdbentry*{patients}{History}{John's patient history here}
\DTLnewdbentry*{patients}{Past History}{John's past history here}
\DTLnewdbentry*{patients}{Personal History}{John's personal history}
\DTLnewdbentry*{patients}{Family History}{John's family history}
\DTLnewdbentry*{patients}{Examination}{John's examination}
\DTLnewdbentry*{patients}{Diagnosis}
{%
  \begin{enumerate}
    \item John's diagnosis
  \end{enumerate}
}
\DTLnewdbentry*{patients}{Treatment}
{%
  \begin{enumerate}
    \item John's treatment
  \end{enumerate}
}

您可以像这样访问特定患者:

\documentclass{scrartcl}

\usepackage{datatool}

% load from csv file:
%\DTLsetseparator{|}
%\DTLloaddb{patients}{patients.csv}
% or load from .tex file:
\input{patients}

\title{Consultation Report}
\author{}

\newcommand*{\getdetails}[1]{%
  \dtlgetentryfromcurrentrow{\patientdetails}{\dtlcolumnindex{patients}{#1}}%
  \patientdetails
}

\begin{document}
\maketitle

% fetch patient's details (patient number 0002)
\dtlgetrowforvalue{patients}{\dtlcolumnindex{patients}{Patient Number}}{0002}%

\begin{tabular}{ll}
Name: & \getdetails{Name} \getdetails{Surname}\\
DoB: & \getdetails{DoB}\\
Sex: & \getdetails{Sex}\\
Address: & \getdetails{Address}\\
Phone: & \getdetails{Phone}
\end{tabular}

\section*{Clinical details}

\subsection*{Present history}

\getdetails{History}

\subsection*{Past History}

\getdetails{Past History}

\subsection*{Personal history}

\getdetails{Personal History}

\subsection*{Family history }

\getdetails{Family History}

\subsection*{Examination}

\getdetails{Examination}

\section*{Diagnosis}

\getdetails{Diagnosis}

\section*{Rx}

\getdetails{Treatment}

\begin{flushright}
My Name \\
{\footnotesize Qualification
}\\
{\footnotesize designation}\\
{\footnotesize Ph: }
\par\end{flushright}{\footnotesize \par}

\end{document}

相关内容