This commit is contained in:
Grahame Grieve 2020-09-02 08:09:50 +10:00
commit c3b21733fd
2 changed files with 16 additions and 29 deletions

View File

@ -1,33 +1,20 @@
package org.hl7.fhir.convertors.misc;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.utilities.CSVReader;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.cache.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.cache.NpmPackage;
import org.hl7.fhir.utilities.cache.ToolsVersion;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.w3c.dom.Element;
import java.io.*;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
public class VSACImporter extends OIDBasedValueSetImporter {
public static void main(String[] args) throws FileNotFoundException, FHIRException, IOException, ParseException {
@ -44,19 +31,19 @@ public class VSACImporter extends OIDBasedValueSetImporter {
private void process(String source, String dest) {
for (File f : new File(source).listFiles()) {
try {
System.out.println("Process "+f.getName());
System.out.println("Process " + f.getName());
List<ValueSet> vsl = importValueSet(TextFile.fileToBytes(f));
for (ValueSet vs : vsl) {
if (vs.getId() != null) {
new JsonParser().compose(new FileOutputStream(Utilities.path(dest, "ValueSet-"+vs.getId()+".json")), vs);
new JsonParser().compose(new FileOutputStream(Utilities.path(dest, "ValueSet-" + vs.getId() + ".json")), vs);
}
}
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
private List<ValueSet> importValueSet(byte[] source) throws Exception {
List<ValueSet> res = new ArrayList<ValueSet>();
Element x = loadXml(new ByteArrayInputStream(source)).getDocumentElement();
@ -64,8 +51,8 @@ public class VSACImporter extends OIDBasedValueSetImporter {
for (Element v : vl) {
ValueSet vs = new ValueSet();
vs.setId(v.getAttribute("ID"));
vs.setUrl("http://vsac.nlm.nih.gov/fhir/ValueSet/"+vs.getId());
vs.getMeta().setSource("https://vsac.nlm.nih.gov/valueset/"+vs.getId()+"/expansion");
vs.setUrl("http://vsac.nlm.nih.gov/fhir/ValueSet/" + vs.getId());
vs.getMeta().setSource("https://vsac.nlm.nih.gov/valueset/" + vs.getId() + "/expansion");
vs.setVersion(v.getAttribute("version"));
vs.setTitle(v.getAttribute("displayName"));
vs.setName(Utilities.titleize(vs.getTitle()).replace(" ", ""));
@ -74,9 +61,9 @@ public class VSACImporter extends OIDBasedValueSetImporter {
vs.setDescription(d.getTextContent());
}
Element s = XMLUtil.getNamedChild(v, "Status");
if (s != null && "Active".equals(s.getTextContent())) {
if (s != null && "Active".equals(s.getTextContent())) {
vs.setStatus(PublicationStatus.ACTIVE);
} else {
} else {
vs.setStatus(PublicationStatus.DRAFT);
}
Element dt = XMLUtil.getNamedChild(v, "RevisionDate");
@ -94,7 +81,7 @@ public class VSACImporter extends OIDBasedValueSetImporter {
String csver = cc.getAttribute("codeSystemVersion");
String url = context.oid2Uri(csoid);
if (url == null) {
url = "urn:oid:"+csoid;
url = "urn:oid:" + csoid;
}
csver = fixVersionforSystem(url, csver);
ConceptSetComponent inc = getInclude(vs, url, csver);

View File

@ -38,7 +38,7 @@ public class ValidationOutcome {
}
@JsonProperty("issues")
public ValidationOutcome setIssues(List<ValidationMessage> issues) {
public ValidationOutcome setMessages(List<ValidationMessage> issues) {
this.messages = issues;
return this;
}