Question
Yone Moreno · 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
 

00
3 0 4 148
Log in or sign up to continue

I have no idea, what is the date format of PID 7.1, but I'm sure, you can convert this date to $h format, so the answer to your question is

set age = $h - $zdh(PID7.1Date,?) \ 365.25

now <age> contains the patients age in full years

Hi, Yone

Did you notice in command "w $system.SQL.DATEADD("yy",65,"1976-22-04")"
The Date is in format "YYYY-DD-MM"
The correct must by in format "YYYY-MM-DD"
The command "w $system.SQL.DATEADD("yy",65,"1976-04-22")" results "2041-04-22 00:00:00"

The command "w $system.SQL.DATEADD("yy",65,"19760422") " result in error, must contain the separator"-".

Hi Yone,

I would personally go for something like this:-

if $zd($system.SQL.DATEADD("yy",65,nacimientoFormateado),3)<+$h write "younger than 65"

if $zd($system.SQL.DATEADD("yy",65,nacimientoFormateado),3)>=+$h write "65 or older"

Assuming that nacimientoFormateadois in an ODBC format i.e. 2021-06-22

Hope that helps.

Property cAge As %String(TRUNCATE = 1) [ Calculated, SqlComputeCode = {set {cAge}=0 if {dDateOfBirth}>0 set {cAge}=$ZD($H,8)-$zd({dDateOfBirth},8)\10000 }, SqlComputed ];

This code turns my date of birth (+$h style ) into age

I use to find the age of animals in my competitions. as they return year on year. but the Date of birth is constant.