Announcement

Collapse
No announcement yet.

Object array pushing only last value 11 time even if we pass correct values .

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Object array pushing only last value 11 time even if we pass correct values .

    Hello Dears,

    I am sure some thing wrong on my script . After checking condition required data are pushing to object array 11 times. While it display object array value it display 11 times as expected . But , I think it push 11 times last content 11 times . Logically it corrects data are pushing wrong . Not sure where should modify ..

    I am sure it push correct data only to function . Some body give best advice on it
    --------------------------- This is my code ---------------------------------------------------

    var MsgType=msg['MSH']['MSH.9']['MSH.9.1'].toString();
    $c('MessageControlId',msg['MSH']['MSH.10']['MSH.10.1'].toString());
    $c('MsgType',MsgType);
    var field1,field3,word,ObservationId,Send,UnitsIdent,O bserVal;
    var Code;
    $c('observations',[]);
    var observation = {};
    if(MsgType=="ORU")
    {
    $c('PatientId',msg['PID']['PID.3']['PID.3.1'].toString());
    $c('PatientVisitId',msg['PV1']['PV1.1']['PV1.1.1'].toString());

    //var sql="select M.lookup_value AS VITALS_ID, M.FIELD2 AS MACHINE_VITALS,UPPER(M.FIELD3) AS MACHINE_UNIT,V.lookup_value AS VITALS,V.FIELD1 AS VITALS_UNIT from emr_lookup M JOIN emr_lookup V ON M.lookup_value = V.emr_lookup_id where M.lookup_type = 'VITAL SIGNS HL7 CHANNEL MAPPING' AND V.lookup_type='VITAL SIGNS' AND M.ISVALID=1 AND V.ISVALID=1 AND M.FIELD1='1' order by 1 desc";
    //var gen_lookup= Fun_Select(sql);

    for each (obx in msg.OBX)
    {
    try
    {
    ObservationId= obx['OBX.3']['OBX.3.1'].toString();
    Code=ObservationId;
    Send=obx['OBX.3']['OBX.3.1'].toString();
    UnitsIdent= obx['OBX.6']['OBX.6.1'].toString();
    ObserVal = obx['OBX.5']['OBX.5.1'].toString();
    field1=PreparData(Code,Send,UnitsIdent,ObserVal);
    }
    catch(e)
    {
    logger.info(" OBX processing"+e);
    }
    }

    $c('observations',JSON.stringify($c('observations' )));

    for each (observation in JSON.parse($('observations')))
    {
    logger.info("observation.Id="+observation.Id +"observation.ObservationValue="+observation.Obser vationValue+"observation.UnitsIdentifier="+observa tion.UnitsIdentifier+"observation.send="+observati on.send+"observation.Refid="+observation.Refid);
    }

    }

    function PreparData(Code,Send,UnitsIdent,ObserVal)
    {
    var temp;
    try
    {
    var value1,value2,value3,field2;
    var sql="select M.lookup_value AS VITALS_ID, M.FIELD2 AS MACHINE_VITALS,UPPER(M.FIELD3) AS MACHINE_UNIT,V.lookup_value AS VITALS,V.FIELD1 AS VITALS_UNIT from emr_lookup M JOIN emr_lookup V ON M.lookup_value = V.emr_lookup_id where M.lookup_type = 'VITAL SIGNS HL7 CHANNEL MAPPING' AND V.lookup_type='VITAL SIGNS' AND M.ISVALID=1 AND V.ISVALID=1 AND M.FIELD1='1' order by 1 desc";
    var gen_lookup= Fun_Select(sql);
    while(gen_lookup.next())
    {
    value1=gen_lookup.getString('MACHINE_VITALS');
    value2=gen_lookup.getString('VITALS');
    field2=gen_lookup.getString('VITALS_UNIT');
    field3=gen_lookup.getString('VITALS_ID');
    if(value1==Code)
    {
    observation.Id =value2;
    observation.send=Send;
    observation.UnitsIdentifier=field2;
    observation.Refid=field3;
    observation.ObservationValue=ObserVal;
    $c('observations').push(observation)
    AddToArray(value2,Send,field2,field3,ObserVal);
    // logger.debug("value2="+value2+"Send="+Send+"field2 ="+field2+"field3="+field3+"ObserVal="+ObserVal )
    }
    }

    return "True";
    }
    catch(e)
    {
    logger.info("PreparData"+e);
    }

    }









    Pushed value --- Only value pushed 11 times
    -----------------------------------------------
    transformer: value2=BP: SystolicSend=150021field2=Mm/hpfield3=26ObserVal=100
    transformer: value2=BP: DiastolicSend=150022field2=Mm/hpfield3=32ObserVal=50
    transformer: value2=TemperatureSend=150344field2=°Cfield3=24Obs erVal=36.9683
    transformer: value2=Pulse(Toddler)Send=150456field2=Beats/Minfield3=632442ObserVal=99
    transformer: value2=Pulse(School-age)Send=150456field2=Beats/Minfield3=632440ObserVal=99
    transformer: value2=Pulse(Preschool)Send=150456field2=Beats/Minfield3=632438ObserVal=99
    transformer: value2=Pulse(Neonatal)Send=150456field2=Beats/Minfield3=632436ObserVal=99
    transformer: value2=Pulse(Infants)Send=150456field2=Beats/Minfield3=632434ObserVal=99
    transformer: value2=PulseSend=150456field2=Beats/Minfield3=31ObserVal=99
    transformer: value2=WeightSend=68063field2=kgfield3=23ObserVal= 68
    transformer: value2=HeightSend=68060field2=cmfield3=30ObserVal= 177.8
    -----------------------------------------------------------------------------
    Displayed values --------------

    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    < pool-1-thread-198] transformer: observation.Id=Heightobservation.ObservationValue= 177.8observation.UnitsIdentifier=cmobservation.sen d=68060observation.Refid=30
    --------------------------------------------

  • #2
    Hi,

    Short solution to your problem, add below line of code after the if logic inside your wile loop

    observation = {};


    after adding changes your code will look like
    if (value1 == Code) {
    observation = {};
    observation.Id = value2;

    ************************************************** ************************************************** **********************
    if you want to experiment more, here is a piece of code for more experimentation:

    var observation = {};
    $c('observations', []);

    observation.Id = 1;
    observation.send = 'a';
    $c('observations').push(observation)
    logger.info(JSON.stringify(($c('observations'))));

    //In below line i am clearing the content of variable observation
    //run this code and then comment out below line of code and run it you will see the difference
    observation = {};

    observation.Id = 2;
    observation.send = 'b';
    $c('observations').push(observation)
    logger.info(JSON.stringify(($c('observations'))));

    for each(observation in $('observations')) {
    logger.info("observation.Id= " + observation.Id + " observation.send= " + observation.send );
    }

    Comment


    • #3
      It works well !!!

      Thank you so much for helping me .I coludn't have done it with you to .

      Comment

      Working...
      X