我目前是ngx_postgres的快乐用户。然而,我最近发现我需要做一些非常奇怪的事情。基本上我需要产生以下 json 输出:
{
"PatientName": {
"Tag": "00100010",
"VR": "PN",
"PersonName": [
{
"SingleByte": "Wang^XiaoDong",
"Ideographic": "王^小東"
}
]
},
},
{
"PatientName": {
"Tag": "00100010",
"VR": "PN",
"PersonName": [
{
"SingleByte": "John^Doe",
}
]
},
}
稍微阅读一下 DICOM 标准,就很容易创建(简化)关键字、标签和 VR 的等效表:
CREATE TABLE equiv (
"Keyword" varchar(64) PRIMARY KEY,
"Tag" char(8) NOT NULL,
"VR" char(2) NOT NULL,
);
好吧,现在棘手的部分是我不理解的 PatientName 的这种间接方式,我尝试了:
CREATE TABLE patientname (
"SingleByte" varchar(64) primary key,
"Ideographic" varchar(64),
);
CREATE TABLE patientlevel_impl_detail (
"PatientName" varchar(64) references patientname("SingleByte"),
"PatientID" character varying(64) NOT NULL
);
CREATE view patientlist as select
patientname."SingleByte",
patientname."Ideographic",
patientname."Phonetic",
patientlevel_impl_detail."PatientID"
FROM patientlevel_impl_detail,patientname where patientlevel_impl_detail."PatientName" = patientname."SingleByte";
但是在任何情况下,TABLE 和/或 VIEW 总是变平的,相反,我得到的是:
$ curl http://localhost:8080/patients
[
{
"Tag": "00100010",
"VR": "PN",
"SingleByte": "John^Doe",
"Ideographic": null,
},
]
所以我看不到如何使 PersonName 成为嵌套字符串数组(嵌套 json 树)。
注意:我没有使用 9.3,我现在需要使用 9.1