数据¶
数据值¶
本节关于发送和读取数据值。
List organisation units with id and name and total count:
发送数据值¶
List users with id and username:
/api/users/gist?fields=id,userCredentials.username
A common use-case for system integration is the need to send a set of data values from a third-party system into DHIS. In this example, we will use the DHIS2 demo on http://play.dhis2.org/demo as basis. We assume that we have collected case-based data using a simple software client running on mobile phones for the Mortality <5 years data set in the community of Ngelehun CHC (in Badjia chiefdom, Bo district) for the month of January 2014. We have now aggregated our data into a statistical report and want to send that data to the DHIS2 instance. The base URL to the demo API is http://play.dhis2.org/demo/api. The following links are relative to the base URL.
最适合我们发送数据的资源 values 是 /api/dataValueSets 资源。一个数据值集代表一个 一组具有关系的数据值,通常来自 从相同的数据输入表单中捕获。格式看起来像 这:
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="dataSetID"
completeDate="date" period="period" orgUnit="orgUnitID" attributeOptionCombo="aocID">
<dataValue dataElement="dataElementID"
categoryOptionCombo="cocID" value="1" comment="comment1"/>
<dataValue dataElement="dataElementID"
categoryOptionCombo="cocID" value="2" comment="comment2"/>
<dataValue dataElement="dataElementID"
categoryOptionCombo="cocID" value="3" comment="comment3"/>
</dataValueSet>
JSON支持以下格式:
{
"dataSet": "dataSetID",
"completeDate": "date",
"period": "period",
"orgUnit": "orgUnitID",
"attributeOptionCombo": "aocID",
"dataValues": [
{
"dataElement": "dataElementID",
"categoryOptionCombo": "cocID",
"value": "1",
"comment": "comment1"
},
{
"dataElement": "dataElementID",
"categoryOptionCombo": "cocID",
"value": "2",
"comment": "comment2"
},
{
"dataElement": "dataElementID",
"categoryOptionCombo": "cocID",
"value": "3",
"comment": "comment3"
}
]
}
CSV支持以下格式:
“ dataelement”,“ period”,“ orgunit”,“ catoptcombo”,“ attroptcombo”,“ value”,“ strby”,“ lstupd”,“ cmt”
“ dataElementID”,“ period”,“ orgUnitID”,“ cocID”,“ aocID”,“ 1”,“用户名”,“ 2015-04-01”,“ comment1”
“ dataElementID”,“ period”,“ orgUnitID”,“ cocID”,“ aocID”,“ 2”,“用户名”,“ 2015-04-01”,“ comment2”
“ dataElementID”,“ period”,“ orgUnitID”,“ cocID”,“ aocID”,“ 3”,“用户名”,“ 2015-04-01”,“ comment3”
/api/organisationUnits/zFDYIgyGmXG/children/gist?fields=id,name&inverse=true
从这个例子中,我们可以看出我们需要识别周期, 数据集、组织单位(设施)和数据元素 报告。
To obtain the identifier for the data set we make a request to the /api/dataSets resource. From there we find and follow the link to the Mortality < 5 years data set which leads us to /api/dataSets/pBOMPrpg1QX. The resource representation for the Mortality < 5 years data set conveniently advertises links to the data elements which are members of it. From here we can follow these links and obtain the identifiers of the data elements. For brevity we will only report on three data elements: Measles with id f7n9E0hX8qk, Dysentery with id Ix2HsbDMLea and Cholera with id eY5ehpbEsB7.
剩下的就是掌握组织的标识符 单元。 dataSet 表示方便地提供了到组织的链接 报告它的单位,所以我们搜索 Ngelehun CHC 并按照 链接到 /api/organisationUnits/DiszpKrYNg8 中的 HTML 表示,其中 告诉我们这个组织单位的标识符是DiszpKrYNg8。
根据我们基于病例的数据,我们假设我们有 12 例麻疹病例,14 痢疾16例,霍乱16例。我们现在已经聚集了足够的 能够将 XML 数据值集放在一起的信息 信息:
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="pBOMPrpg1QX"
completeDate="2014-02-03" period="201401" orgUnit="DiszpKrYNg8">
<dataValue dataElement="f7n9E0hX8qk" value="12"/>
<dataValue dataElement="Ix2HsbDMLea" value="14"/>
<dataValue dataElement="eY5ehpbEsB7" value="16"/>
</dataValueSet>
JSON格式:
{
"dataSet": "pBOMPrpg1QX",
"completeDate": "2014-02-03",
"period": "201401",
"orgUnit": "DiszpKrYNg8",
"dataValues": [
{
"dataElement": "f7n9E0hX8qk",
"value": "1"
},
{
"dataElement": "Ix2HsbDMLea",
"value": "2"
},
{
"dataElement": "eY5ehpbEsB7",
"value": "3"
}
]
}
To perform functional testing we will use the curl tool which provides an easy way of transferring data using HTTP. First, we save the data value set XML content in a file called datavalueset.xml. From the directory where this file resides we invoke the following from the command line:
发送数据值 { #webapi_sending_data_values }
要发送 JSON 内容,您必须设置 content-type 标头 因此:
POST /api/dataValueSets
该命令将向演示 Web API 发送请求,设置 application/xml 作为内容类型并使用 admin/district 作为用户名/密码。如果一切顺利,这将返回一个 200 OK HTTP 状态代码。您可以验证数据是否已 通过在 DHIS2 中打开数据输入模块并选择组织来接收 本例中使用的单位、数据集和期间。
The API follows normal semantics for error handling and HTTP status codes. If you supply an invalid username or password, 401 Unauthorized is returned. If you supply a content-type other than application/xml, 415 Unsupported Media Type is returned. If the XML content is invalid according to the DXF namespace, 400 Bad Request is returned. If you provide an invalid identifier in the XML content, 409 Conflict is returned together with a descriptive message.
发送大量数据值¶
前面的例子向我们展示了如何发送一组相关的数据值 共享同一时期和组织单位。这个例子将向我们展示 如何发送大量不一定是的数据值 逻辑相关。
我们将再次与/api/dataValueSets 资源交互。这次我们 不会指定 dataSet 和 completeDate 属性。此外,我们将 在单个数据值上指定 period 和 orgUnit 属性 元素而不是外部数据值集元素。这会 使我们能够发送不同时期和组织单位的数据值:
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0">
<dataValue dataElement="f7n9E0hX8qk"
period="201401" orgUnit="DiszpKrYNg8" value="12"/>
<dataValue dataElement="f7n9E0hX8qk"
period="201401" orgUnit="FNnj3jKGS7i" value="14"/>
<dataValue dataElement="f7n9E0hX8qk"
period="201402" orgUnit="DiszpKrYNg8" value="16"/>
<dataValue dataElement="f7n9E0hX8qk"
period="201402" orgUnit="Jkhdsf8sdf4" value="18"/>
</dataValueSet>
JSON格式:
{
"dataValues": [
{
"dataElement": "f7n9E0hX8qk",
"period": "201401",
"orgUnit": "DiszpKrYNg8",
"value": "12"
},
{
"dataElement": "f7n9E0hX8qk",
"period": "201401",
"orgUnit": "FNnj3jKGS7i",
"value": "14"
},
{
"dataElement": "f7n9E0hX8qk",
"period": "201402",
"orgUnit": "DiszpKrYNg8",
"value": "16"
},
{
"dataElement": "f7n9E0hX8qk",
"period": "201402",
"orgUnit": "Jkhdsf8sdf4",
"value": "18"
}
]
}
CSV格式:
“ dataelement”,“ period”,“ orgunit”,“ categoryoptioncombo”,“ attributeoptioncombo”,“ value”
“ f7n9E0hX8qk”,“ 201401”,“ DiszpKrYNg8”,“ bRowv6yZOF2”,“ bRowv6yZOF2”,“ 1”
“ Ix2HsbDMLea”,“ 201401”,“ DiszpKrYNg8”,“ bRowv6yZOF2”,“ bRowv6yZOF2”,“ 2”
“ eY5ehpbEsB7”,“ 201401”,“ DiszpKrYNg8”,“ bRowv6yZOF2”,“ bRowv6yZOF2”,“ 3”
我们通过使用curl以XML格式发送数据值进行测试:
发送数据值 { #webapi_sending_data_values }
请注意,使用 CSV 格式时,您必须使用二进制数据选项 保留 CSV 文件中的换行符:
curl --data-binary @datavalueset.csv "https://play.dhis2.org/demo/24/api/dataValueSets"
-H "Content-Type:application/csv" -u admin:district
数据值集资源提供有用的 XML 响应 当您想验证您的请求所产生的影响时。我们第一次 发送上面的数据值设置请求,服务器将响应 以下导入摘要:
<importSummary>
<dataValueCount imported="2" updated="1" ignored="1"/>
<dataSetComplete>false</dataSetComplete>
</importSummary>
此消息告诉我们导入了 3 个数据值,1 个数据值是 在忽略零数据值时更新。单一更新来自 我们在上一个示例中发送该数据值的结果。一个数据 如果引用不存在的数据元素,值将被忽略, 期间、组织单位或数据集。在我们的例子中,这个被忽略的值是 由对组织单位的无效引用的最后一个数据值引起。 数据集完整元素将显示数据的日期 值集已完成,如果没有数据元素属性,则为 false 提供。
导入参数¶
curl -d @datavalueset.json "https://play.dhis2.org/demo/api/dataValueSets"
-H "Content-Type:application/json" -u admin:district
选项(第一项为默认值)
| 默认值 | 发送大量数据值 { #webapi_sending_bulks_data_values } | 描述 |
|---|---|---|
| 数据元素标识方案 | CSV格式: | JSON格式: |
| programStageIdScheme | CSV格式: | ```csv |
| “ dataelement”,“ period”,“ orgunit”,“ categoryoptioncombo”,“ attributeoptioncombo”,“ value” | ||
| “ f7n9E0hX8qk”,“ 201401”,“ DiszpKrYNg8”,“ bRowv6yZOF2”,“ bRowv6yZOF2”,“ 1” | ||
| “ Ix2HsbDMLea”,“ 201401”,“ DiszpKrYNg8”,“ bRowv6yZOF2”,“ bRowv6yZOF2”,“ 2” | ||
| “ eY5ehpbEsB7”,“ 201401”,“ DiszpKrYNg8”,“ bRowv6yZOF2”,“ bRowv6yZOF2”,“ 3” | ||
| ``` | ||
| End date for the time span of the values to export | orgUnitIdScheme | 请注意,使用 CSV 格式时,您必须使用二进制数据选项 |
| 保留 CSV 文件中的换行符: | ||
| programIdScheme | CSV格式: | ```xml |
| ``` | ||
| outlining how to resolve identified issues | orgUnitIdScheme | The import process can be customized using a set of import parameters. |
| Table: Import parameters | orgUnitIdScheme | Values (default first) |
UID, CODE, NAME, ATTRIBUTE:{uid} | orgUnitIdScheme | uid | name | code | attribute:ID |
| 方案 | orgUnitIdScheme | uid | name | code | attribute:ID |
| 假 | 假 | uid | name | code| attribute:ID |
| 总览 | 假 | source.target.request.categoryOptionComboIdScheme |
Sets import strategy, CREATE_AND_UPDATE will try and match on identifier, if it doesn't exist, it will create the object. | dataSetIdScheme | id | name | code | attribute:ID |
| Property of the data set to use to map the complete registrations. | 假 | uid | name | code| attribute:ID |
| Property of the category object to use to map the data values (ADX only). | 假 | source.target.request.orgUnitIdScheme |
| 异步导入时,会立即返回一个 Location 标头,指向 importReport 的位置。有效载荷还包含一个已创建任务的 json 对象。 | 假 | id | name | code | attribute:ID |
| Property of any of the above objects if they are not specified, to use to map the data values. | 假 | false | true |
| 描述 | storedByDataValue | false | true |
所有参数都是可选的,可以作为查询参数提供 请求 URL 是这样的:
importStrategy
它们也可以作为数据值集上的 XML 属性提供 元素如下。 XML 属性将覆盖查询字符串 参数。
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataElementIdScheme="code"
orgUnitIdScheme="name" dryRun="true" importStrategy="CREATE">
</dataValueSet>
请注意,preheatCache 参数会对 表现。对于小的导入文件,将其设置为 false 会很快。 对于包含大量不同数据的大型导入文件 元素和组织单位,将其设置为 true 将是 幅度更快。
数据值要求¶
数据值导入支持一组值类型。对于每个值类型, 有一个特殊要求。下表列出了边缘情况 对于值类型。
skipAudit
| 值类型 | 要求 | 评论 |
|---|---|---|
JSON object for ADD proposal, JSON array for UPDATE proposal, nothing for REMOVE proposal | Indicates whether the import should be done asynchronous or synchronous. The former is suitable for very large imports as it ensures that the request does not time out, although it has a significant performance overhead. The latter is faster but requires the connection to persist until the process is finished. | force |
标识符方案¶
Regarding the id schemes, by default the identifiers used in the XML messages use the DHIS2 stable object identifiers referred to as UID. In certain interoperability situations we might experience that an external system decides the identifiers of the objects. In that case we can use the code property of the organisation units and other objects to set fixed identifiers. When importing data values we hence need to reference the code property instead of the identifier property of these metadata objects. Identifier schemes can be specified in the XML message as well as in the request as query parameters. To specify it in the XML payload you can do this:
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0"
dataElementIdScheme="CODE" orgUnitIdScheme="UID" idScheme="CODE">
</dataValueSet>
上面的参数表解释了如何指定 id 方案 作为查询参数。以下规则适用于 优先级:
-
XML 或 JSON 负载中定义的 ID 方案优先于 id 方案定义为 URL 查询参数。
-
/api/dataValueSets?dataElementIdScheme=code&orgUnitIdScheme=name &dryRun=true&importStrategy=CREATE orgUnitIdScheme 优先于一般 idScheme。
-
```xml
请注意,`preheatCache` 参数会对 表现。对于小的导入文件,将其设置为 false 会很快。 对于包含大量不同数据的大型导入文件 元素和组织单位,将其设置为 true 将是 幅度更快。 以下标识符方案可用。 - storedByDataValue - 码 - 名称 - 属性(后跟属性的UID) 属性选项是特殊的,指的是元数据属性 已被标记为*独特*。使用此选项时,`attribute` 必须 紧随其后的是属性的标识符,例如 “属性:DnrLSdo4hMl”。 #### 异步数据值导入 { #webapi_data_values_async_import } 可以通过以下方式以异步方式发送和导入数据值 提供设置为 *true* 的 `async` 查询参数: Used when the value is a boolean, true or false value. The import service does not care if the input begins with an uppercase or lowercase letter, or if it's all uppercase. 这将启动一个异步导入作业,您可以对其进行监控 任务摘要 API 中的状态。 API 响应表明 作业的唯一标识符、作业类型和可用于的 URL 监控导入作业状态。响应将类似于以下内容: ```json { "httpStatus": "OK", "httpStatusCode": 200, "status": "OK", "message": "Initiated dataValueImport", "response": { "name": "dataValueImport", "id": "YR1UxOUXmzT", "created": "2018-08-20T14:17:28.429", "jobType": "DATAVALUE_IMPORT", "relativeNotifierEndpoint": "/api/system/tasks/DATAVALUE_IMPORT/YR1UxOUXmzT" } }
请阅读有关*异步任务状态*的部分了解更多信息 信息。
CSV数据值格式¶
以下部分描述了 DHIS2 中使用的 CSV 格式。首先 行被假定为标题行,在导入期间将被忽略。
id 方案定义为 URL 查询参数。
| 柱 | 需要 | 描述 |
| 数据元素 | 是的 | uid |
| 期 | 是的 | 属性(后跟属性的UID) |
| 组织单位 | 是的 | uid |
| 类别选项组合 | 不 | ```json |
| { | ||
| "httpStatus": "OK", | ||
| "httpStatusCode": 200, | ||
| "status": "OK", | ||
| "message": "Initiated dataValueImport", | ||
| "response": { | ||
| "name": "dataValueImport", | ||
| "id": "YR1UxOUXmzT", | ||
| "created": "2018-08-20T14:17:28.429", | ||
| "jobType": "DATAVALUE_IMPORT", | ||
| "relativeNotifierEndpoint": "/api/system/tasks/DATAVALUE_IMPORT/YR1UxOUXmzT" | ||
| } | ||
| } | ||
| ``` | ||
| 请阅读有关*异步任务状态*的部分了解更多信息 | ||
| 信息。 | 不 | 以下部分描述了 DHIS2 中使用的 CSV 格式。首先 |
| 行被假定为标题行,在导入期间将被忽略。 | ||
| 值 | 不 | 资料值 |
| 描述 | 不 | 是的 |
| Refers to ID by default, can also be name and code based on selected id scheme | 不 | 是的 |
| 评论 | 不 | 是的 |
| Refers to ID by default, can also be name and code based on selected id scheme | 不 | 不 |
可以导入DHIS2的CSV文件示例如下所示。
“ dataelement”,“ period”,“ orgunit”,“ catoptcombo”,“ attroptcombo”,“ value”,“ storedby”,“ timestamp”
“ DUSpd8Jq3M7”,“ 201202”,“ gP6hn503KUX”,“ Prlt0C1RF0s”,“ 7”,“ bombali”,“ 2010-04-17”
“ DUSpd8Jq3M7”,“ 201202”,“ gP6hn503KUX”,“ V6L425pT3A0”,“ 10”,“ bombali”,“ 2010-04-17”
“ DUSpd8Jq3M7”,“ 201202”,“ OjTS752GbZE”,“ V6L425pT3A0”,“ 9”,“孟买”,“ 2010-04-06”
生成数据值集模板¶
要为特定数据集生成数据值集模板,您可以使用 /api/dataSets/ <id> /dataValueSet 资源。 XML 和 JSON 响应 支持格式。例子:
值
描述了可用于进一步调整输出的参数 以下:
您还可以请求CSV格式的数据,如下所示:
| 查询参数 | 需要 | 描述 |
|---|---|---|
| eventDate | 不 | Date in ISO format |
| orgUnit | 不 | Free text comment |
| 描述 | 不 | true or false |
| programStageIdScheme | 不 | 生成数据值集模板 { #webapi_data_values_template } |
| 数据元素标识方案 | 不 | 描述了可用于进一步调整输出的参数 |
| 以下: |
读取数据值¶
查询参数
需要
描述
Whether to save changes on the server or just return the import summary.
| 默认值 | 描述 |
|---|---|
| 描述 | 不 |
| Organisation unit to use, supports multiple orgUnits, both id and code can be used. | comment |
| 最小最大数据元素 | Should comments be include, default: Yes. |
| eventDate | 不 |
| 开始日期 | 数据元素标识方案 |
| 结束日期 | Data-element scheme to use, supports id | code. |
| orgUnit | To read data values you can make a GET request to the following resource. |
| Table: Data value set query parameters | 是否将子代包含在组织单位的层次结构中。布尔值(默认为 "false")。 |
| 读取完整的数据集注册 { #webapi_reading_complete_data_sets } | Parameter |
| > 注 | |
| > | |
| > 以下属性可能使用了外部系统的引用,因此被特意排除在合并之外。如果这些字段出现问题,可能需要更新。 | |
| > | |
| > 指标: aggregateExportCategoryOptionCombo & aggregateExportAttributeOptionCombo | |
| > | |
| > 项目指标: aggregateExportCategoryOptionCombo & aggregateExportAttributeOptionCombo | dataSet |
| 串 | dataElementGroup |
| 不 | dataElement |
| Data element identifier. Can be repeated any number of times. | period |
| 不 | 开始日期 |
| 数据元素标识方案 | 结束日期 |
| programStageIdScheme | orgUnit |
| programIdScheme | children |
| End date for the time span of the values to export | orgUnitGroup |
| outlining how to resolve identified issues | attributeOptionCombo |
| Table: Import parameters | includeDeleted |
UID, CODE, NAME, ATTRIBUTE:{uid} | lastUpdated |
| 方案 | lastUpdatedDuration |
| Include only data values which are updated within the given duration. The format is <value><time-unit>, where the supported time units are "d" (days), "h" (hours), "m" (minutes) and "s" (seconds). | limit |
| The max number of results in the response. | 数据元素标识方案 |
| Property of the data element object to use for data values in response. | orgUnitIdScheme |
| Property of the org unit object to use for data values in response. | categoryOptionComboIdScheme |
| The name of the headers to be returned as part of the response. One or more headers name separated by comma | attributeOptionComboIdScheme |
| Property of the attribute option combo objects to use for data values in response. | dataSetIdScheme |
| Property of the data set object to use in the response. | categoryIdScheme |
Property of the category object to use in the response (ADX only). - categoryOptionIdScheme - Property of the category option object to use in the response (ADX only). - 方案
支持以下响应格式:
-
xml(应用程序/ xml)
-
json(应用程序/ json)
-
csv(应用程序/ csv)
-
adx(应用程序/ adx + xml)
假设我们已经根据 上一节称为 发送数据值 我们现在可以放在一起 我们对单个数据值集的请求并使用 cURL 请求它:
Identifier property used for the provided dataElementGroup parameter values; id or code
我们还可以使用开始和结束日期查询参数来请求一个 大量的数据值。 IE。您还可以请求数据值 多个数据集和组织单位以及一个时间跨度以便导出 更大的数据块。请注意,期间查询参数采用 优先于开始和结束日期参数。一个例子看起来像 这:
Identifier property used for the provided dataElement parameter values; id or code
检索已创建或更新的数据值 过去 10 天,您可以提出这样的请求:
/ api / dataValueSets?dataSet = pBOMPrpg1QX&orgUnit = DiszpKrYNg8&lastUpdatedDuration = 10d
响应将如下所示:
<?xml version='1.0' encoding='UTF-8'?>
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="pBOMPrpg1QX"
completeDate="2014-01-02" period="201401" orgUnit="DiszpKrYNg8">
<dataValue dataElement="eY5ehpbEsB7" period="201401" orgUnit="DiszpKrYNg8"
categoryOptionCombo="bRowv6yZOF2" value="10003"/>
<dataValue dataElement="Ix2HsbDMLea" period="201401" orgUnit="DiszpKrYNg8"
categoryOptionCombo="bRowv6yZOF2" value="10002"/>
<dataValue dataElement="f7n9E0hX8qk" period="201401" orgUnit="DiszpKrYNg8"
categoryOptionCombo="bRowv6yZOF2" value="10001"/>
</dataValueSet>
您可以使用JSON格式请求数据,如下所示:
File name to use for the response, a non-blank value indicates rendering the response as an attachment.
响应将如下所示:
{
"dataSet": "pBOMPrpg1QX",
"completeDate": "2014-02-03",
"period": "201401",
"orgUnit": "DiszpKrYNg8",
"dataValues": [
{
"dataElement": "eY5ehpbEsB7",
"categoryOptionCombo": "bRowv6yZOF2",
"period": "201401",
"orgUnit": "DiszpKrYNg8",
"value": "10003"
},
{
"dataElement": "Ix2HsbDMLea",
"categoryOptionCombo": "bRowv6yZOF2",
"period": "201401",
"orgUnit": "DiszpKrYNg8",
"value": "10002"
},
{
"dataElement": "f7n9E0hX8qk",
"categoryOptionCombo": "bRowv6yZOF2",
"period": "201401",
"orgUnit": "DiszpKrYNg8",
"value": "10001"
}
]
}
请注意,数据值是软删除的,即删除的值具有 deleted 属性设置为 true 而不是被永久删除。 这在集成多个系统以进行通信时很有用 删除。您可以在响应中包含已删除的值,如下所示:
either orgUnit or orgUnitGroup
您还可以请求CSV格式的数据,如下所示:
xml(应用项目/ xml)
响应将如下所示:
数据元素,期限,组织单位,catoptcombo,attroptcombo,值,存储于,最后更新,注释,开始
f7n9E0hX8qk,201401,DiszpKrYNg8,bRowv6yZOF2,bRowv6yZOF2,12,system,2015-04-05T19:58:12.000,comment1,false
Ix2HsbDMLea,201401,DiszpKrYNg8,bRowv6yZOF2,bRowv6yZOF2,14,system,2015-04-05T19:58:12.000,comment2,false
eY5ehpbEsB7,201401,DiszpKrYNg8,bRowv6yZOF2,bRowv6yZOF2,16,系统,2015-04-05T19:58:12.000,comment3,false
FTRrcoaog83,201401,DiszpKrYNg8,bRowv6yZOF2,bRowv6yZOF2,12,系统,2014-03-02T21:45:05.519,comment4,false
adx(应用项目/ adx + xml)
假设我们已经根据 上一节称为 发送数据值 我们现在可以放在一起 我们对单个数据值集的请求并使用 cURL 请求它:
curl "https://play.dhis2.org/demo/api/dataValueSets?dataSet=pBOMPrpg1QX&period=201401&orgUnit=DiszpKrYNg8"
-H "Accept:application/xml" -u admin:district
以下约束适用于数据值集资源:
-
必须至少指定一个数据集。
-
必须是至少一个期间或开始日期和结束日期 指定的。
-
必须至少指定一个组织单位。
-
组织单位必须在组织的层次结构内 认证用户的单位。
-
限制不能小于零。
发送,读取和删除单个数据值¶
此示例将显示如何发送要保存的单个数据值 一个要求。这可以通过发送一个 POST 请求到 dataValues 资源:
请注意,数据值是软删除的,即删除的值具有 deleted 属性设置为 true 而不是被永久删除。 这在集成多个系统以进行通信时很有用 删除。您可以在响应中包含已删除的值,如下所示:
此资源支持以下查询参数:
您还可以请求CSV格式的数据,如下所示:
| 查询参数 | 需要 | 描述 |
|---|---|---|
| 德 | 是的 | / api / 33 / system / flags |
| 聚乙烯 | 是的 | 期间标识符 |
| 欧 | 是的 | / api / 33 / system / taskSummaries / {task-category-id} |
| 描述 | 不 | 发送,读取和删除单个数据值 { #webapi_sending_individual_data_values } |
| ```bash | ||
| GET /api/33/completeDataSetRegistrations?dataSet=pBOMPrpg1QX | ||
| &startDate=2014-01-01&endDate=2014-01-31&orgUnit=YuQRtpLP10I | ||
| &orgUnit=vWbkYPRmKyS&children=true | ||
| ``` | POST /api/dataValues | 此资源支持以下查询参数: |
| 本节说明如何取消注册数据的完整性 | ||
| 放。要取消完成数据集,您将与 | ||
| completeDataSetRegistrations 资源: | 查询参数 | 需要 |
| Table: Query parameters | 不 | 是的 |
| 价值 | 不 | 是的 |
| 描述 | 不 | 是的 |
| 跟进 | 不 | 不 |
如果给定的任何标识符无效,如果数据值或 评论无效或如果数据被锁定,响应将包含 409 Conflict 状态代码和描述性文本消息。如果 操作导致保存或更新的值,200 OK 将被返回。 请求的示例如下所示:
cc
此资源还允许使用特殊语法将值关联到 一个属性选项组合。这可以通过发送 属性类别组合的标识符,连同标识符 值代表的属性类别选项 组合。类别组合由 cc 参数指定,而 类别选项被指定为分号分隔的字符串,带有cp 范围。有必要确保类别选项都是部分 的类别组合。一个示例如下所示:
Attribute category combo identifier
您可以使用 GET 方法通过请求检索数据值。这 value、comment 和 followUp 参数在这方面不适用:
No (must be combined with cc)
您可以使用 DELETE 方法通过请求删除数据值。
ds¶
不
Data set, to check if POST or DELETE is allowed for period and organisation unit. If specified, the data element must be assigned to this data set. If not specified, a data set containing the data element will be chosen to check if the operation is allowed.
价值
不
Data value. For boolean values, the following will be accepted: true | True | TRUE | false | False | FALSE | 1 | 0 | t | f |
comment
如果数据值已成功保存或更新,则状态代码将为201 Created,如果存在验证错误,则状态代码将为409 Conflict。
处理文件数据值¶
处理具有 file 类型数据元素的数据值时 与上述方法存在一些偏差。这些数据 值的特殊之处在于值的内容是一个 UID 引用 到 FileResource 对象而不是自包含常量。这些 数据值的行为就像其他存储文本的数据值一样 内容,但应以不同方式处理以产生 有意义的输入和输出。
不
-
Follow up on data value, will toggle the current boolean value 如果给定的任何标识符无效,如果数据值或 评论无效或如果数据被锁定,响应将包含 409 Conflict 状态代码和描述性文本消息。如果 操作导致保存或更新的值,200 OK 将被返回。 请求的示例如下所示:
-
```bash curl "https://play.dhis2.org/demo/api/dataValues?de=s46m5MS0hxu &pe=201301&ou=DiszpKrYNg8&co=Prlt0C1RF0s&value=12" -X POST -u admin:district
此资源还允许使用特殊语法将值关联到 一个属性选项组合。这可以通过发送 属性类别组合的标识符,连同标识符 值代表的属性类别选项 组合。类别组合由 `cc` 参数指定,而 类别选项被指定为分号分隔的字符串,带有`cp` 范围。有必要确保类别选项都是部分 的类别组合。一个示例如下所示: 1. 如所述将文件上传到 `/api/fileResources` 端点 在文件资源部分。 2. ```bash curl "https://play.dhis2.org/demo/api/dataValues?de=s46m5MS0hxu &pe=201301&ou=DiszpKrYNg8&co=Prlt0C1RF0s" -u admin:district -
您可以使用 DELETE 方法通过请求删除数据值。 上面描述的方法。
数据值和文件资源之间只有一对一的关系 允许。这是在内部强制执行的,以便保存文件资源 ID 在多个数据值中是不允许的,并且会返回错误。删除 数据值将删除引用的文件资源。直接删除 的文件资源是不可能的。
数据值现在可以作为除返回数据以外的任何其他值进行检索 将是文件资源的 UID。为了检索实际 内容(意味着存储在映射的文件资源中的文件 到数据值)必须向 /api/dataValues/files 发出 GET 请求 镜像查询参数,因为它们将用于数据值 本身。 /api/dataValues/files 端点仅支持 GET 请求。
值得注意的是,由于底层存储机制工作 异步文件内容可能不会立即准备好 从/api/dataValues/files 端点下载。这是特别真实的 对于可能需要耗时上传的大文件 外部文件存储的背景(取决于系统 配置)。从文件资源元数据中检索 /api/fileResources/ <id> 端点允许检查 storageStatus 在尝试下载内容之前。
ADX数据格式¶
The endpoint supports specifying attribute option combos in a nested structure.
ADX 数据消息的结构与您可能的结构非常相似 从前面描述的 DXF 2 数据中已经熟悉了。有一个 几个重要的区别。我们将描述这些差异 参考一个小例子:
<adx xmlns="urn:ihe:qrph:adx:2015" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ihe:qrph:adx:2015 ../schema/adx_loose.xsd"
exported="2015-02-08T19:30:00Z">
<group orgUnit="OU_559" period="2015-06-01/P1M"
completeDate="2015-07-01" dataSet="(TB/HIV)VCCT">
<dataValue dataElement="VCCT_0" GENDER="FMLE" HIV_AGE="AGE0-14" value="32"/>
<dataValue dataElement="VCCT_1" GENDER="FMLE" HIV_AGE="AGE0-14" value="20"/>
<dataValue dataElement="VCCT_2" GENDER="FMLE" HIV_AGE="AGE0-14" value="10"/>
<dataValue dataElement="PLHIV_TB_0" GENDER="FMLE" HIV_AGE="AGE0-14" value="10"/>
<dataValue dataElement="PLHIV_TB_1" GENDER="FMLE" HIV_AGE="AGE0-14" value="10"/>
<dataValue dataElement="VCCT_0" GENDER="MLE" HIV_AGE="AGE0-14" value="32"/>
<dataValue dataElement="VCCT_1" GENDER="MLE" HIV_AGE="AGE0-14" value="20"/>
<dataValue dataElement="VCCT_2" GENDER="MLE" HIV_AGE="AGE0-14" value="10"/>
<dataValue dataElement="PLHIV_TB_0" GENDER="MLE" HIV_AGE="AGE0-14" value="10"/>
<dataValue dataElement="PLHIV_TB_1" GENDER="MLE" HIV_AGE="AGE0-14" value="10"/>
<dataValue dataElement="VCCT_0" GENDER="FMLE" HIV_AGE="AGE15-24" value="32"/>
<dataValue dataElement="VCCT_1" GENDER="FMLE" HIV_AGE="AGE15-24" value="20"/>
<dataValue dataElement="VCCT_2" GENDER="FMLE" HIV_AGE="AGE15-24" value="10"/>
<dataValue dataElement="PLHIV_TB_0" GENDER="FMLE" HIV_AGE="AGE15-24" value="10"/>
<dataValue dataElement="PLHIV_TB_1" GENDER="FMLE" HIV_AGE="AGE15-24" value="10"/>
<dataValue dataElement="VCCT_0" GENDER="MLE" HIV_AGE="AGE15-24" value="32"/>
<dataValue dataElement="VCCT_1" GENDER="MLE" HIV_AGE="AGE15-24" value="20"/>
<dataValue dataElement="VCCT_2" GENDER="MLE" HIV_AGE="AGE15-24" value="10"/>
<dataValue dataElement="PLHIV_TB_0" GENDER="MLE" HIV_AGE="AGE15-24" value="10"/>
<dataValue dataElement="PLHIV_TB_1" GENDER="MLE" HIV_AGE="AGE15-24" value="10"/>
</group>
</adx>
处理文件数据值¶
处理具有 file 类型数据元素的数据值时 与上述方法存在一些偏差。这些数据 值的特殊之处在于值的内容是一个 UID 引用 到 FileResource 对象而不是自包含常量。这些 数据值的行为就像其他存储文本的数据值一样 内容,但应以不同方式处理以产生 有意义的输入和输出。
There are two methods of storing file resource data values.¶
Upload the file to the /api/dataValues/file endpoint as
described in the file resource section. This works on versions 2.36 and later.
If you are writing code that needs to be compatible
ADX期间定义¶
如所述将文件上传到 /api/fileResources 端点
在文件资源部分。
| 期间类型 | Store the retrieved identifier using the value property of the data value using any | 上面描述的方法。 | 数据值和文件资源之间只有一对一的关系 允许。这是在内部强制执行的,以便保存文件资源 ID 在多个数据值中是不允许的,并且会返回错误。删除 数据值将删除引用的文件资源。直接删除 的文件资源是不可能的。 | |---|---|---|---| | 日常 | 值得注意的是,由于底层存储机制工作 异步文件内容可能不会立即准备好 从/api/dataValues/files 端点下载。这是特别真实的 对于可能需要耗时上传的大文件 外部文件存储的背景(取决于系统 配置)。从文件资源元数据中检索 /api/fileResources/ <id> 端点允许检查 storageStatus 在尝试下载内容之前。 | Oct 04 2017-Oct 10-2017 | From version 2.20 we have included support for an international standard for aggregate data exchange called ADX. ADX is developed and maintained by the Quality Research and Public Health committee of the IHE (Integrating the HealthCare Enterprise). The wiki page detailing QRPH activity can be found at wiki.ihe.net. ADX is still under active development and has now been published for trial implementation. Note that what is implemented currently in DHIS2 is the functionality to read and write ADX formatted data, i.e. what is described as Content Consumer and Content Producer actors in the ADX profile. | | ADX 数据消息的结构与您可能的结构非常相似 从前面描述的 DXF 2 数据中已经熟悉了。有一个 几个重要的区别。我们将描述这些差异 参考一个小例子: | Unlike dxf2, ADX requires that the datavalues are grouped according to orgUnit, period and dataSet. The example above shows a data report for the "(TB/HIV) VCCT" dataset from the online demo database. This example is using codes as identifiers instead of dhis2 uids. Codes are the preferred form of identifier when using ADX. | The ADX root element { #the-adx-root-element } | The ADX root element has only one mandatory attribute, which is the exported timestamp. In common with other ADX elements, the schema is extensible in that it does not restrict additional application specific attributes. | | The ADX group element { #the-adx-group-element } | Unlike dxf2, ADX requires that the datavalues are grouped according to orgUnit, period and dataSet. The example above shows a data report for the "(TB/HIV) VCCT" dataset from the online demo database. This example is using codes as identifiers instead of dhis2 uids. Codes are the preferred form of identifier when using ADX. | The orgUnit, period and dataSet attributes are mandatory in ADX. The group element may contain additional attributes. In our DHIS2 implementation any additional attributes are simply passed through to the underlying importer. This means that all attributes which currently have meaning in dxf2 (such as completeDate in the example above) can continue to be used in ADX and they will be processed in the same way. | A significant difference between ADX and dxf2 is in the way that periods are encoded. ADX makes strict use of ISO8601 and encodes the reporting period as (date|datetime)/(duration). So the period in the example above is a period of 1 month (P1M) starting on 2015-06-01. So it is the data for June 2015. The notation is a bit more verbose, but it is very flexible and allows us to support all existing period types in DHIS2 | | ADX期间定义 { #adx-period-definitions } | Unlike dxf2, ADX requires that the datavalues are grouped according to orgUnit, period and dataSet. The example above shows a data report for the "(TB/HIV) VCCT" dataset from the online demo database. This example is using codes as identifiers instead of dhis2 uids. Codes are the preferred form of identifier when using ADX. | Table: ADX Periods | 期间类型 | | Duration notation | Unlike dxf2, ADX requires that the datavalues are grouped according to orgUnit, period and dataSet. The example above shows a data report for the "(TB/HIV) VCCT" dataset from the online demo database. This example is using codes as identifiers instead of dhis2 uids. Codes are the preferred form of identifier when using ADX. | Duration(s) | 日常 | | P1D | Unlike dxf2, ADX requires that the datavalues are grouped according to orgUnit, period and dataSet. The example above shows a data report for the "(TB/HIV) VCCT" dataset from the online demo database. This example is using codes as identifiers instead of dhis2 uids. Codes are the preferred form of identifier when using ADX. | Oct 01 2017 | Weekly | | P7D | 2017-10-02/P7D | Oct 02 2017-Oct 08-2017 | Weekly Wednesday | | P7D | 2017-10-04/P7D | Oct 04 2017-Oct 10-2017 | Weekly Thursday | | 双月刊 | 2017-10-05/P7D | Oct 05 2017-Oct 011-2017 | Weekly Saturday | | P7D | 2017-10-07/P7D | Oct 07 2017-Oct 13-2017 | Weekly Sunday | | P7D | 2017-10-01/P1M | Oct 01 2017-Oct 07-2017 | Bi-weekly | | P14D | 2017-10-01/P1M | Oct 02 2017-Oct 15 2017 | Monthly | | P1M | 2017-10-01/P1M | Oct 01 2017-Oct 31 2017 | 双月刊 | | P2M | 2017-01-01/P6M
2017-07-01/P6M | Nov 01 2017-Dec 31 2017 | Quarterly | | P3M | 2017-01-01/P6M
2017-07-01/P6M | Sep 01 2017-Dec 31 2017 | Six-monthly | | P6M | 2017-01-01/P6M
2017-07-01/P6M | Jan 01 2017-Jun 30 2017
Jul 01 2017-Dec 31 2017 | Six-monthly April | | P6M | 2017-01-01/P6M
2017-07-01/P6M | Apr 01 2017-Sep 30 2017
Oct 01 2017-Mar 31 2018 | Six-monthly November | | P6M | 2017-01-01/P6M
2017-07-01/P6M | Nov 01 2017-Apr 30 2018
May 01 2018-Oct 31 2018 | Yearly |
P1Y¶
2017-01-01/P1Y
Jan 01 2017-Dec 31 2017
Financial April
使用分解数据的显式维度的主要好处是 那
-
生成数据的系统不必与 DHIS2 中的 categoryOptionCombo。
-
生产者和消费者可以将他们的代码与第三方进行匹配 权威来源,例如 vterminology 服务。请注意,在 上面的性别和年龄组代码示例使用的是代码列表 来自世卫组织全球卫生观察站。
Financial October
P1Y
2017-10-01/P1Y¶
Oct 01 2017-Sep 30 2018
Financial November
P1Y
2017-11-01/P1Y¶
Nov 01 2017-Oct 31 2018
ADX Data values { #adx-data-values }
The dataValue element in ADX is very similar to its equivalent in DXF. The mandatory attributes are dataElement and value. The orgUnit and period attributes don't appear in the dataValue as they are required at the group level.
后续行动¶
本节介绍了后续的标记数据。
数据值跟踪¶
数据值跟踪端点允许标记数据值以进行跟踪。
PUT / api / 36 / dataValues /跟进
生产者和消费者可以将他们的代码与第三方进行匹配
{
"dataElement": "s46m5MS0hxu",
"period": "202005",
"orgUnit": "DiszpKrYNg8",
"categoryOptionCombo": "psbwp3CQEhs",
"attributeOptionCombo": "HllvX50cXC0",
"followup": true
}
上面的性别和年龄组代码示例使用的是代码列表
{
"dataElement": "s46m5MS0hxu",
"period": "202005",
"orgUnit": "DiszpKrYNg8",
"followup": false
}
Note that this feature may be extremely useful, for example when producing disaggregated data from an EMR system, but there may be cases where a categoryOptionCombo mapping is easier or more desirable. The DHIS2 implementation of ADX will check for the existence of a categoryOptionCombo attribute and, if it exists, it will use that in preference to exploded dimension attributes. Similarly, an attributeOptionCombo attribute on the group element will be processed in the legacy way. Otherwise, the attributeOptionCombo can be treated as exploded categories just as on the dataValue.
如果操作成功,响应状态代码将为200 OK,如果请求出错,则响应状态代码为409 Conflict。
Importing ADX data { #importing-adx-data }
DHIS2 exposes an endpoint for POST ADX data at /api/dataValueSets using application/xml+adx as content type. So, for example, the following curl command can be used to POST the example data above to the DHIS2 demo server:
curl -u admin:district -X POST -H "Content-Type: application/adx+xml"
-d @data.xml "https://play.dhis2.org/demo/api/dataValueSets?dataElementIdScheme=code&orgUnitIdScheme=code"
{
"values": [
{
"dataElement": "s46m5MS0hxu",
"period": "202005",
"orgUnit": "DiszpKrYNg8",
"categoryOptionCombo": "psbwp3CQEhs",
"attributeOptionCombo": "HllvX50cXC0",
"followup": true
}
]
}
Exporting ADX data { #exporting-adx-data }
DHIS2 exposes an endpoint to GET ADX data sets at /api/dataValueSets using application/xml+adx as the accepted content type. So, for example, the following curl command can be used to retrieve the ADX data: