2016-10-01 180 views
0

通過CCDA的實驗室工作需要遍歷父兒童和兒童片段,但對於「實驗室」變量沒有然而「一節」和「頭」的工作:組合嵌套的foreach循環

var file=""; var header=""; var Lab=""; var section=""; 


header=msg['recordTarget']['patientRole']['patient']['name']['family'].toString()+"|"+ //last name msg['recordTarget']['patientRole']['patient']['name']['given'].toString()+"|"+ //first name msg['recordTarget']['patientRole']['patient']['administrativeGenderCode']['@code'].toString()+"|"+ //gender msg['recordTarget']['patientRole']['patient']['birthTime']['@value'].toString(); //DOB msg['component']['structuredBody']['component'][8]['section']['title'].toString() 
       for each (seg in msg..component) 
       { Lab = ""; 
        Lab =seg['section']['title'].toString(); 
        if (section == "Results") 
       { 
        for each (seg in seg..entry..organizer) 
       { 

         Lab+= seg ['code']['@code'].toString()+"|"+ //LOINC code 
         seg ['code']['@displayName'].toString()+"|"+//actText 
         seg ['effectiveTime']['@value'].toString();//collection timestamp 

          } 
         } 
       } for each (seg in msg..component) 
       { 
        section = ""; 
        section =seg['section']['title'].toString(); 
        if (section == "Results") 

       { 
        for each (seg in seg..entry..organizer..component) 
       { 

         file+=header+"|"+Lab+"|"+ 
         seg ['observation']['code']['@code'].toString()+"|"+ //LOINC code 
         seg ['observation']['code']['@displayName'].toString()+"|"+//actText 
         seg ['observation']['effectiveTime']['@value'].toString()+"|"+//result timestamp 
         seg ['observation']['value']['@value'].toString()+"|"+//result value 
         seg ['observation']['value']['@unit'].toString()+"|"+//result unit 
         seg ['observation']['interpretationCode']['@code'].toString()+"!!!"+"\r"+"\n";//interpretationCode 

          } 
         } 
       } 

channelMap.put("FILE",file); 

回答

0

'for each'已棄用,請使用'for';

你有2號線(單線評論) 頭=語法錯誤...

的聲明應被分割了幾行

header=msg['recordTarget']['patientRole']['patient']['name']['family'].toString()+"|"+ //last name 
msg['recordTarget']['patientRole']['patient']['name']['given'].toString()+"|"+ //first name 
msg['recordTarget']['patientRole']['patient']['administrativeGenderCode']['@code'].toString()+"|"+ //gender 
msg['recordTarget']['patientRole']['patient']['birthTime']['@value'].toString(); //DOB 
msg['component']['structuredBody']['component'][8]['section']['title'].toString(); 

點點語法僅適用於數文字

556..toString()==="556" 

全部替換..通過。 (單點)

在第一個循環段中永遠不會改變它的初始值「」; section ==「結果」始終爲false,其後續分支從不執行。

你使用xml到json解析器嗎? 我不相信,侯需要調用toString() 投自動完成(字符串+東西被解釋轉化爲字符串+ something.toString())

var file="", 
    header="", 
    Lab="", 
    section=""; 


header=msg['recordTarget']['patientRole']['patient']['name']['family'].toString()+"|"+ //last name 
    msg['recordTarget']['patientRole']['patient']['name']['given'].toString()+"|"+ //first name 
    msg['recordTarget']['patientRole']['patient']['administrativeGenderCode']['@code'].toString()+"|"+ //gender 
    msg['recordTarget']['patientRole']['patient']['birthTime']['@value'].toString(); //DOB 
    msg['component']['structuredBody']['component'][8]['section']['title'].toString(); 

for(seg in msg.component){ 
    Lab = ""; 
    Lab =seg['section']['title'].toString(); 
    if (section == "Results"){ 
     for(seg in seg .entry .organizer){ 

    Lab+= seg ['code']['@code'].toString()+"|"+ 
     //LOINC code 
     seg ['code']['@displayName'].toString()+"|"+ 
     //actText 
     seg ['effectiveTime']['@value'].toString(); 
     //collection timestamp 

    } 
    } 
} 

for(seg in msg.component){ 
    section = ""; 
    section =seg['section']['title'].toString(); 
    if (section == "Results"){ 
    for(seg in seg.entry.organizer.component){ 
    file+=header+"|"+Lab+"|"+ 
    seg ['observation']['code']['@code'].toString()+"|"+ 
     //LOINC code 
    seg ['observation']['code']['@displayName'].toString()+"|"+ 
     //actText 
    seg ['observation']['effectiveTime']['@value'].toString()+"|"+ 
     //result timestamp 
    seg ['observation']['value']['@value'].toString()+"|"+ 
     //result value 
    seg ['observation']['value']['@unit'].toString()+"|"+ 
     //result unit 
    seg ['observation']['interpretationCode']['@code'].toString()+"!!!"+"\r"+"\n"; 
     //interpretationCode 
    } 
    } 
} 

channelMap.put("FILE",file); 
+0

謝謝 - 頁眉和實際節完美地完成了它的實驗室循環 - 它正在挑選結果之後的「護理計劃」的「標題」,這是我不理解的部分。我不使用xml來使用Json解析器,而是使用Mirth中的消息樹解析器 –