View Javadoc
1   package ca.uhn.fhir.jpa.provider.dstu3;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.jpa.provider.BaseTerminologyUploaderProvider;
24  import ca.uhn.fhir.rest.annotation.Operation;
25  import ca.uhn.fhir.rest.annotation.OperationParam;
26  import ca.uhn.fhir.rest.api.server.RequestDetails;
27  import ca.uhn.fhir.rest.param.StringParam;
28  import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
29  import org.hl7.fhir.convertors.VersionConvertor_30_40;
30  import org.hl7.fhir.dstu3.model.Attachment;
31  import org.hl7.fhir.dstu3.model.IntegerType;
32  import org.hl7.fhir.dstu3.model.Parameters;
33  import org.hl7.fhir.dstu3.model.StringType;
34  import org.hl7.fhir.exceptions.FHIRException;
35  
36  import javax.servlet.http.HttpServletRequest;
37  import java.util.ArrayList;
38  import java.util.List;
39  
40  public class TerminologyUploaderProviderDstu3 extends BaseTerminologyUploaderProvider {
41  
42  	@Operation(name = UPLOAD_EXTERNAL_CODE_SYSTEM, idempotent = false, returnParameters = {
43  		@OperationParam(name = "conceptCount", type = IntegerType.class, min = 1)
44  	})
45  	public Parameters uploadExternalCodeSystem(
46  		HttpServletRequest theServletRequest,
47  		@OperationParam(name = "url", min = 1) StringParam theCodeSystemUrl,
48  		@OperationParam(name = "localfile", min = 1, max = OperationParam.MAX_UNLIMITED) List<StringType> theLocalFile,
49  		@OperationParam(name = "package", min = 0, max = OperationParam.MAX_UNLIMITED) List<Attachment> thePackage,
50  		RequestDetails theRequestDetails
51  	) {
52  		try {
53  			List<org.hl7.fhir.r4.model.StringType> localFile = null;
54  			if (theLocalFile != null) {
55  				localFile = new ArrayList<>();
56  				for (StringType next : theLocalFile) {
57  					localFile.add(VersionConvertor_30_40.convertString(next));
58  				}
59  			}
60  			List<org.hl7.fhir.r4.model.Attachment> pkg = null;
61  			if (thePackage!=null){
62  				pkg = new ArrayList<>();
63  				for (Attachment next : thePackage) {
64  					pkg.add(VersionConvertor_30_40.convertAttachment(next));
65  				}
66  			}
67  			org.hl7.fhir.r4.model.Parameters retValR4 = handleUploadExternalCodeSystem(theServletRequest, theCodeSystemUrl, localFile, pkg, theRequestDetails);
68  			return VersionConvertor_30_40.convertParameters(retValR4);
69  		} catch (FHIRException e) {
70  			throw new InternalErrorException(e);
71  		}
72  	}
73  }