> For the complete documentation index, see [llms.txt](https://docs.docbits.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docbits.com/chinese/guan-li-yu-she-zhi/settings/global-settings/document-types/script/creating-and-editing-scripts.md).

# 创建和编辑脚本

{% embed url="<https://youtu.be/n8NpWWIjmlA>" %}
DocBits 文档脚本说明：自动化文档工作流中的自定义逻辑
{% endembed %}

## 按照以下详细说明在 DocBits 中创建新脚本：

**选择脚本语言：**

首先，选择要使用的脚本语言。DocBits 通常支持 Python、JavaScript 或 SQL 等常用脚本语言。语言的选择取决于项目需求和您自身的熟练程度。

**打开脚本开发环境：**

登录 DocBits 并导航到脚本开发环境。该环境位于管理区域。

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-4bf2e32d01f1a0d4021dd4a163a4c8d0473e0ea2%2Fscript_development_environment_overview.png?alt=media" alt="脚本开发环境概览"><figcaption></figcaption></figure>

**创建新脚本：**

点击“+ New”按钮，打开新的脚本编辑器。

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-b02b44e3ea22759f763fa0670fcce2941b5246d1%2Fcreate_new_script_button.png?alt=media" alt="创建新脚本按钮"><figcaption></figcaption></figure>

**编写代码：**

使用编辑器编写脚本代码。请从所选脚本语言的基本语法开始。

例如，如果使用 Python，脚本可能如下所示：

## 1. Python 脚本示例

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-f3b8ffa378e65fdc2b8a4d26c2b7ded307eb19a5%2Fpython_script_example_1.png?alt=media" alt="Python 脚本示例 1"><figcaption></figcaption></figure>

## 清理患者姓名的函数

def clean\_patient\_name(name): cleaned\_name = name.strip().title() # 删除空格并应用首字母大写

return cleaned\_name

## 主程序

if **name** == "**main**": patient\_name = " john doe " cleaned\_name = clean\_patient\_name(patient\_name) print("清理后的患者姓名：", cleaned\_name)

## 2. 脚本示例

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-744db55a77a66739528ed4fac0a5993d87f771f5%2Fpython_script_example_2.png?alt=media" alt="Python 脚本示例 2"><figcaption></figcaption></figure>

**测试脚本：**

检查代码是否存在错误，并在测试环境中进行测试。确保脚本能产生预期结果并正常运行。

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-84f0046df7240734feda5575f87fe900c396b1fe%2Fscript_testing_interface.png?alt=media" alt="脚本测试界面"><figcaption></figcaption></figure>

**保存脚本：**

在 DocBits 中保存脚本，并为其指定一个能描述脚本用途的名称。

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-6a1bab892686474afbfa238aa7948d1e90a06ee2%2Fsave_script_button.png?alt=media" alt="保存脚本按钮" width="84"><figcaption></figcaption></figure>

**将脚本映射到文档类型：**

重要的一步是将脚本映射到相应的文档类型。这决定了脚本何时以及如何应用。通常可以通过 DocBits 中的配置界面完成此操作：将脚本分配给特定文档类型，并指定应用脚本的条件。

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-7c95c820ac2cfc0bcb35579df73719af849f5aef%2Fscript_document_type_mapping.png?alt=media" alt="脚本与文档类型的映射"><figcaption></figcaption></figure>

**审核并发布：**

创建、测试并映射脚本后，再次检查是否存在错误或不一致之处。如果一切正常，就可以将脚本发布到 DocBits 生产环境。

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-3d4215556aad2dd08644bbcdfd493a556988b3d6%2Fscript_review_and_publish.png?alt=media" alt="审核并发布脚本"><figcaption></figcaption></figure>

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-b4661f27a254c2a31fb7d015be26fc4365ce8240%2Fscript_publish_confirmation.png?alt=media" alt="脚本发布确认"><figcaption></figcaption></figure>

按照这些步骤，您可以在 DocBits 中成功创建、测试并实施新脚本，从而实现流程自动化并提高医疗文档处理的效率。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.docbits.com/chinese/guan-li-yu-she-zhi/settings/global-settings/document-types/script/creating-and-editing-scripts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
