我正在尝试从事务返回查询结果。这是我的代码。
/**
* Sample transaction
* @param {org.zcon.healthcare.SearchPatient} tx
* @returns{org.zcon.healthcare.Patient[]}
* @transaction
*/
async function SearchPatient(tx){
let queryString = `SELECT org.zcon.healthcare.Patient WHERE (`;
let conditions = [];
if (tx.hasOwnProperty('firstName')) {
var firstName =tx.firstName;
conditions.push(`(firstName == "${firstName}")`)
};
if (tx.hasOwnProperty('lastName')) {
var lastName = tx.lastName;
conditions.push(`(lastName == "${lastName}")`)
};
if (tx.hasOwnProperty('gender')) {
var gender = tx.gender;
conditions.push(`(gender == "${gender}")`)
};
if (tx.hasOwnProperty('birthDate')) {
var dob =tx.birthDate;
conditions.push(`(birthDate == "${dob}")`)
};
if (tx.hasOwnProperty('ssn')) {
var ssn=tx.ssn;
conditions.push(`(ssn == "${ssn}")`)
};
if (tx.hasOwnProperty('medicalRecordNumber')) {
var mrn = tx.medicalRecordNumber;
conditions.push(`(medicalRecordNumber == "${mrn}")`)
};
queryString += conditions.join(' AND ') + ')';
console.log(queryString);
let finalQuery = buildQuery(queryString);
console.log(finalQuery);
const searchPatient = await query(finalQuery);
if(searchPatient.length ==0){
throw "No Patient Records found!!"
}else
return searchPatient;
}
但是除了事务细节,它不返回数组。我需要更改退货类型吗?还是我想念其他东西?
答案 0 :(得分:0)
正如穆罕默德(Mohammed)指出的那样,它是一个查询事务;您需要定义返回类型。还定义提交类型-如
@commit(false)
@returns(Patient[])
transaction SearchPatient {
<txn definition here>
}
模型(.cto)文件中的。
所有文档(带有示例)在这里-> https://hyperledger.github.io/composer/latest/reference/js_scripts