-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af0476e
commit 59dd08f
Showing
12 changed files
with
1,428 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Preliminaries | ||
Lexical Elements | ||
Language Constructs | ||
Identifiers | ||
Case-Sensitivity | ||
There are several lexical errors throughout this library. Correct the errors to | ||
obtain a lexically correct library. | ||
*/ | ||
library Exercises01Key | ||
|
||
// # Lexical Errors | ||
|
||
/* | ||
// This is a comment | ||
// Whitespace is all the "invisibles" (spaces, tabs, returns) | ||
*/ // 1) Multi-line comments need a close | ||
// 2) CQL is case-sensitive, so needs to define not DEFINE | ||
define "This is a quoted identifier": // 3) Quoted identifier missing a close quote | ||
@2021-03-29 + 3 days // 4) DateTime literals use ISO date/time format | ||
|
||
define _1MoreIdentifier: // 5) Unquoted identifiers can't begin with numbers | ||
0.0 'g' // 6) decimal (and quantity) literals must have a leading zero | ||
// # Syntax Errors | ||
define "Inequality Expression": // 7) Missing a colon after the define | ||
4 != 5 // 8) Inequality symbol is !=, not <> | ||
define "Relative Comparison Expression": | ||
4 <= 5 // 9) No space between <= operator | ||
define "Quantity Expression": | ||
5 'g/dL' // 10) Units of a quantity are specified with a string | ||
// # Semantic Errors | ||
define "Reference Expression": | ||
"Quantity Expression" // 11) Identifiers are case-sensitive | ||
define "String Concatenation": | ||
'1' + 'John' // 12) Can't add strings and integers | ||
|
||
define "Warning Message": | ||
Message(1, true, '123', 'Warning', 'This is a warning message') | ||
|
||
define "Nested Warning Message": | ||
1 + Message(2, true, '123', 'Warning', 'The value is 2') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
/* | ||
Types and Values | ||
Type Categories (Simple, Structured, Interval, List, Choice) | ||
Simple Types (Boolean, Integer, Decimal, String, Date, DateTime, Time) | ||
Clinical Structured Types (Quantities, Ratios, Codes, Concepts) | ||
Structured Values and Classes | ||
Missing Information | ||
Conversions | ||
Type Testing and Casting | ||
Choice Types | ||
*/ | ||
library Exercises02Key | ||
|
||
define "Boolean True": true | ||
define "Boolean False": false | ||
|
||
/* | ||
Fill in the blanks to make the expressions evaluate to true | ||
*/ | ||
|
||
// # Boolean Values | ||
|
||
define "Boolean Not": | ||
(not true) is false | ||
|
||
define "Boolean And": | ||
(true and false) is false | ||
|
||
define "Boolean Xor": | ||
(true xor false) is true | ||
|
||
// Translator issue [#617](https://github.com/cqframework/clinical_quality_language/issues/617) | ||
define "Boolean Implies": | ||
(false implies true) is true | ||
|
||
// # String Values | ||
|
||
define "Simple String": | ||
'John Doe' | ||
|
||
define "String Escapes": | ||
'John O\'Mally' | ||
|
||
define "String Equality": | ||
('John Doe' = 'john doe') is false | ||
|
||
define "String Comparisons": | ||
('Deer' < 'Doe') is true | ||
|
||
// # Numbers | ||
|
||
define "Integer": | ||
5 | ||
|
||
define "Decimal": | ||
5.0 | ||
|
||
define "Implicit Decimal Conversion": | ||
5 + 5.0 | ||
|
||
define "Decimal Comparison Ignores Precision": | ||
5.0 = 5.00 | ||
|
||
define "Standard Arithmetic Precedence": | ||
2 + 5 * 10 | ||
|
||
define "Use Parentheses to Force Precedence": | ||
(2 + 5) * 10 | ||
|
||
define "Division Returns Decimal": | ||
10 / 2 | ||
|
||
define "Use Truncated Divide (div) for Integer Division": | ||
10 div 2 | ||
|
||
define "Mod returns remainder": | ||
10 mod 2 | ||
|
||
// # Quantities | ||
|
||
define "Mass Quantity": | ||
25 'mg' | ||
|
||
define "Length Quantity": | ||
100 'cm2' | ||
|
||
define "Respect the Units": | ||
1 'm' = 100 'cm' | ||
|
||
define "Calculate the Units": | ||
10 'cm' * 10 'cm' | ||
|
||
// # Date and Time Values | ||
|
||
define "Date Value": | ||
@2021-03-01 | ||
|
||
define "DateTime Value": | ||
@2021-03-01T14:30:14.5 | ||
|
||
define "Time Value (at midnight)": | ||
@T12:00:00.0 | ||
|
||
define "Time Value": | ||
@T14:30:14.5 | ||
|
||
define "Partial Date (Year)": | ||
@2014 | ||
|
||
define "Partial Date (Year-Month)": | ||
@2014-01 | ||
|
||
define "Partial Time (Hour)": | ||
@T14 | ||
|
||
define "Partial Time (Hour Minute)": | ||
@T14:30 | ||
|
||
define "DateTime Function": | ||
DateTime(2014, 7, 5) | ||
|
||
define "Time Function": | ||
Time(14, 30) | ||
|
||
define "Date From": | ||
date from @2014-01-25T14:30:14 | ||
|
||
define "Time From": | ||
time from @2014-01-25T14:30:14 | ||
|
||
define "Component From (Year)": | ||
year from @2014-01-25 | ||
|
||
define "Now Function": | ||
Now() | ||
|
||
define "Today Function": | ||
Today() | ||
|
||
define "TimeOfDay Function": | ||
TimeOfDay() | ||
|
||
// # Structured Values | ||
|
||
define "Simple Info": | ||
Tuple { name: 'Patrick', dob: @2014-01-01 } | ||
|
||
define "Nested Info": | ||
{ | ||
name: 'Patrick', | ||
dob: @2014-01-01, | ||
address: { | ||
line1: '41 Spinning Ave', | ||
city: 'Dayton', | ||
state: 'OH' | ||
}, | ||
phones: { | ||
{ | ||
number: '202-413-1234', | ||
use: 'home' | ||
} | ||
} | ||
} | ||
|
||
// # Missing Information | ||
|
||
define "Null Comparison": | ||
1 = null | ||
|
||
define "Null Arithmetic": | ||
1 + null | ||
|
||
define "Null Predicate": | ||
1 is null | ||
|
||
define "Not Null Predicate": | ||
1 is not null | ||
|
||
define "3-Valued Logic And": | ||
false and null | ||
|
||
define "3-Valued Logic Or": | ||
true or null | ||
|
||
define "Coalesce Expression": | ||
Coalesce(null, 1) |
Oops, something went wrong.