-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #1
- Loading branch information
Showing
5 changed files
with
196 additions
and
69 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 |
---|---|---|
|
@@ -12,3 +12,4 @@ pytest-cov = "==3.0.0" | |
freezegun = "==1.2.2" | ||
pyyaml = "==5.4" | ||
pre-commit = "~=2.21.0" | ||
black = "*" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,43 @@ | ||
class DSL: | ||
path: str | ||
|
||
def __init__(self, prefix=None): | ||
self.path = prefix | ||
|
||
def __getattr__(self, attr): | ||
if self.path is None and attr == "empty": | ||
return DSL("{}") | ||
if self.path is None and attr == "env": | ||
return DSL("%") | ||
elif self.path == "%": | ||
return DSL(f"{self.path}{attr}") | ||
elif self.path is not None: | ||
return DSL(f"{self.path}.{attr}") | ||
else: | ||
return DSL(attr) | ||
|
||
def __getitem__(self, attr): | ||
return DSL(f"{self.path}[{attr}]") | ||
|
||
def __eq__(self, other): | ||
return DSL(f"{self.path} ~ {format_value(other)}") | ||
|
||
def __ne__(self, other): | ||
return DSL(f"{self.path} !~ {format_value(other)}") | ||
|
||
def __call__(self, **kwargs): | ||
args = build_args(kwargs) | ||
return DSL(f"{self.path}({args})") | ||
|
||
def __str__(self): | ||
return self.path | ||
|
||
|
||
def format_value(value): | ||
if isinstance(value, str): | ||
return f"'{value}'" | ||
return str(value) | ||
|
||
|
||
def build_args(args): | ||
return ",".join(f"{k}={format_value(v)}" for k, v in args.items()) |
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,16 @@ | ||
from fhirpathpy import dsl | ||
|
||
|
||
def dsl_test(): | ||
assert str(dsl.Patient.id) == "Patient.id" | ||
assert ( | ||
str(dsl.Patient.name.where(use="usual").given.first()) | ||
== "Patient.name.where(use='usual').given.first()" | ||
) | ||
assert ( | ||
str( | ||
dsl.env.Source.entry[0].resource.expansion.contains.where(code=dsl.env.Coding.code) | ||
!= dsl.empty | ||
) | ||
== "%Source.entry[0].resource.expansion.contains.where(code=%Coding.code) !~ {}" | ||
) |