This wiki has undergone a migration to Confluence found Here
<meta name="googlebot" content="noindex">

Difference between revisions of "Arden Syntax:Implementation Guide:Basic Tasks"

From HL7Wiki
Jump to navigation Jump to search
Line 79: Line 79:
 
   urgency:    ;;
 
   urgency:    ;;
 
  end:
 
  end:
 +
 +
=== Convert String to DateTime ===
 +
In former versions it was not possible to simply convert a String into a DateTime, the following MLM contains the logic to make this conversion.
 +
 +
maintenance:
 +
  title:      convert_stringdate_to_datetime;
 +
  mlmname:    convert_stringdate_to_datetime;;
 +
  arden:      Version 2.5;;
 +
  version:    1.0;;
 +
  institution: Medexter Healthcare;;
 +
  author:      Karsten Fehre;;
 +
  specialist:  ;;
 +
  date:        2013-11-13;;
 +
  validation:  testing;;
 +
library:
 +
  purpose:    ;;
 +
  explanation: ;;
 +
  keywords:    ;;
 +
  citations:  ;;
 +
  links:      ;;
 +
knowledge:
 +
  type:   data_driven;;
 +
  data:       
 +
DOB_str := argument;
 +
  ;;
 +
  priority:    ;;
 +
  evoke:      ;;
 +
  logic:
 +
/* for example DOB_str := "1973-11-02T12:34:56"; */
 +
 +
year_str := SUBSTRING 4 CHARACTERS FROM DOB_str; 
 +
month_str := SUBSTRING 2 CHARACTERS STARTING AT 6 FROM DOB_str; 
 +
day_str := SUBSTRING 2 CHARACTERS STARTING AT 9 FROM DOB_str; 
 +
hour_str := SUBSTRING 2 CHARACTERS STARTING AT 12 FROM DOB_str; 
 +
minute_str := SUBSTRING 2 CHARACTERS STARTING AT 15 FROM DOB_str; 
 +
second_str := SUBSTRING 2 CHARACTERS STARTING AT 18 FROM DOB_str;
 +
 +
startDate := 1800-01-01T00:00:00;
 +
 +
DOB := startDate + (year_str as number) years - 1800 years; 
 +
DOB := DOB + (month_str as number) months - 1 month; 
 +
DOB := DOB + (day_str as number) days - 1 day; 
 +
DOB := DOB + (hour_str as number) hours; 
 +
DOB := DOB + (minute_str as number) minutes; 
 +
DOB := DOB + (second_str as number) seconds;
 +
 +
Age_duration := currenttime - DOB;
 +
Age_yrs := Age_duration/1 year;
 +
conclude true;
 +
  ;;
 +
  action:
 +
    return DOB;
 +
  ;;
 +
  urgency:    ;;
 +
end:
 +
 +
Since Arden Syntax version 2.8 this whole conversion can be done by the simple line:
 +
 +
DOB := "1973-11-02T12:34:56" AS TIME

Revision as of 22:23, 15 November 2013

Basic Tasks

Sort a List of Objects

maintenance:
 title:       sample_sort_objects;;
 mlmname:     sample_sort_objects;;
 arden:       Version 2.9;;
 version:     1.0;;
 institution: Medexter Healthcare;;
 author:      Karsten Fehre;;
 specialist:  ;;
 date:        2013-11-13;;
 validation:  testing;;
library:
 purpose:     ;;
 explanation: ;;
 keywords:    ;;
 citations:   ;;
 links:       ;;
knowledge:
 type:		   data_driven;;
 data:        
   guidResult := object [      // result object: result of guidline query
       compliance,             // the compliance of the patient to a guidline
       eOfIntervention,        // the "ease of intervention" 
       text];                  // the text
 ;;
 priority:    ;;
 evoke:       ;;
 logic:

   result_list := ();
   
   resGuid1 := new guidResult with false, 12, "The patient is not in compliance with the guideline.";	
   result_list := result_list, resGuid1;
    
   resGuid2 := new guidResult with true, 70, "The patient is in compliance with the guideline.";	
   result_list := result_list, resGuid2;
 	
   resGuid3 := new guidResult with true, 23, "The patient is in compliance with the guideline.";	
   result_list := result_list, resGuid3;
  
   /* sorting the result */
   sorted_list := ();
   for en in result_list do
     inserted := false;
     n := 1;
     list_size := count sorted_list;
     mylist := mylist, list_size;
     while not inserted do
       if list_size = 0 then
         sorted_list := sorted_list, en;
         inserted := true;
       elseif n <= list_size then
         el := sorted_list[n];
         if ((el.compliance = false) and (en.compliance = false)) and (el.eOfIntervention > en.eOfIntervention) then
           sorted_list := sorted_list[1 seqto (n-1)], en, sorted_list[n seqto list_size];
           inserted := true;
         elseif (el.compliance = true) and (en.compliance = false) then
           sorted_list := sorted_list[1 seqto (n-1)], en, sorted_list[n seqto list_size];
           inserted := true;
         elseif ((el.compliance = true) and (en.compliance = true)) and (el.eOfIntervention > en.eOfIntervention) then
           sorted_list := sorted_list[1 seqto (n-1)], en, sorted_list[n seqto list_size];
           inserted := true;
         endif;
       else 
         sorted_list := sorted_list, en;
         inserted := true;
       endif;
       n := n +1;
     enddo;
   enddo;
 conclude true; 
 ;;
 action:	 
   return sorted_list;
 ;;
 urgency:     ;;
end:

Convert String to DateTime

In former versions it was not possible to simply convert a String into a DateTime, the following MLM contains the logic to make this conversion.

maintenance:
 title:       convert_stringdate_to_datetime;
 mlmname:     convert_stringdate_to_datetime;;
 arden:       Version 2.5;;
 version:     1.0;;
 institution: Medexter Healthcare;;
 author:      Karsten Fehre;;
 specialist:  ;;
 date:        2013-11-13;;
 validation:  testing;;
library:
 purpose:     ;;
 explanation: ;;
 keywords:    ;;
 citations:   ;;
 links:       ;;
knowledge:
 type:		   data_driven;;
 data:        

DOB_str := argument;

 ;;
 priority:    ;;
 evoke:       ;;
 logic:

/* for example DOB_str := "1973-11-02T12:34:56"; */

year_str := SUBSTRING 4 CHARACTERS FROM DOB_str; month_str := SUBSTRING 2 CHARACTERS STARTING AT 6 FROM DOB_str; day_str := SUBSTRING 2 CHARACTERS STARTING AT 9 FROM DOB_str; hour_str := SUBSTRING 2 CHARACTERS STARTING AT 12 FROM DOB_str; minute_str := SUBSTRING 2 CHARACTERS STARTING AT 15 FROM DOB_str; second_str := SUBSTRING 2 CHARACTERS STARTING AT 18 FROM DOB_str;

startDate := 1800-01-01T00:00:00;

DOB := startDate + (year_str as number) years - 1800 years; DOB := DOB + (month_str as number) months - 1 month; DOB := DOB + (day_str as number) days - 1 day; DOB := DOB + (hour_str as number) hours; DOB := DOB + (minute_str as number) minutes; DOB := DOB + (second_str as number) seconds;

Age_duration := currenttime - DOB; Age_yrs := Age_duration/1 year; conclude true;

 ;;
 action:	 
   return DOB;
 ;;
 urgency:     ;;
end:

Since Arden Syntax version 2.8 this whole conversion can be done by the simple line:

DOB := "1973-11-02T12:34:56" AS TIME