Question
· Jun 21, 2021

How could we check if birth date from PID 7.1 is below 65 years old?

Hello,

First of all thanks for your time reading our question, and thanks for your replies and help

 

We would need to know if a patient has less than 65 years old, using their birthday from the PID 7.1

 

So far we have developed the following code:

 

 //19760422 
  set nacimiento             = request.GetValueAt("PID:DateTimeofBirth.Time")
  $$$LOGINFO("nacimiento: "_nacimiento)


  //22/04/1976
  set nacimientoFormateado   = ##class(Util.FuncionesComunes).DateFormatConvertToXML(nacimiento)


  // ""
  set nacimientoFormateado65 = $extract($system.SQL.DATEADD("yy",65,nacimientoFormateado),1,10)
  // 2021-06-21
  set hoy = $zdate($h,3)


  $$$LOGINFO(nacimientoFormateado_" - "_nacimientoFormateado65_" - "_hoy)


  if (hoy<nacimientoFormateado65){
     $$$LOGINFO("hoy: "_hoy)
     $$$LOGINFO("nacimientoFormateado65: "_nacimientoFormateado65)
     set edad = "1"
  }

 

We observe that when PID 7.1 = 19760422 , the line:

$$$LOGINFO(nacimientoFormateado_" - "_nacimientoFormateado65_" - "_hoy)

 

Prints:

22/04/1976 - - 2021-06-21

 

And it does not enters in the if, so then it is not being detected has younger than 65 years old

 

How would you recommend to approach this task in a logical and correct way?

How would you continue?

How could we check if birth date from PID 7.1 is below 65 years old? 💭💭💭

 

➡️ Thanks for your help, time and replies

 

We think that the challenge could be in the following line of code:

set nacimientoFormateado65 = $extract($system.SQL.DATEADD("yy",65,nacimientoFormateado),1,10)

Because it outputs nothing:

 

Also we have tried to debug what date format expects the DATEADD as third parameter, as follows:

w $system.SQL.DATEADD("yy",65,"1976-22-04")

w $system.SQL.DATEADD("yy",65,"1976-22-04") - Error <ILLEGAL VALUE>
w $system.SQL.DATEADD("yy",65,'1976-22-04')

w $system.SQL.DATEADD("yy",65,'1976-22-04') - Error <SYNTAX>
w $system.SQL.DATEADD("yy",65,"1976-22-04")

w $system.SQL.DATEADD("yy",65,"1976-22-04") - Error <ILLEGAL VALUE>

 

 

How would you suggest to continue this task?

 

 

We have read: 💭💭

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...

 

Thanks for your help
 

Discussion (4)3
Log in or sign up to continue