Skip to content

Commit

Permalink
add support for code = / concept = filters on $expand
Browse files Browse the repository at this point in the history
Grahame Grieve committed Nov 27, 2024
1 parent 95fc397 commit f926a88
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library/fdb/fdb_sqlite3.pas
Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@ procedure TFDBSQLiteManager.init;
loadSQLite;
assert(sqlite3_threadsafe>0, 'SQLite library is not threadsafe');
if not FAutoCreate then
if not FileExists(FFIlename) then
if not FileExists(FFilename) then
raise EDBException.Create('SQLite Database '+FFilename+' not found');
end;

32 changes: 29 additions & 3 deletions library/ftx/fhir_codesystem_service.pas
Original file line number Diff line number Diff line change
@@ -212,6 +212,8 @@ TFhirCodeSystemProvider = class (TCodeSystemProvider)
procedure iterateConceptsByProperty(src : TFhirCodeSystemConceptListW; pp : TFhirCodeSystemPropertyW; values: TStringArray; list: TFhirCodeSystemProviderFilterContext; include : boolean);
procedure iterateConceptsByKnownProperty(src : TFhirCodeSystemConceptListW; code : String; values: TStringArray; List: TFhirCodeSystemProviderFilterContext; include : boolean);
procedure iterateConceptsByRegex(src : TFhirCodeSystemConceptListW; regex: string; list: TFhirCodeSystemProviderFilterContext);
procedure iterateConceptsByEquality(positive : boolean; src : TFhirCodeSystemConceptListW; code: string; list: TFhirCodeSystemProviderFilterContext);

procedure listChildrenByProperty(code : String; list, children : TFhirCodeSystemConceptListW);
protected
function sizeInBytesV(magic : integer) : cardinal; override;
@@ -1608,6 +1610,20 @@ procedure TFhirCodeSystemProvider.iterateConceptsByRegex(src: TFhirCodeSystemCon
end;
end;

procedure TFhirCodeSystemProvider.iterateConceptsByEquality(positive: boolean; src: TFhirCodeSystemConceptListW; code: string; list: TFhirCodeSystemProviderFilterContext);
var
c : TFhirCodeSystemConceptW;
ok : boolean;
begin
for c in src do
begin
ok := (c.code = code) = positive;
if ok then
list.Add(c.Link, 0);
iterateConceptsByEquality(positive, c.conceptList, code, list);
end;
end;

function toStringArray(value : String) : TStringArray; overload;
begin
setLength(result, 1);
@@ -1632,7 +1648,7 @@ function TFhirCodeSystemProvider.filter(opContext : TTxOperationContext; forExpa
cc : TFhirCodeSystemConceptW;
includeRoot : boolean;
begin
if (op in [foIsA, foDescendentOf]) and (prop = 'concept') then
if (op in [foIsA, foDescendentOf]) and ((prop = 'concept') or (prop = 'code')) then
begin
code := doLocate(value, nil);
try
@@ -1655,7 +1671,7 @@ function TFhirCodeSystemProvider.filter(opContext : TTxOperationContext; forExpa
code.free;
end;
end
else if (op in [foIsNotA]) and (prop = 'concept') then
else if (op in [foIsNotA]) and ((prop = 'concept') or (prop = 'code')) then
begin
code := doLocate(value, nil);
try
@@ -1676,7 +1692,7 @@ function TFhirCodeSystemProvider.filter(opContext : TTxOperationContext; forExpa
code.free;
end;
end
else if (op = foIn) and (prop = 'concept') then
else if (op = foIn) and ((prop = 'concept') or (prop = 'code')) then
begin
result := TFhirCodeSystemProviderFilterContext.Create;
try
@@ -1717,6 +1733,16 @@ function TFhirCodeSystemProvider.filter(opContext : TTxOperationContext; forExpa
result.free;
end;
end
else if (op = foEqual) and (prop = 'code') then
begin
result := TFhirCodeSystemProviderFilterContext.Create;
try
iterateConceptsByEquality(true, FCs.CodeSystem.conceptList, value, result as TFhirCodeSystemProviderFilterContext);
result.link;
finally
result.free;
end;
end
else if (op = foRegex) and (prop = 'code') then
begin
result := TFhirCodeSystemProviderFilterContext.Create;

0 comments on commit f926a88

Please sign in to comment.