2 Replies Latest reply: Aug 27, 2013 9:45 AM by Jamie Hicks RSS

    Expressor Datascript help

    Jamie Hicks

      I'm trying to replicate this SQL functionality with datascript:

       

      CASE WHEN (RMP.Major_Payor_Group_Code IN ('206','366','923','280','281','282','283','284','285','286','287','288','289','290','291','292','299','303','374','555','787','820','980')) THEN 'Y' ELSE 'N' END

       

      I don't want to have to write a nested IF statement or write multiple 'or' clauses for each value. I thought it would be easier to declare each value in a table, then use one IF statement to return the 'Y' or 'N' flag.

       

      Here is the datascript that I have. The only problem is that it returns a 'Y' for the first value in the table (206) only. All others are returned with a 'N'. I need the process to read through the entire table to look for a match for each input value.

       

      function initialize()

       

        BUCA = {'206','366','923','280','281','282','283','284','285','286','287','288','289','290','291','292','299','303','374','555','787','820','980'}

       

      end;

       

      function transform(input)

       

        output = {}

       

        for index, value in ipairs(BUCA) do

        if input.Major_Payor_Group_Code==value then BUCAIND = 'Y'

        else

        BUCAIND = 'N'

        end

       

       

        output.BUCAIND = BUCAIND

       

       

        return output;

       

       

      end

      end;

        • Re: Expressor Datascript help
          Juan Gerardo Cabeza Luque

          To use this approach, I would suggest reviewing the code. There are a couple of mistakes:

           

          function initialize()

           

            BUCA = {'206','366','923','280','281','282','283','284','285','286','287','288','289','290','291','292','299','303','374','555','787','820','980'}

          end;

           

          function transform(input)

           

            output = {}

            output.BUCAIND = 'N'

           

            for index, value in ipairs(BUCA) do

                 if input.Major_Payor_Group_Code == value then

                      output.BUCAIND = 'Y'

                      break -- Found, then you must exit the loop and stop comparing

                 end

            end

           

            return output;

           

          end;