2016-10-01 147 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中的消息树解析器 –