Question
· Mar 26, 2020

Merge two lists?

Hello,

 

We are developing a method to take two messages which have a list of data types. It is being defined as:

 

Class Mensajes.Response.HistoriaClinica.ConsultaCitasResponse Extends Ens.Response [ ProcedureBlock ]
{

Property informacion As EsquemasDatos.HistoriaClinica.Informacion;

Property datos As list Of EsquemasDatos.HistoriaClinica.ConsultaCitas;

Property error As EsquemasDatos.HistoriaClinica.Error;

}

 

Inside datos we have:

Class EsquemasDatos.HistoriaClinica.ConsultaCitas Extends (%Persistent, %XML.Adaptor) [ ProcedureBlock ]
{

Property fecha As %String(MAXLEN = ""); Property hora As %String(MAXLEN = "");

Property ubicacion As %String(MAXLEN = ""); Property centro As %String(MAXLEN = "");

Property modoCita As %String(MAXLEN = ""); Property telefono As %String(MAXLEN = "");

Property servicio As %String(MAXLEN = ""); Property origen As %String(MAXLEN = "");

Property especialidad As %String(MAXLEN = "");

Property nombreMedico As %String(MAXLEN = "");

Property borrable As %String(MAXLEN = "");

}

 

We have two different messages with the structure we have shown you. We would need to return just a message which its datos list being the merge of the two initial's message's datos lists. To explain with further detail the use case, we have a Process where we are calling this ClassMethod.

 

We have thought it could be written as:

 

ClassMethod unirCitas(citasPrimarias As Mensajes.Response.HistoriaClinica.ConsultaCitasResponse, citasEspecializadas As Mensajes.Response.HistoriaClinica.ConsultaCitasResponse) As %ListOfObjects(ELEMENTTYPE="EsquemasDatos.HistoriaClinica.ConsultaCitas")
{
//Method merge two lists
  do citasPrimarias.datos.InsertList(citasEspecializadas.datos)
quit citasPrimarias
}

 

However it is incorrect because of when we put a $$$LOGINFO before being called in the process, it is being printed, however when we put it after calling it, it is not being printed.

 

In addition, we are writting this new ClassMethod inside a class which extends %Persistent, so when we try to debug it with $$$LOGINFO it says the following:

MPP5610 : Referenced macro not defined: 'LOGINFO'
 TEXT: $$$LOGINFO(citasPrimarias)

 

How could we debug this?

 

We have read:

 

 

EDIT:

 

We have also tried to insert the contents of the second list into the first list as follows:

 

ClassMethod unirCitas(citasPrimarias As Mensajes.Response.HistoriaClinica.ConsultaCitasResponse, citasEspecializadas As Mensajes.Response.HistoriaClinica.ConsultaCitasResponse) As %ListOfObjects(ELEMENTTYPE="EsquemasDatos.HistoriaClinica.ConsultaCitas")
{

for i=1:1:citasEspecializadas.datos.Size{

 set ^content=citasEspecializadas.datos.GetAt(i)
 do citasPrimarias.datos.Insert(^content)
 set ^numeroCitasPrimarias=citasPrimarias.datos.Size
} 
for j=1:1:citasPrimarias.datos.Size{
 set ^j=j
} 
quit citasPrimarias
}

 

However if we log the previous globals, we observe that the citasPrimarias.datos is still having the same size (3) so then the citasEspecializadas contents are not being inserted.

 

We log the previous information with:


  $$$LOGINFO("citasEspecializadas: "_^i)
 
  $$$LOGINFO("^numeroCitasPrimarias after insert: "_^numeroCitasPrimarias)
 
 
  $$$LOGINFO("^content: "_^content)
  $$$LOGINFO("^citasPrimarias end size: "_^j)  

 

And we see the following:

(we start with citasEspecializadas.Size=2 and citasPrimarias.Size=3)

  citasEspecializadas: 2

 

^numeroCitasPrimarias after insert: 3
 
 
 
  ^citasPrimarias end size: 3
 

  How could we improve this and merge the two lists?

 

Besides if we try to create a new list, as a ListOfObjects:

 

ClassMethod unirCitas(citasPrimarias As Mensajes.Response.HistoriaClinica.ConsultaCitasResponse, citasEspecializadas As Mensajes.Response.HistoriaClinica.ConsultaCitasResponse) As %ListOfObjects(ELEMENTTYPE="EsquemasDatos.HistoriaClinica.ConsultaCitas")
{

set ^newList = ##class(%ListOfObjects).%New()

 


for i=1:1:citasEspecializadas.datos.Size{

set ^content=citasEspecializadas.datos.GetAt(i)
do ^newList.Insert(^content)

...


}

 

If we run the previous code, it does not execute, because of the line:

do ^newList.Insert(citasPrimarias.datos.GetAt(i))

Makes it crash.

 

However if we comment out the Insert, and we use a $$$LOGINFO, as follows:

$$$LOGINFO("^newList: "_^newList)

 

It outputs:
^newList: 20@%Library.ListOfObjects  

 

How could we merge two lists?

 

 

 

EDIT2:

 

Besides we have tried to create a new message which has inside a new list of objects of the element type needed. Then we loop for each of the two lists and insert their contents into the list as follows:

ClassMethod unirCitas(citasPrimarias As Mensajes.Response.HistoriaClinica.ConsultaCitasResponse, citasEspecializadas As Mensajes.Response.HistoriaClinica.ConsultaCitasResponse) As Mensajes.Response.HistoriaClinica.ConsultaCitasResponse
{

set listaCitas = ##class(Mensajes.Response.HistoriaClinica.ConsultaCitasResponse).%New()
set listaCitas.datos = ##class(%ListOfObjects).%New()
set listaCitas.datos.ElementType = "EsquemasDatos.HistoriaClinica.ConsultaCitas"

for j=1:1:citasPrimarias.datos.Size{
 set ^content=citasPrimarias.datos.GetAt(j)
 do listaCitas.datos.Insert(citasPrimarias.datos.GetAt(j))
}

for i=1:1:citasEspecializadas.datos.Size{
 set ^content=citasEspecializadas.datos.GetAt(i)
 do listaCitas.datos.Insert(citasEspecializadas.datos.GetAt(i))
}

set ^listaCitasEndSize=listaCitas.datos.Size /*

quit listaCitas
}

 

Now it does work, because of we have discovered that if we Insert(^content) it does not work, but if we do Insert(citasPrimarias.datos.GetAt(j)) it does update the list.

 

We wonder, why?

Discussion (1)2
Log in or sign up to continue