001package org.hl7.fhir.convertors.misc; 002 003import org.hl7.fhir.exceptions.FHIRException; 004import org.hl7.fhir.r4.formats.JsonParser; 005import org.hl7.fhir.r4.model.ValueSet; 006import org.hl7.fhir.r4.utils.client.FHIRToolingClient; 007import org.hl7.fhir.utilities.CSVReader; 008import org.hl7.fhir.utilities.Utilities; 009 010import java.io.FileInputStream; 011import java.io.FileOutputStream; 012import java.io.IOException; 013import java.net.URISyntaxException; 014import java.text.ParseException; 015 016public class VSACImporter extends OIDBasedValueSetImporter { 017 018 public VSACImporter() throws FHIRException, IOException { 019 super(); 020 init(); 021 } 022 023 public static void main(String[] args) throws FHIRException, IOException, ParseException, URISyntaxException { 024 VSACImporter self = new VSACImporter(); 025 self.process(args[0], args[1], args[2], args[3]); 026 } 027 028 private void process(String source, String dest, String username, String password) throws FHIRException, IOException, URISyntaxException { 029 CSVReader csv = new CSVReader(new FileInputStream(source)); 030 csv.readHeaders(); 031 032 FHIRToolingClient fhirToolingClient = new FHIRToolingClient("https://cts.nlm.nih.gov/fhir", "fhir/vsac"); 033 fhirToolingClient.setUsername(username); 034 fhirToolingClient.setPassword(password); 035 036 int i = 0; 037 while (csv.line()) { 038 String oid = csv.cell("OID"); 039 try { 040 ValueSet vs = fhirToolingClient.read(ValueSet.class, oid); 041 new JsonParser().compose(new FileOutputStream(Utilities.path(dest, "ValueSet-" + oid + ".json")), vs); 042 i++; 043 if (i % 100 == 0) { 044 System.out.println(i); 045 } 046 } catch (Exception e) { 047 System.out.println("Unable to fetch OID " + oid + ": " + e.getMessage()); 048 } 049 } 050 System.out.println("Done. " + i + " ValueSets"); 051 } 052}