Verifying the the recent changes were merged correctly with the refactorings

This commit is contained in:
Adam Carbone 2016-02-05 14:37:30 -05:00
parent 7b5767c514
commit 686d942a90
1 changed files with 90 additions and 83 deletions

View File

@ -58,7 +58,6 @@ import ca.uhn.fhir.util.ResourceReferenceInfo;
public class ExampleDataUploader extends BaseCommand {
private static final String SPEC_DEFAULT_VERSION = "dstu2";
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleDataUploader.class);
@ -77,9 +76,7 @@ public class ExampleDataUploader extends BaseCommand {
Options options = new Options();
Option opt;
opt = new Option("f", "fhirversion", true, "Spec version to upload (default is '" + SPEC_DEFAULT_VERSION + "')");
opt.setRequired(false);
options.addOption(opt);
addFhirVersionOption(options);
opt = new Option("t", "target", true, "Base URL for the target server (e.g. \"http://example.com/fhir\")");
opt.setRequired(true);
@ -106,7 +103,8 @@ public class ExampleDataUploader extends BaseCommand {
@Override
public void run(CommandLine theCommandLine) throws Exception {
String specVersion = theCommandLine.getOptionValue("f", SPEC_DEFAULT_VERSION);
FhirContext ctx = getSpecVersionContext(theCommandLine);
String targetServer = theCommandLine.getOptionValue("t");
if (isBlank(targetServer)) {
throw new ParseException("No target server (-t) specified");
@ -124,16 +122,17 @@ public class ExampleDataUploader extends BaseCommand {
}
}
FhirContext ctx = null;
String specUrl;
if (SPEC_DEFAULT_VERSION.equals(specVersion)) {
ctx = FhirContext.forDstu2();
specUrl = "http://hl7.org/fhir/" + specVersion + "/examples-json.zip";
} else if ("dstu2.1".equals(specVersion)) {
ctx = FhirContext.forDstu2_1();
switch (ctx.getVersion().getVersion()) {
case DSTU2:
specUrl = "http://hl7.org/fhir/dstu2/examples-json.zip";
break;
case DSTU3:
specUrl = "http://hl7-fhir.github.io/examples-json.zip";
} else {
throw new ParseException("Unknown spec version: " + specVersion);
break;
default:
throw new ParseException("Invalid spec version for this command: " + ctx.getVersion().getVersion());
}
String filepath = theCommandLine.getOptionValue('d');
@ -226,7 +225,6 @@ public class ExampleDataUploader extends BaseCommand {
throw new Exception("File already exists: " + file.getAbsolutePath());
}
FileWriter w = new FileWriter(file, false);
w.append(encoded);
w.close();
} else {
@ -243,12 +241,12 @@ public class ExampleDataUploader extends BaseCommand {
}
}
private void processBundle(FhirContext ctx, Bundle originalBundle) {
private void processBundle(FhirContext ctx, Bundle bundle) {
Map<String, Integer> ids = new HashMap<String, Integer>();
Set<String> fullIds = new HashSet<String>();
for (Iterator<Entry> iterator = originalBundle.getEntry().iterator(); iterator.hasNext();) {
for (Iterator<Entry> iterator = bundle.getEntry().iterator(); iterator.hasNext();) {
Entry next = iterator.next();
// DataElement have giant IDs that seem invalid, need to investigate this..
@ -278,7 +276,7 @@ public class ExampleDataUploader extends BaseCommand {
}
Set<String> qualIds = new HashSet<String>();
Map<String, String> renames = new HashMap<String, String>();
for (Iterator<Entry> iterator = originalBundle.getEntry().iterator(); iterator.hasNext();) {
for (Iterator<Entry> iterator = bundle.getEntry().iterator(); iterator.hasNext();) {
Entry next = iterator.next();
if (next.getResource().getId().getIdPart() != null) {
String idPart = next.getResource().getId().getIdPart();
@ -299,7 +297,7 @@ public class ExampleDataUploader extends BaseCommand {
}
int goodRefs = 0;
for (Entry next : originalBundle.getEntry()) {
for (Entry next : bundle.getEntry()) {
List<ResourceReferenceInfo> refs = ctx.newTerser().getAllResourceReferences(next.getResource());
for (ResourceReferenceInfo nextRef : refs) {
// if (nextRef.getResourceReference().getReferenceElement().isAbsolute()) {
@ -323,10 +321,19 @@ public class ExampleDataUploader extends BaseCommand {
}
}
// for (Entry next : bundle.getEntry()) {
// if (next.getResource().getId().hasIdPart() &&
// Character.isLetter(next.getResource().getId().getIdPart().charAt(0))) {
// next.getTransaction().setUrl(next.getResource().getResourceName() + '/' +
// next.getResource().getId().getIdPart());
// next.getTransaction().setMethod(HTTPVerbEnum.PUT);
// }
// }
ourLog.info("{} good references", goodRefs);
System.gc();
ourLog.info("Final bundle: {} entries", originalBundle.getEntry().size());
ourLog.info("Final bundle: {} entries", bundle.getEntry().size());
}