Skip to content

Commit

Permalink
Enable extension/derivative upload via API.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicode committed Jan 18, 2024
1 parent 7d59b21 commit 399288e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
25 changes: 25 additions & 0 deletions docs/importing-extension-or-derivative-packages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Importing Extension or Derivative Packages
Many national versions of SNOMED CT are published using an extension package. This is where the release file does not contain the content of the International Edition.

Also SNOMED International and other organisations publish many derivative packages, for example the International Patient Summary RF2 Refset package.

In these scenarios the International Edition and the extension or derivative packages must be imported at the same time to create a single FHIR CodeSystem.

_Please note that when loading using a Syndication Service multiple packages are loaded automatically._

### Import Multiple SNOMED Archive Files
Run Snowstorm Lite in your local Docker:
```
docker pull snomedinternational/snowstorm-lite:latest
docker run -p 8080:8080 snomedinternational/snowstorm-lite \
--admin.password=yourAdminPassword
```

Upload all relevant SNOMED CT packages at once (should take under 10 minutes):
```
curl -u admin:yourAdminPassword \
--form file=@SnomedCT_InternationalRF2_PRODUCTION_20230731T120000Z.zip \
--form file=@SnomedCT_IPS_PRODUCTION_20231031T120000Z.zip \
--form version-uri="http:https://snomed.info/sct/900000000000207008/version/20230731" \
http:https://localhost:8080/fhir-admin/load-package
```
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ If you have access to the SNOMED International MLDS service then Snowstorm Lite
Run Snowstorm Lite in your local Docker:
```
docker pull snomedinternational/snowstorm-lite:latest
docker run -i -t -p 8085:8080 snomedinternational/snowstorm-lite \
docker run -i -t -p 8080:8080 snomedinternational/snowstorm-lite \
--admin.password=yourAdminPassword \
--syndicate --version-uri=http:https://snomed.info/sct/900000000000207008
```
Expand All @@ -69,7 +69,7 @@ If you have access to a SNOMED CT Edition release archive this can be imported.
Run Snowstorm Lite in your local Docker:
```
docker pull snomedinternational/snowstorm-lite:latest
docker run -p 8085:8080 snomedinternational/snowstorm-lite \
docker run -p 8080:8080 snomedinternational/snowstorm-lite \
--admin.password=yourAdminPassword
```

Expand All @@ -78,10 +78,12 @@ Upload a SNOMED CT package (takes about 2 minutes):
curl -u admin:yourAdminPassword \
--form file=@SnomedCT_InternationalRF2_PRODUCTION_20230131T120000Z.zip \
--form version-uri="http:https://snomed.info/sct/900000000000207008/version/20230131" \
http:https://localhost:8085/fhir-admin/load-package
http:https://localhost:8080/fhir-admin/load-package
```
Then Snowstorm Lite will be ready for use! The FHIR interface is here: http:https://localhost:8085/fhir.

It is possible to [import extension or derivative packages](docs/importing-extension-or-derivative-packages.md).

_It is also possible to [deploy as a Java application, without Docker](docs/running-with-java.md)._

## Postman
Expand Down
32 changes: 20 additions & 12 deletions src/main/java/org/snomed/snowstormlite/fhir/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import org.ihtsdo.otf.snomedboot.ReleaseImportException;
import org.snomed.snowstormlite.snomedimport.ImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

@RestController
Expand All @@ -30,16 +31,23 @@ public class AdminController {
private FhirContext fhirContext;

@PostMapping(value = "load-package", consumes = "multipart/form-data")
public void loadPackage(@RequestParam(name = "version-uri") String versionUri, @RequestParam MultipartFile file, HttpServletResponse response) throws IOException {

File tempFile = File.createTempFile("snomed-archive-upload-" + UUID.randomUUID(), ".tgz");
try (InputStream inputStream = file.getInputStream()) {
Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
public void loadPackage(@RequestParam(name = "version-uri") String versionUri, @RequestParam MultipartFile[] file, HttpServletResponse response) throws IOException {
if (file == null || file.length == 0) {
error(new FHIRServerResponseException(400, "Missing file parameter.", new OperationOutcome()), response);
return;
}

try {
importService.importReleaseStreams(Collections.singleton(new FileInputStream(tempFile)), versionUri);
} catch (ReleaseImportException e) {
Set<InputStream> inputStreams = new HashSet<>();
for (MultipartFile multipartFile : file) {
File tempFile = File.createTempFile("snomed-archive-upload-" + UUID.randomUUID(), ".tgz");
try (InputStream inputStream = multipartFile.getInputStream()) {
Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
inputStreams.add(new FileInputStream(tempFile));
}
importService.importReleaseStreams(inputStreams, versionUri);
} catch (IOException | ReleaseImportException e) {
error(new FHIRServerResponseException(500, "Failed to import SNOMED CT.", new OperationOutcome()), response);
} catch (FHIRServerResponseException e) {
error(e, response);
Expand Down

0 comments on commit 399288e

Please sign in to comment.