Dienstag, 28. Januar 2014

A neat end for our first MPL

Hello back again!

The second post is right incoming ;)
The last post ended with a question to you. What should we do in the If-Clause?
Well principially it is up to you. But we wanted to check if our OCR-device send us the right date, therefor we should ask the user what is the right thing at the moment.

So how to ask something? In MOLIS we have several possibilities to display messages onto the screen. The first is the function askparam() in which we could ask the value of anything we want. Like a date or the value of an analysis or the weigth of the patient... The other ist askmess(), which we will use in this problem.
The function askparam() uses two inputs. The first ist the question and the second are the possible answers. In return, the function delivers the number of the choosen answer.
Therefor we should built our next codefragment like this:
$answer=("Which date should be used?","Today,%%sample_dt.ORD%%%,Other Date")
Wait! What are these cryptical things in the second answer choice?
When we want to display the value of a field we have access to, we use this description %%fieldname%%%. If we want to connet the value of to fields we use %%field1%%field2%%%.

Now we have to interpret the vaule of our $answer variable. This will be fullfilled by three If-clauses.

if($answer#=1)
    $date=ldate_now()
endif

if($answer#=2)
    $date=sample_dt.ORD
endif

if($answer#=3)
    $date=askparam("Please enter the date:")
endif

As you can see we use the first described possibility for letting the user type in the prefered date.
The ldate_now() function returns the actual date. So now we have nearly everything to complete our first MPL program.
At the end we want to write the newly selected date back into the sample_dt.ORD field.
Therefor the whole code should look like this:

if ((ldate(recept_dt.ORD,"D2")-ldate(sample_dt.ORD,"D2"))#>X)
    $answer=("Which date should be used?","Today,%%sample_dt.ORD%%%,Other Date")
    if($answer#=1)
        $date=ldate_now()
    endif

    if($answer#=2)
        $date=sample_dt.ORD
    endif
   
    if($answer#=3)
        $date=askparam("Please enter the date:")
    endif
    sample_dt.ORD=$date
endif

At the end of this post I will show you one last useful code fragment. No matter how good you write your MPL code, the day will come that you make a mistake. That's normal and okay but you don't want to build those failures into your live system.
To decrease the harms of a mistake you can put all of your newly MPL code in this If-clause:

if($42="XXX")
    everything you code
endif

XXX stand for your short username. In the number register $42 the actual short user name is saved. Therefor every change made will only affect you and no one else.

If you got ideas, problems or feedback in any other form, dont hesitate an post it in the comments!
Because I dont think I will read the mails of this account often...
In the next post we will learn the differenz between DT.-1 and sample_dt.-1, it will be fun to know!!! :D

Keine Kommentare:

Kommentar veröffentlichen