doc_jay
asked on
LUA calander function to calculate date range from 'X' number of days old.
Hi,
I need some help with LUA please. I hope that this is a good place to post this.
I am running the following lua script to generate a .txt file.
What I need help with is simplifying this so that I won't have to edit it every time I need to run it. And that would include the date range 'a.StudyDate='19000101-200 70714''. I need to have a date range here as this script uses it. Is there a function that lua can do to calculate the date range for me if I say, show me everything that is '2190' days old and older? I have been using the beginning date of '19000101' because I knew that I would not have anything that old. Also, the date format above needs to stay as 'yearmonthday'.
thank you!!
I need some help with LUA please. I hope that this is a good place to post this.
I am running the following lua script to generate a .txt file.
a=DicomObject:new()
a.QueryRetrieveLevel='STUDY'
a.StudyInstanceUID=''
--a.PatientName='*test*'
--a.AccessionNumber='123456'
a.StudyDate='19000101-20070714'
a.PatientBirthDate = '19000101-19920714'
a.ModalitiesInStudy = ''
b=dicomquery('ARCH', 'STUDY', a)
f=io.open('suid.txt', 'wt')
for i=0, #b-1 do
if string.find(b[i].ModalitiesInStudy, 'MG')==nil then
f:write(b[i].StudyInstanceUID .. '\n')
end
end
What I need help with is simplifying this so that I won't have to edit it every time I need to run it. And that would include the date range 'a.StudyDate='19000101-200
thank you!!
ASKER
Aikimark,
thanks for the reply. I d/l the date library from the github link. I really don't know how to write lua as the code I have I have pieced together from others helping me out. I'll look at the examples from your last link and see if I can have any luck.
Thanks again
thanks for the reply. I d/l the date library from the github link. I really don't know how to write lua as the code I have I have pieced together from others helping me out. I'll look at the examples from your last link and see if I can have any luck.
Thanks again
Generally, I advise people to normalize their data. In the case of your date ranges, I would have two data elements (begin date, end date) rather than the delimited string you are currently using.
Example:
Example:
a.StudyDateStart='19000101'
a.StudyDateEnd='20070714'
a.PatientBirthDateStart = '19000101'
a.PatientBirthDateEnd = '19920714'
Like you, I am still learning lua.
ASKER
Okay - so I have this code now that works:
and it is displayed how I need it. This displays the output at this time as:
...I just need now for each line to be placed inside single quotes like:
or else my script won't complete correctly.
days = 2192
startdate = os.date(19000101)
enddate = os.date('%Y%m%d', os.time()-days*24*3600)
print (startdate .. '-' .. enddate)
days = 7670
startDOB = os.date(19000101)
endDOB = os.date('%Y%m%d', os.time()-days*24*3600)
print (startDOB .. '-' .. endDOB)
and it is displayed how I need it. This displays the output at this time as:
19000101-20070717
19000101-19920717
...I just need now for each line to be placed inside single quotes like:
'19000101-20070717'
'19000101-19920717'
or else my script won't complete correctly.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
https://github.com/LuaDist/luadate
http://lua-users.org/lists/lua-l/2005-08/msg00694.html
According to the lua date calculation examples in the following link, you might just be able to subtract a number of days from a date. Once that is done, you would need to format the dates back into the string ranges you are using.
http://scilua.org/time.html