use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class R2R3ConversionManager method main.
public static void main(String[] args) throws IOException, FHIRException {
if (args.length == 0 || !hasParam(args, "-d2") || !hasParam(args, "-d3") || !hasParam(args, "-maps") || !hasParam(args, "-src") || !hasParam(args, "-dest") || (!hasParam(args, "-r2") && !hasParam(args, "-r3"))) {
System.out.println("R2 <--> R3 Convertor");
System.out.println("====================");
System.out.println();
System.out.println("parameters: -d2 [r2 definitions] -d3 [r3 definitions] -maps [map source] -src [source] -dest [dest] -r2/3 - fmt [format]");
System.out.println();
System.out.println("d2: definitions from http://hl7.org/fhir/DSTU2/downloads.html");
System.out.println("d3: definitions from http://hl7.org/fhir/STU3/downloads.html");
System.out.println("maps: R2/R3 maps from http://hl7.org/fhir/r2r3maps.zip");
System.out.println("src: filename for source to convert");
System.out.println("dest: filename for destination of conversion");
System.out.println("-r2: source is r2, convert to r3");
System.out.println("-r3: source is r3, convert to r2");
System.out.println("-fmt: xml | json (xml is default)");
} else {
R2R3ConversionManager self = new R2R3ConversionManager();
self.setR2Definitions(getNamedParam(args, "-d2"));
self.setR3Definitions(getNamedParam(args, "-d3"));
self.setMappingLibrary(getNamedParam(args, "-maps"));
FhirFormat fmt = hasParam(args, "-fmt") ? getNamedParam(args, "-fmt").equalsIgnoreCase("json") ? FhirFormat.JSON : FhirFormat.XML : FhirFormat.XML;
InputStream src = new FileInputStream(getNamedParam(args, "-src"));
OutputStream dst = new FileOutputStream(getNamedParam(args, "-dest"));
self.convert(src, dst, hasParam(args, "-r2"), fmt);
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class PhinVadsImporter method process.
private void process(String source, String dest) {
for (File f : new File(source).listFiles()) {
try {
System.out.println("Process " + f.getName());
ValueSet vs = importValueSet(TextFile.fileToBytes(f));
if (vs.getId() != null) {
new JsonParser().compose(new FileOutputStream(Utilities.path(dest, "ValueSet-" + vs.getId() + ".json")), vs);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class PhinVadsImporter method importValueSet.
private ValueSet importValueSet(byte[] source) throws FHIRException, IOException, ParseException {
// first thing do is split into 2
List<byte[]> parts = Utilities.splitBytes(source, "\r\n\r\n".getBytes());
if (parts.size() < 2) {
TextFile.bytesToFile(source, Utilities.path("[tmp]", "phinvads.txt"));
throw new FHIRException("Unable to parse phinvads value set: " + parts.size() + " parts found");
}
CSVReader rdr = new CSVReader(new ByteArrayInputStream(parts.get(0)));
rdr.setDelimiter('\t');
rdr.setMultiline(true);
rdr.readHeaders();
rdr.line();
ValueSet vs = new ValueSet();
vs.setId(rdr.cell("Value Set OID"));
vs.setUrl("http://phinvads.cdc.gov/fhir/ValueSet/" + vs.getId());
vs.getMeta().setSource("https://phinvads.cdc.gov/vads/ViewValueSet.action?oid=" + vs.getId());
vs.setVersion(rdr.cell("Value Set Version"));
vs.setTitle(rdr.cell("Value Set Name"));
vs.setName(rdr.cell("Value Set Code"));
vs.setDescription(rdr.cell("Value Set Definition"));
if ("Published".equals(rdr.cell("Value Set Status"))) {
vs.setStatus(PublicationStatus.ACTIVE);
} else {
vs.setStatus(PublicationStatus.DRAFT);
}
if (rdr.has("VS Last Updated Date")) {
vs.setDate(new SimpleDateFormat("mm/dd/yyyy").parse(rdr.cell("VS Last Updated Date")));
}
rdr = new CSVReader(new ByteArrayInputStream(parts.get(parts.size() - 1)));
rdr.setMultiline(true);
rdr.setDelimiter('\t');
rdr.readHeaders();
while (rdr.line()) {
String code = rdr.cell("Concept Code");
String display = rdr.cell("Preferred Concept Name");
String csoid = rdr.cell("Code System OID");
String csver = rdr.cell("Code System Version");
String url = context.oid2Uri(csoid);
if (url == null) {
url = "urn:oid:" + csoid;
}
csver = fixVersionforSystem(url, csver);
ConceptSetComponent inc = getInclude(vs, url, csver);
inc.addConcept().setCode(code).setDisplay(display);
}
return vs;
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class VSACImporter method process.
private void process(String source, String dest, String username, String password) throws FHIRException, IOException, URISyntaxException {
CSVReader csv = new CSVReader(new FileInputStream(source));
csv.readHeaders();
FHIRToolingClient fhirToolingClient = new FHIRToolingClient("https://cts.nlm.nih.gov/fhir", "fhir/vsac");
fhirToolingClient.setUsername(username);
fhirToolingClient.setPassword(password);
int i = 0;
while (csv.line()) {
String oid = csv.cell("OID");
try {
ValueSet vs = fhirToolingClient.read(ValueSet.class, oid);
new JsonParser().compose(new FileOutputStream(Utilities.path(dest, "ValueSet-" + oid + ".json")), vs);
i++;
if (i % 100 == 0) {
System.out.println(i);
}
} catch (Exception e) {
System.out.println("Unable to fetch OID " + oid + ": " + e.getMessage());
}
}
System.out.println("Done. " + i + " ValueSets");
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ExamplesPackageBuilder method process.
private void process(String source) throws FHIRFormatError, FileNotFoundException, IOException {
Set<String> set = new HashSet<>();
for (File f : new File(source).listFiles()) {
if (f.getName().endsWith(".json")) {
JsonObject obj = JsonTrackingParser.parseJson(new FileInputStream(f));
if (obj.has("resourceType") && obj.has("id")) {
String type = obj.get("resourceType").getAsString();
String id = obj.get("id").getAsString();
byte[] content = TextFile.fileToBytes(f);
if (type.equals("ConceptMap")) {
System.out.println("convert " + f.getName());
content = r5ToR4B(content);
TextFile.bytesToFile(content, f);
}
// TextFile.bytesToFile(content, Utilities.path(dest2, type+"-"+id+".json"));
// if (!set.contains(type+"/"+id)) {
// set.add(type+"/"+id);
// pck.addFile(Category.RESOURCE, type+"-"+id+".json", content);
// }
}
}
}
// pck.finish();
//
}
Aggregations