我建议如下[模型、查询定义等],如下所示-这是基于您走了“概念”路线的事实(您也可以使用普通数组,并查询一组天/小时,稍微不同的模型,但这是为了另一天)。您的查询(上面的)不能工作,因为您不能“单步执行”查询定义中的对象—它不像SQL数据库(只是为了清除它)。
下面的模型提供了这个概念
Availability
在资产中获取医生的可用性矩阵
Schedule
(因此与那里的医生有关系)。此外,它是一系列概念,允许该计划ID在每天的每小时计划。最后,医生(或一组医生)可以与该计划关联-如果是一对一的,那么显然您只需要提供一个“医生”条目。查看我的示例JSON数据
schedule
再往下。同样,医生(参与者)也可以与一个或多个时间表(或不与此相关,视情况而定)有关系,但选项仍然存在,正如您将在
Doctor
参与者,我有一个可选的
日程安排
(一组计划)-在这种情况下,它会将概念数据(在资产中)存储在实际参与者记录上(然后您会查询它)-但由于明显的原因,您可能不想管理参与者内部的计划数据。注意:这只是一个建议,基于你发布的内容-有很多方法可以剥橘子皮:—)
participant Doctor identified by doctorID {
o String doctorID
o String contact
o String doctorName
o String description
o Schedule[] schedule optional // see comment below
}
asset Schedule identified by scheduleID {
o String scheduleID
o Availability[] availability
--> Doctor[] doctor
}
concept Availability {
o WeekDay Day
o Hours Hour
}
enum WeekDay {
o MON
o TUE
o WED
o THU
o FRI
o SAT
o SUN
}
enum Hours {
o H00
o H01
o H02
o H03
o H04
o H05
o H06
o H07
o H08
o H09
o H10
o H11
o H12
o H13
o H14
o H15
o H16
o H17
o H18
o H19
o H20
o H21
o H22
o H23
}
使用该模型,您现在可以定义概念查询。
例1:
query doctordoctor1 {
description: "Select all doctors available at 1st hour on MON only"
statement: SELECT org.acme.mynetwork.Schedule
WHERE ( availability CONTAINS (Day == "MON" AND Hour == "H01" ) )
}
仅返回附表4,因此医生1和2(而不是医生3或4)
例2:
query doctordoctor2 {
description: "Select all doctors available at 1st hour - any day"
statement: SELECT org.acme.mynetwork.Schedule
WHERE ( availability CONTAINS (Hour == "H01" ) )
}
将返回时间表4和5,这意味着医生1和2+医生3和4将匹配。
请注意,它不会返回该查询中医生配置文件的详细信息请注意-您可以在一个事务中调用该查询,然后根据返回的查询对象(计划)之间的关系为每个找到的医生获取相关的医生信息(如有需要)。
==========数据====(保留在此处,但可以放入Pastebin)
{
"$class": "org.acme.mynetwork.Schedule",
"scheduleID": "4",
"availability": [
{
"$class": "org.acme.mynetwork.Availability",
"Day": "MON",
"Hour": "H01"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "MON",
"Hour": "H02"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "MON",
"Hour": "H03"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "TUE",
"Hour": "H04"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "TUE",
"Hour": "H05"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "TUE",
"Hour": "H06"
}
],
"doctor": [
"resource:org.acme.mynetwork.Doctor#1",
"resource:org.acme.mynetwork.Doctor#2"
]
}
下一项
{
"$class": "org.acme.mynetwork.Schedule",
"scheduleID": "5",
"availability": [
{
"$class": "org.acme.mynetwork.Availability",
"Day": "WED",
"Hour": "H01"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "WED",
"Hour": "H02"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "THU",
"Hour": "H03"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "FRI",
"Hour": "H04"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "SAT",
"Hour": "H05"
},
{
"$class": "org.acme.mynetwork.Availability",
"Day": "SAT",
"Hour": "H06"
}
],
"doctor": [
"resource:org.acme.mynetwork.Doctor#3",
"resource:org.acme.mynetwork.Doctor#4"
]
}
====从事务处理程序调用查询的代码-或者只调用它
来自其余API
/**
* Track the schedule
* @param {org.acme.mynetwork.doctor} doctor - the query object as a trxn
* @transaction
*/
function doctor(doctor) {
console.log('got inside doctor function');
return query('doctordoctor') //
.then(function (results) {
var schedule_asset = [];
for (var n = 0; n < results.length; n++) {
var schedule_asset = results[n];
console.log('The transaction object ' + (n+1) + ', object is ' + schedule_asset);
console.log('Schedule identifier is: ' + schedule_asset.getIdentifier());
console.log(' Doctor id is ' + schedule_asset.doctor[0].getIdentifier());
}
});
}