def runtest(self): expression = self.test["expression"] resource = self.resource model = models[self.test["model"]] if "model" in self.test else None if "inputfile" in self.test: if self.test["inputfile"] in resources: resource = resources[self.test["inputfile"]] variables = {"resource": resource} if "context" in self.test: variables["context"] = evaluate(resource, self.test["context"])[0] if "variables" in self.test: variables.update(self.test["variables"]) if "error" in self.test and self.test["error"]: with pytest.raises(Exception): evaluate(resource, expression, variables, model) else: assert (evaluate(resource, expression, variables, model) == self.test["result"])
def aidbox_polimorphici_test(): qr = { "resourceType": "QuestionnaireResponse", "item": {"linkId": "foo", "answer": {"value": {"Coding": {"code": 1}}}}, } assert evaluate(qr, "QuestionnaireResponse.item.answer.value.Coding") == [ {"code": 1} ]
def misc_functions_test(resource, path, expected): # Monkeypatching for Constants.nowDate tz = datetime.timezone(datetime.timedelta(seconds=10800)) constants.nowDate = datetime.datetime(year=2020, month=8, day=20, hour=17, minute=52, second=15, tzinfo=tz) assert evaluate(resource, path) == expected
def find_concept_test(): env = {} env["Source"] = { "resourceType": "Bundle", "id": -1, "entry": [ { "resource": { "resourcceType": "ValueSet", "expansion": { "contains": [ { "system": "http://snomed.info/sct", "code": "16291000122106", "display": "Ifenprodil", }, { "system": "http://snomed.info/sct", "code": "789067004", "display": "Amlodipine benzoate", }, { "system": "http://snomed.info/sct", "code": "783132009", "display": "Bosentan hydrochloride", }, { "system": "http://snomed.info/sct", "code": "766924002", "display": "Substance with nicotinic receptor antagonist mechanism of action", }, { "system": "http://snomed.info/sct", "code": "708177006", "display": "Betahistine mesilate (substance)", }, ] }, } } ], } env["Coding"] = { "system": "http://snomed.info/sct", "code": "708177006", "display": "Betahistine mesilate (substance)", } assert evaluate( {}, "%Source.entry[0].resource.expansion.contains.where(code=%Coding.code)!~{}", env, ) == [True] env["Coding"] = ( { "system": "http://snomed.info/sct", "code": "428159003", "display": "Ambrisentan", }, ) assert evaluate( {}, "%Source.entry[0].resource.expansion.contains.where(code=%Coding.code)!~{}", env, ) == [False]
def simple_logic_expressions_test(resource, path, expected): assert evaluate(resource, path) == expected
def path_functions_test(resource, path, expected): assert evaluate(resource, path) == expected
def subsetting_functions_test(resource, path, expected): assert evaluate(resource, path) == expected