getValues( )
このヘルパー関数を使用して、複数の訪問にわたる1つ以上の変数の値を、訪問順に配列形式でフェッチします。
ノート:
これは集計関数です。ターゲットが繰返しフォーム上にある場合、ルールは各フォーム・インスタンスに対して実行されます。
2項形式で使用する場合、GetCurrentRFInstance( )を使用して、現在の2項フォームインスタンスでのみ実行するようにルールを制限できます。
構文
getValues('var1', 'var2', ...)
戻り値
成功した場合はtrue
、それ以外の場合はfalse
を戻します。
ノート:
この変数に関連するデータ要素がない場合、ルール変数はnull
に再定義されます。このため、データの処理に使用する前に、変数に配列要素が含まれているかどうかを常に検証する必要があります。
- var1、 var2、 ... - パラメータとして渡される各変数は、結果を持つ配列を保持します。配列内の各項目(
var1[0]
など)には、次のものが含まれます。var1[0].visitName
- 訪問の名前var1[0].deleted
- 繰返しフォーム・インスタンスが削除された場合、truevar1[0].tableRowInstance
- 表内にある場合の繰返し表の行インスタンスvar1[0].branchName
- ブランチの名前var1[0].eventType
- 訪問のタイプ- ScheduleAbleVisit、UnScheduleAbleVisit、イベントなどvar1[0].formRepeatNumber
- ケース・フォームの繰返しフォーム・インスタンス番号は繰返しフォームですvar1[0].value
- データ要素値、または値がクリアされた場合はnull
var1[0].cycleNumber
- サイクルの場合の訪問のサイクル番号var1[0].empty
- 値がクリアされたか、繰返しフォームに入力されなかった場合はtruevar1[0].treatmentArm
- トリートメントアーム
- 日付要素:
- 変数が完全な日付の場合、返される変数値は
Date
オブジェクトです。 - 変数が部分的な日付の場合、返される変数値は
C1Date
オブジェクトです。ヒント:
部分的な日付の場合、値はオブジェクトとして返され、item.value
のみでなくitem.value.day
、item.value.month
などの日付部分を使用してフェッチする必要があります。// Sample JSON response for a partial date item: [ { "visitName": "visit1", "deleted": false, "tableRowInstance": null, "branchName": null, "eventType": "ScheduleAbleVisit", "formRepeatNumber": null, "value": { "partialDate": true, "date": null, "day": "UNK", "month": 2, "year": 2021 }, "cycleNumber": null, "empty": false, "treatmentArm": null } ]
- 変数が完全な日付の場合、返される変数値は
- 選択制御要素: 変数が選択制御(チェックボックス、ラジオまたはドロップダウン)の場合、返される変数値はJSON形式の文字列です。
これは、"[{\"value\":\"3\",\"label\":\"TestLabel\"}]"
JSON.parse
またはparseChoice( )
を使用して解析できます。
使用方法のヒント
'variable'
は「任意の訪問」タイプ変数です:getValues('variable')
このタイプの変数定義では、ルールを作成するターゲット・フォームと同じ訪問に存在しないフォームで収集されたデータを操作できます。詳細は、ルール変数の定義を参照してください。
制限
質問が複数の訪問に存在する場合は、getValues( )によって返されるデータの量が重要になる場合があります。これは、データ送信のパフォーマンスに影響を与える可能性があります。
ノート:
変数をgetValues( )に渡すと、ルール内の別の場所にある個別値として再利用することはできません。行の個別値を参照し、別の場所にアクセスする必要がある場合は、2番目の変数を宣言する必要があります。
例3-102単一アイテムに対するgetValues関数コールの結果の表示
// this can be helpful during rule development to view the results returned by the getValues function
// using a read-only text field as the target
var val = getValues("item1");
if (val == true) {
return JSON.stringify(item1);
}
/* example results:
[
{
"visitName": "visit1",
"deleted": false,
"tableRowInstance": null,
"branchName": null,
"eventType": "ScheduleAbleVisit",
"formRepeatNumber": null,
"value": "Test",
"cycleNumber": null,
"empty": false,
"treatmentArm": null
},
{
"visitName": "visit2",
"deleted": false,
"tableRowInstance": null,
"branchName": null,
"eventType": "ScheduleAbleVisit",
"formRepeatNumber": null,
"value": "Test",
"cycleNumber": null,
"empty": false,
"treatmentArm": null
}
]
*/
例3-103すべての訪問におけるすべての腫瘍直径値の合計
var sumTotalLongestDiameter = -1;
function calculateTumor(item, index)
{
if ( longestDiameter[index] !== null )
{
sumTotalLongestDiameter += longestDiameter[index].value;
}
}
var rc = getValues("tumorID", "longestDiameter");
if ( rc === true )
{
tumorID.forEach(calculateTumor);
// Set the value for the current row where this rule runs
return sumTotalLongestDiameter;
}
例3-104フィルタ機能を使用したスクリーニング・ビジットを除く、すべてのビジットの腫瘍直径の合計値
var rc = getValues("tumorID", "longestDiameter");
//filter by visit name
function filterFunction(item) {
return item.visitName !== 'Screening';
}
var sumTotalLongestDiameter = -1;
function calculateTumor(item, index)
{
if ( longestDiameter[index] !== null )
{
sumTotalLongestDiameter += longestDiameter[index].value;
}
}
if ( rc === true )
{
//exclude Screening visit
var filterResult = tumorID.filter(filterFunction);
filterResult.forEach(calculateTumor);
// Set the value for the current row where this rule runs
return sumTotalLongestDiameter;
}
例3-105同じフォームでターゲットおよびオペランドを使用した前/次の値の検索
brDateForFunc
- 日付を参照するルール変数。brDate
- 日付を参照するルール変数(異なる訪問で同じ項目を比較する必要がある場合、同じ名前を持つ最初の変数と同じです)。
var visitName = getCurrentVisitPropertyValue("visitid");
var currCycle = getCurrentCycle();var prevValue = null;
var prevValueFound = false;
function getPrevValue(item){
if(prevValueFound) return;
if(item.visitName==visitName && item.cycleNumber==currCycle){
prevValueFound = true; return;
}
if(item.eventType!='UnScheduleAbleVisit' && item.value!=null)
prevValue = item.value;
}
var res = getValues('brDateForFunc');
if(res){
brDateForFunc.forEach(getPrevValue);
//in case the next visit should be found the array should be reverted:
//brDateForFunc.reverse().forEach(getPrevValue);
//here should go the necessary logic to compare brDate with previous value which is now in variable prevValue
}
例3-106異なるフォームでターゲットおよびオペランドを使用した、最後または最も近い次の値の検索
aeDate
- AEフォームの日付を参照するルール変数。cycleDate1
- 最初のサイクル訪問の日付を参照するルール変数。cycleDate2
- 第2サイクル訪問の日付を参照するルール変数。cycleCheck1
- 最初のサイクル・ビジットのいくつかの条件を参照するルール変数。cycleCheck2
- 2番目のサイクル・ビジットのいくつかの条件を参照するルール変数。vsd
- 「すべての訪問」オプションを使用した訪問開始日
var lastStartedlVisit = null;
var lastVisitFound = false;
var cycleDate = null;
var cycleCheck = null;
var cycleNumber = null;
function getLastStartedlVisit(item){
if(lastVisitFound || item.eventType=='UnScheduleAbleVisit') return;
//condition may depend on where the point of comparison is, at some situation it can be <if(item.value==null)> or something else
if(item.eventType=='AdverseEvent'){
lastVisitFound = true;
return;
}
if(item.value!=null) {
lastStartedlVisit = item;
}
}
function findItem(item, index){
if(item.cycleNumber === cycleNumber){
if(this.valueOf()=='cycleDate') cycleDate = item.value;
if(this.valueOf()=='cycleCheck') cycleCheck = item.value;
}
}
var res = getValues('vsd');
if(res){
//the first visit before AE
vsd.forEach(getLastStartedlVisit);
//in case the next visit should be found the array should be reverted:
//vsd.reverse().forEach(getLastStartedlVisit);
cycleNumber = lastStartedlVisit.cycleNumber;
res = getValues('cycleDate1');
if( cycleDate1[cycleDate1.length-1].visitName == lastStartedlVisit.visitName){
cycleDate1.forEach(findItem, 'cycleDate');
res = getValues('cycleCheck1');
cycleCheck1.forEach(findItem, 'cycleCheck');
}
else{
res = getValues('cycleDate2');
if( cycleDate2[cycleDate2.length-1].visitName == lastStartedlVisit.visitName){
cycleDate2.forEach(findItem, 'cycleDate');
res = getValues('cycleCheck2');
cycleCheck2.forEach(findItem, 'cycleCheck');
}
}
}
//logMsg(JSON.stringify(aeDate))
//logMsg(JSON.stringify(cycleDate));
//logMsg(JSON.stringify(cycleCheck));
//logic to compare cycleDate cycleCheck and aeDate
例3-107日付と次の訪問開始日の比較
brDate
- 日付を参照するルール変数。vsd
- 「すべての訪問」オプションで訪問開始日を参照するルール変数。
var visitName = getCurrentVisitPropertyValue("visitid");
var currCycle = getCurrentCycle();
//logMsg(visitName);
//logMsg(currCycle);
//logMsg(brDate);
var nextValue = null;
var nextValueFound = false;
function getNextValue(item){
if(nextValueFound) return;
if(item.visitName==visitName && item.cycleNumber==currCycle){
nextValueFound = true;
return;
}
if(item.eventType!='UnScheduleAbleVisit' && item.value!=null)
nextValue = item.value;
}
var res = getValues('vsd');
if(res){
vsd.reverse().forEach(getNextValue);
//logMsg(nextValue);
//logMsg(brDate);
//compare next vsd with cycle date: vsd
}
親トピック:書式設定およびその他の機能