문제

I am working on Lua and I have this kind of code

MapMessage(Process["ks.MSH"][1], MsgIn, mg)
MapEvent(Process["ks.EVN"][1], MsgIn, mg)
MapPatient(Process["ks.PID"][1], MsgIn, mg)
MapVisit(Process["ks.PV1"][1],MsgIn,mg)

In above statements, MapMessage, MapEvent, MapPatient, MapVisit are the functions and ks.MSH, ks.EVN, ks.PID, ks.PV1 are the tables in the database. Now, I want to automate a part of this process using gmatch function provided in lua and I have this so far

for u in string.gmatch(S, "([^,%s]+)"), 1 do
     l[k] = u 
    _G["Map"..l[k]](Process["ks[l[k]]"][1], R[1])
     k=k+1
   end 

but the concatenation part in the third line of above code is not really making it ks.MSH, ks.PID, ks.PV1 e.t.c, so please suggest what needs to be there in place of (Process["ks[l[k]]"][1]to get s.MSH, ks.PID, ks.PV1 e.t.c

도움이 되었습니까?

해결책

Since your string contains "MSH, PID, PV1, EVN", you'd have to use a hash-table or a lookup table. The program would be something like this:

S = "MSH, PID, PV1, EVN"
tLookup = {
    MSH = "Message",
    EVN = "Event",
    PID = "Patient",
    PV1 = "Visit",
}

for u in S:gmatch "([^,%s]+)" do
    sNameOfFunction = tLoopup[u]
    _G[ "Map"..sNameOfFunction ] ( Process["ks."..u][1], MsgIn, mg )
     k=k+1
end

Or even something like this:

S = "MSH, PID, PV1, EVN"
tLookup = {
    MSH = _G.MapMessage,
    EVN = _G.MapEvent,
    PID = _G.MapPatient,
    PV1 = _G.MapVisit,
}

for u in S:gmatch "([^,%s]+)" do
    tLoopup[u] ( Process["ks."..u][1], MsgIn, mg )
    k = k+1
end

다른 팁

Here is what finally worked, thanks Egor and hjpotter92 :)

ks = {MSH = "ks.MSH", EVN = "ks.EVN", PID = "ks.PID", PV1 = "ks.PV1", PV2 = "ks.PV2"}
S = tostring(R[1].AllSegmentsList)
 l = {}
k = 1
for u in string.gmatch(S, "([^,%s]+)") do
 l[k] = u 
 _G["Map"..l[k]](Process[ks[l[k]]][1], MsgIn, mg)
   k=k+1
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top