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
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Basic Tasks ==
 
== Basic Tasks ==
 +
 +
* common tasks (e.g. search a list for a specific value etc.)
 +
* small snippets of MLM code on how to solve specific problems
 +
* [[Arden_Syntax:Implementation_Guide:MLM_to_MLM_interaction| MLM to MLM interaction]] (call sub MLM, import MLM)
 +
* create complex knowledge bases with MLMs
 +
  
 
=== Sort a List of Objects ===
 
=== Sort a List of Objects ===
Line 41: Line 47:
 
     resGuid3 := new guidResult with true, 23, "The patient is in compliance with the guideline.";
 
     resGuid3 := new guidResult with true, 23, "The patient is in compliance with the guideline.";
 
     result_list := result_list, resGuid3;
 
     result_list := result_list, resGuid3;
 
+
 
     // sorting the result
+
     /* sorting the result */
 
     sorted_list := ();
 
     sorted_list := ();
 
     for en in result_list do
 
     for en in result_list do
Line 69: Line 75:
 
           inserted := true;
 
           inserted := true;
 
         endif;
 
         endif;
 
 
         n := n +1;
 
         n := n +1;
 
       enddo;
 
       enddo;
Line 80: Line 85:
 
   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;
 +
       
 +
        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
 +
 +
=== calculate the current age in years from a given birthday ===
 +
Given the date of birth, the age in years can be calculated by the following expression
 +
 +
        Age_duration := currenttime - DOB;
 +
        Age_yrs := Age_duration/1 year;
 +
 +
=== MLM to MLM interaction ===
 +
 +
[[Arden_Syntax:Implementation_Guide:MLM_to_MLM_interaction| MLM to MLM interaction]] (call sub MLM, import MLM)

Latest revision as of 22:31, 15 November 2013

Basic Tasks

  • common tasks (e.g. search a list for a specific value etc.)
  • small snippets of MLM code on how to solve specific problems
  • MLM to MLM interaction (call sub MLM, import MLM)
  • create complex knowledge bases with MLMs


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;
       
       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

calculate the current age in years from a given birthday

Given the date of birth, the age in years can be calculated by the following expression

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

MLM to MLM interaction

MLM to MLM interaction (call sub MLM, import MLM)