Skip to content

Commit 4f266f8

Browse files
author
Grahame Grieve
committed
fix loading of $translate source
1 parent 6ec43ee commit 4f266f8

1 file changed

Lines changed: 118 additions & 42 deletions

File tree

server/tx_operations.pas

Lines changed: 118 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ interface
4141
session, storage, ftx_service, tx_manager, tx_server, closuremanager;
4242

4343
type
44-
TLoadCodedType = (lctCS, lctVS, lctCMSrc, lctCMTgt);
45-
44+
// TLoadCodedType = (lctCS, lctVS, lctCMSrc, lctCMTgt);
4645

4746
{ TFhirTerminologyOperation }
4847

@@ -54,8 +53,10 @@ TFhirTerminologyOperation = class (TFhirOperation)
5453
function parseLanguages(value : String): THTTPLanguageList;
5554
procedure processExpansionParams(request: TFHIRRequest; manager: TFHIROperationEngine; params : TFhirParametersW; result : TFHIRTxOperationParams);
5655
function buildExpansionParams(request: TFHIRRequest; manager: TFHIROperationEngine; params : TFhirParametersW) : TFHIRTxOperationParams;
57-
function loadCoded(request : TFHIRRequest; loadType : TLoadCodedType; var issuePath : string; var mode : TValidationCheckMode) : TFhirCodeableConceptW; overload;
58-
function loadCoded(params : TFHIRParametersW; loadType : TLoadCodedType; var issuePath : string; var mode : TValidationCheckMode) : TFhirCodeableConceptW; overload;
56+
function loadCoded(request : TFHIRRequest; cs : boolean; var issuePath : string; var mode : TValidationCheckMode) : TFhirCodeableConceptW; overload;
57+
function loadCoded(params : TFHIRParametersW; cs : boolean; var issuePath : string; var mode : TValidationCheckMode) : TFhirCodeableConceptW; overload;
58+
function loadSourceCode(request : TFHIRRequest; var issuePath : string) : TFhirCodeableConceptW; overload;
59+
function loadSourceCode(params : TFHIRParametersW; var issuePath : string) : TFhirCodeableConceptW; overload;
5960
function processAdditionalResources(context : TOperationContext; manager: TFHIROperationEngine; mr : TFHIRMetadataResourceW; params : TFHIRParametersW) : TFslList<TFHIRCachedMetadataResource>;
6061
public
6162
constructor Create(factory : TFHIRFactory; server : TTerminologyServer; languages : TIETFLanguageDefinitions);
@@ -99,7 +100,7 @@ TFhirValueSetBatchValidationOperation = class (TFhirTerminologyOperation)
99100
function isWrite : boolean; override;
100101
function owningResource : String; override;
101102
function isValidation : boolean; override;
102-
function ExecuteItem(manager: TFHIROperationEngine; request: TFHIRRequest; reqId, issuePath : String; vs : TFhirValueSetW; profile : TFHIRTxOperationParams; abstractOk, inferSystem: boolean; mode : TValidationCheckMode; txResources : TFslList<TFHIRCachedMetadataResource>; var summary : string; tt : TFslTimeTracker; pItem : TFhirParametersParameterW; loadType : TLoadCodedType; batchParams : TFhirParametersW) : TFHIRResourceV; overload;
103+
function ExecuteItem(manager: TFHIROperationEngine; request: TFHIRRequest; reqId, issuePath : String; vs : TFhirValueSetW; profile : TFHIRTxOperationParams; abstractOk, inferSystem: boolean; mode : TValidationCheckMode; txResources : TFslList<TFHIRCachedMetadataResource>; var summary : string; tt : TFslTimeTracker; pItem : TFhirParametersParameterW; isCs : boolean; batchParams : TFhirParametersW) : TFHIRResourceV; overload;
103104
public
104105
function Name : String; override;
105106
function Types : TArray<String>; override;
@@ -494,16 +495,16 @@ function TFhirValueSetValidationOperation.Execute(context : TOperationContext; m
494495
params, pout : TFhirParametersW;
495496
oOut : TFHIROperationOutcomeW;
496497
needSecure : boolean;
497-
loadType : TLoadCodedType;
498+
isCS : boolean;
498499
mode : TValidationCheckMode;
499500
profile : TFhirTxOperationParams;
500501
txResources : TFslList<TFHIRCachedMetadataResource>;
501502
mr : TFHIRCachedMetadataResource;
502503
begin
503504
if request.ResourceName = 'ValueSet' then
504-
loadType := lctVS
505+
isCs := false
505506
else
506-
loadType := lctCS;
507+
isCS := true;
507508

508509
result := 'Validate Code';
509510
try
@@ -522,11 +523,11 @@ function TFhirValueSetValidationOperation.Execute(context : TOperationContext; m
522523
profile := nil;
523524
try
524525
profile := buildExpansionParams(request, manager, params);
525-
coded := loadCoded(request, loadType, issuePath, mode);
526+
coded := loadCoded(request, isCS, issuePath, mode);
526527
try
527528
result := 'Validate Code '+coded.renderText;
528529
try
529-
if loadType = lctVS then
530+
if not isCS then
530531
begin
531532
// first, we have to identify the value set.
532533
if request.Id <> '' then // and it must exist, because of the check above
@@ -684,7 +685,7 @@ function TFhirValueSetBatchValidationOperation.CreateDefinition(base : String):
684685
end;
685686

686687

687-
function TFhirValueSetBatchValidationOperation.ExecuteItem(manager: TFHIROperationEngine; request: TFHIRRequest; reqId, issuePath: String; vs: TFhirValueSetW; profile: TFHIRTxOperationParams; abstractOk, inferSystem: boolean; mode: TValidationCheckMode; txResources: TFslList<TFHIRCachedMetadataResource>; var summary: string; tt: TFslTimeTracker; pItem: TFhirParametersParameterW; loadType : TLoadCodedType; batchParams : TFhirParametersW): TFHIRResourceV;
688+
function TFhirValueSetBatchValidationOperation.ExecuteItem(manager: TFHIROperationEngine; request: TFHIRRequest; reqId, issuePath: String; vs: TFhirValueSetW; profile: TFHIRTxOperationParams; abstractOk, inferSystem: boolean; mode: TValidationCheckMode; txResources: TFslList<TFHIRCachedMetadataResource>; var summary: string; tt: TFslTimeTracker; pItem: TFhirParametersParameterW; isCS : boolean; batchParams : TFhirParametersW): TFHIRResourceV;
688689
var
689690
coded : TFhirCodeableConceptW;
690691
pOut : TFhirParametersW;
@@ -698,7 +699,7 @@ function TFhirValueSetBatchValidationOperation.ExecuteItem(manager: TFHIROperati
698699
abstractOk := req.str('abstract') <> 'false';
699700
if req.has('inferSystem') or req.has('implySystem') then
700701
inferSystem := (req.str('inferSystem') = 'true') or (req.str('implySystem') = 'true');
701-
coded := loadCoded(req, loadType, issuePath, mode);
702+
coded := loadCoded(req, isCS, issuePath, mode);
702703
try
703704
pOut := FServer.validate(reqId, issuePath, vs, coded, profile, abstractOk, inferSystem, mode, txResources, summary, tt);
704705
try
@@ -757,7 +758,7 @@ function TFhirValueSetBatchValidationOperation.Execute(context : TOperationConte
757758
params, pout : TFhirParametersW;
758759
oOut : TFHIROperationOutcomeW;
759760
needSecure : boolean;
760-
loadType : TLoadCodedType;
761+
isCS : boolean;
761762
mode : TValidationCheckMode;
762763
profile, lProfile : TFhirTxOperationParams;
763764
txResources : TFslList<TFHIRCachedMetadataResource>;
@@ -766,9 +767,9 @@ function TFhirValueSetBatchValidationOperation.Execute(context : TOperationConte
766767
res : TFHIRResourceV;
767768
begin
768769
if request.ResourceName = 'ValueSet' then
769-
loadType := lctVS
770+
isCS := false
770771
else
771-
loadType := lctCS;
772+
isCS := true;
772773

773774
result := 'Validate Code';
774775
try
@@ -789,7 +790,7 @@ function TFhirValueSetBatchValidationOperation.Execute(context : TOperationConte
789790
profile := buildExpansionParams(request, manager, params);
790791
result := 'Batch Validate Code';
791792
try
792-
if loadType = lctVS then
793+
if not isCS then
793794
begin
794795
// first, we have to identify the value set.
795796
if request.Id <> '' then // and it must exist, because of the check above
@@ -861,7 +862,7 @@ function TFhirValueSetBatchValidationOperation.Execute(context : TOperationConte
861862
begin
862863
lProfile := profile.clone;
863864
try
864-
res := executeItem(manager, request, request.id, issuePath, vs, profile, abstractOk, inferSystem, mode, txResources, summary, tt, pItem, loadType, params);
865+
res := executeItem(manager, request, request.id, issuePath, vs, profile, abstractOk, inferSystem, mode, txResources, summary, tt, pItem, isCS, params);
865866
try
866867
if (res <> nil) then
867868
pOut.addParam('validation').resource := res.link;
@@ -1120,7 +1121,6 @@ function TFhirConceptMapTranslationOperation.Execute(context : TOperationContext
11201121
// resourceKey : integer;
11211122
coded : TFhirCodeableConceptW;
11221123
coding : TFslList<TFhirCodingW>;
1123-
dummy : TValidationCheckMode;
11241124
params, pOut : TFhirParametersW;
11251125
issuePath : String;
11261126
txResources : TFslList<TFHIRCachedMetadataResource>;
@@ -1153,15 +1153,15 @@ function TFhirConceptMapTranslationOperation.Execute(context : TOperationContext
11531153
cml.addIfNotNull(FFactory.wrapConceptMap(params.param['conceptMap'].resource))
11541154
else
11551155
begin
1156-
srcSystem := findSystem(params, 'system', 'source');
1156+
srcSystem := findSystem(params, 'sourceSystem', 'source');
11571157
tgtSystem := findSystem(params, 'targetSystem', 'target');
11581158
findConceptMap(cml, srcSystem, params.str('sourceScope'), tgtSystem, params.str('targetScope'), txResources);
11591159
end;
11601160
if (cml.Empty) then
11611161
raise ETerminologyError.Create('Unable to find a conceptMap to use when translating (not provided by id, url, directly, or found by scope)');
11621162

11631163
// ok, now we need to find the source code to validate
1164-
coded := loadCoded(request, lctCMSrc, issuePath, dummy);
1164+
coded := loadSourceCode(request, issuePath);
11651165
try
11661166
coding := coded.codings;
11671167
try
@@ -1788,10 +1788,11 @@ destructor TFhirTerminologyOperation.Destroy;
17881788
inherited;
17891789
end;
17901790

1791-
function TFhirTerminologyOperation.loadCoded(request : TFHIRRequest; loadType : TLoadCodedType; var issuePath : string; var mode : TValidationCheckMode): TFhirCodeableConceptW;
1791+
function TFhirTerminologyOperation.loadCoded(request : TFHIRRequest; cs : boolean; var issuePath : string; var mode : TValidationCheckMode): TFhirCodeableConceptW;
17921792
var
17931793
coding : TFhirCodingW;
17941794
params : TFhirParametersW;
1795+
m : String;
17951796
begin
17961797
// ok, now we need to find the source code to validate
17971798
if (request.form <> nil) and request.form.hasParam('coding') then
@@ -1829,7 +1830,7 @@ function TFhirTerminologyOperation.loadCoded(request : TFHIRRequest; loadType :
18291830
coding.free;
18301831
end;
18311832
end
1832-
else if (loadType = lctCS) and request.Parameters.has('code') and request.Parameters.has('url') then
1833+
else if (cs) and request.Parameters.has('code') and request.Parameters.has('url') then
18331834
begin
18341835
issuePath := '';
18351836
mode := vcmCode;
@@ -1848,16 +1849,16 @@ function TFhirTerminologyOperation.loadCoded(request : TFHIRRequest; loadType :
18481849
begin
18491850
params := FFactory.wrapParams(request.Resource.link);
18501851
try
1851-
result := loadCoded(params, loadType, issuePath, mode);
1852+
result := loadCoded(params, cs, issuePath, mode);
18521853
finally
18531854
params.free;
18541855
end;
18551856
end
18561857
else
18571858
raise ETerminologyError.Create('Unable to find code to validate (looked for coding | codeableConcept | code+system | code+inferSystem in parameters ='+request.Parameters.Source+')', itNotFound);
18581859
end;
1859-
1860-
function TFhirTerminologyOperation.loadCoded(params : TFHIRParametersW; loadType : TLoadCodedType; var issuePath : string; var mode : TValidationCheckMode): TFhirCodeableConceptW;
1860+
1861+
function TFhirTerminologyOperation.loadCoded(params : TFHIRParametersW; cs : boolean; var issuePath : string; var mode : TValidationCheckMode): TFhirCodeableConceptW;
18611862
var
18621863
coding : TFhirCodingW;
18631864
begin
@@ -1879,7 +1880,7 @@ function TFhirTerminologyOperation.loadCoded(params : TFHIRParametersW; loadType
18791880
result := FFactory.wrapCodeableConcept(params.obj('codeableConcept').Link);
18801881
issuePath := 'CodeableConcept';
18811882
end
1882-
else if (params.has('code') and (params.has('system')) or ((loadType = lctVS) and (params.has('code') and (params.bool('inferSystem') or params.bool('implySystem'))))) then
1883+
else if (params.has('code') and (params.has('system')) or ((not cs) and (params.has('code') and (params.bool('inferSystem') or params.bool('implySystem'))))) then
18831884
begin
18841885
issuePath := '';
18851886
mode := vcmCode;
@@ -1899,7 +1900,7 @@ function TFhirTerminologyOperation.loadCoded(params : TFHIRParametersW; loadType
18991900
coding.free;
19001901
end;
19011902
end
1902-
else if (loadType = lctCS) and (params.has('code') and params.has('url')) then
1903+
else if (cs) and (params.has('code') and params.has('url')) then
19031904
begin
19041905
issuePath := '';
19051906
mode := vcmCode;
@@ -1916,27 +1917,102 @@ function TFhirTerminologyOperation.loadCoded(params : TFHIRParametersW; loadType
19161917
coding.free;
19171918
end;
19181919
end
1919-
else if (loadType = lctCMSrc) then
1920+
else
1921+
raise ETerminologyError.Create('Unable to find code to validate (looked for coding | codeableConcept | code in parameters ='+params.names+')', itNotFound);
1922+
end;
1923+
1924+
function TFhirTerminologyOperation.loadSourceCode(request : TFHIRRequest; var issuePath : string): TFhirCodeableConceptW;
1925+
var
1926+
coding : TFhirCodingW;
1927+
params : TFhirParametersW;
1928+
m : String;
1929+
begin
1930+
// ok, now we need to find the source code to translate
1931+
if (request.form <> nil) and request.form.hasParam('sourceCoding') then
19201932
begin
1921-
if params.has('sourceCode') and params.has('system') then
1922-
begin
1923-
result := FFactory.wrapCodeableConcept(fFactory.makeByName('CodeableConcept'));
1924-
coding := result.addCoding;
1925-
try
1933+
result := FFactory.wrapCodeableConcept(fFactory.makeByName('CodeableConcept'));
1934+
coding := FFactory.makeDtFromForm(request.form.getParam('sourceCoding'), request.langList, 'sourceCoding', 'Coding') as TFHIRCodingW;
1935+
try
1936+
result.addCoding(coding);
1937+
finally
1938+
coding.free;
1939+
end;
1940+
issuePath := 'sourceCoding';
1941+
end
1942+
else if (request.form <> nil) and request.form.hasParam('sourceCodeableConcept') then
1943+
begin
1944+
result := FFactory.makeDtFromForm(request.form.getParam('sourceCodeableConcept'), request.langList, 'sourceCodeableConcept', 'CodeableConcept') as TFhirCodeableConceptW;
1945+
issuePath := 'sourceCodeableConcept';
1946+
end
1947+
else if request.Parameters.has('sourceCode') and (request.Parameters.has('sourceSystem') or request.Parameters.has('system')) then
1948+
begin
1949+
issuePath := '';
1950+
result := FFactory.wrapCodeableConcept(fFactory.makeByName('CodeableConcept'));
1951+
coding := result.addCoding;
1952+
try
1953+
coding.systemUri := request.Parameters['sourceSystem'];
1954+
if (coding.systemUri = '') and (request.Parameters['system'] < '') then
1955+
coding.systemUri := request.Parameters['system'];
1956+
coding.version := request.Parameters['sourceSystemVersion'];
1957+
coding.code := request.Parameters['sourceCode'];
1958+
finally
1959+
coding.free;
1960+
end;
1961+
end
1962+
else if ((request.resource <> nil) and (request.Resource.fhirType = 'Parameters')) then
1963+
begin
1964+
params := FFactory.wrapParams(request.Resource.link);
1965+
try
1966+
result := loadSourceCode(params, issuePath);
1967+
finally
1968+
params.free;
1969+
end;
1970+
end
1971+
else
1972+
raise ETerminologyError.Create('Unable to find code to translate (looked for sourceCoding | sourceCodeableConcept | sourceCode+sourceSystem in parameters ='+request.Parameters.Source+')', itNotFound);
1973+
end;
1974+
1975+
function TFhirTerminologyOperation.loadSourceCode(params : TFHIRParametersW; var issuePath : string): TFhirCodeableConceptW;
1976+
var
1977+
coding : TFhirCodingW;
1978+
begin
1979+
if params.obj('sourceCoding') <> nil then
1980+
begin
1981+
result := FFactory.wrapCodeableConcept(fFactory.makeByName('CodeableConcept'));
1982+
issuePath := 'Coding';
1983+
coding := FFactory.wrapCoding(params.obj('sourceCoding').Link);
1984+
try
1985+
result.addCoding(coding);
1986+
finally
1987+
coding.free;
1988+
end;
1989+
end
1990+
else if params.has('sourceCodeableConcept') then
1991+
begin
1992+
result := FFactory.wrapCodeableConcept(params.obj('sourceCodeableConcept').Link);
1993+
issuePath := 'CodeableConcept';
1994+
end
1995+
else if params.has('sourceCode') and (params.has('sourceSystem') or params.has('system')) then
1996+
begin
1997+
issuePath := '';
1998+
result := FFactory.wrapCodeableConcept(fFactory.makeByName('CodeableConcept'));
1999+
coding := result.addCoding;
2000+
try
2001+
coding.systemUri := params.str('sourceSystem');
2002+
if (coding.systemUri = '') and (params.str('system') <> '') then
19262003
coding.systemUri := params.str('system');
1927-
coding.version := params.str('version');
1928-
coding.code := params.str('sourceCode');
1929-
finally
1930-
coding.free;
1931-
end;
1932-
end
1933-
else
1934-
raise ETerminologyError.Create('Unable to find code to validate (looked for coding | codeableConcept | code in parameters ='+params.names+')', itNotFound);
2004+
if params.has('systemVersion') then
2005+
coding.version := params.str('systemVersion');
2006+
coding.code := params.str('sourceCode');
2007+
finally
2008+
coding.free;
2009+
end;
19352010
end
19362011
else
1937-
raise ETerminologyError.Create('Unable to find code to validate (looked for coding | codeableConcept | code in parameters ='+params.names+')', itNotFound);
2012+
raise ETerminologyError.Create('Unable to find code to translate (looked for sourceCoding | sourceCodeableConcept | sourceCode in parameters ='+params.names+')', itNotFound);
19382013
end;
19392014

2015+
19402016
{$IFDEF DEV_FEATURES}
19412017
{ TFhirFeatureNegotiation }
19422018

0 commit comments

Comments
 (0)