use of org.hl7.fhir.r4.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpansionCache method loadCache.
private void loadCache() throws FHIRFormatError, IOException {
File[] files = new File(cacheFolder).listFiles();
for (File f : files) {
if (f.getName().endsWith(".xml")) {
final FileInputStream is = new FileInputStream(f);
try {
Resource r = context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).parse(is);
if (r instanceof OperationOutcome) {
OperationOutcome oo = (OperationOutcome) r;
expansions.put(ToolingExtensions.getExtension(oo, VS_ID_EXT).getValue().toString(), new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML, false).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
} else if (r instanceof ValueSet) {
ValueSet vs = (ValueSet) r;
if (vs.hasExpansion())
expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
else {
canonicals.put(vs.getUrl(), vs);
if (vs.hasVersion())
canonicals.put(vs.getUrl() + "|" + vs.getVersion(), vs);
}
} else if (r instanceof MetadataResource) {
MetadataResource md = (MetadataResource) r;
canonicals.put(md.getUrl(), md);
if (md.hasVersion())
canonicals.put(md.getUrl() + "|" + md.getVersion(), md);
}
} finally {
IOUtils.closeQuietly(is);
}
}
}
}
use of org.hl7.fhir.r4.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class R3R4ConversionTests method loadLib.
private void loadLib(String dir) throws FileNotFoundException, IOException {
StructureMapUtilities smu = new StructureMapUtilities(contextR4);
for (String s : new File(dir).list()) {
String map = TextFile.fileToString(Utilities.path(dir, s));
try {
StructureMap sm = smu.parse(map, s);
contextR3.cacheResource(sm);
contextR4.cacheResource(sm);
for (Resource r : sm.getContained()) {
if (r instanceof MetadataResource) {
MetadataResource mr = (MetadataResource) r.copy();
mr.setUrl(sm.getUrl() + "#" + r.getId());
contextR3.cacheResource(mr);
contextR4.cacheResource(mr);
}
}
} catch (FHIRException e) {
System.out.println("Unable to load " + Utilities.path(dir, s) + ": " + e.getMessage());
loadErrors.put(s, e);
// e.printStackTrace();
}
}
}
use of org.hl7.fhir.r4.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method loadFromFile.
public void loadFromFile(InputStream stream, String name, IContextResourceLoader loader) throws IOException, FHIRException {
Resource f;
try {
if (loader != null)
f = loader.loadBundle(stream, false);
else {
XmlParser xml = new XmlParser();
f = xml.parse(stream);
}
} catch (DataFormatException e1) {
throw new org.hl7.fhir.exceptions.FHIRFormatError("Error parsing " + name + ":" + e1.getMessage(), e1);
} catch (Exception e1) {
throw new org.hl7.fhir.exceptions.FHIRFormatError("Error parsing " + name + ":" + e1.getMessage(), e1);
}
if (f instanceof Bundle) {
Bundle bnd = (Bundle) f;
for (BundleEntryComponent e : bnd.getEntry()) {
if (e.getFullUrl() == null) {
logger.logDebugMessage(LogCategory.CONTEXT, "unidentified resource in " + name + " (no fullUrl)");
}
cacheResource(e.getResource());
}
} else if (f instanceof MetadataResource) {
MetadataResource m = (MetadataResource) f;
cacheResource(m);
}
}
use of org.hl7.fhir.r4.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method AddVsRef.
private void AddVsRef(ResourceContext rcontext, String value, XhtmlNode li) {
Resource res = rcontext == null ? null : rcontext.resolve(value);
if (res != null && !(res instanceof MetadataResource)) {
li.addText(value);
return;
}
MetadataResource vs = (MetadataResource) res;
if (vs == null)
vs = context.fetchResource(ValueSet.class, value);
if (vs == null)
vs = context.fetchResource(StructureDefinition.class, value);
// vs = context.fetchResource(DataElement.class, value);
if (vs == null)
vs = context.fetchResource(Questionnaire.class, value);
if (vs != null) {
String ref = (String) vs.getUserData("path");
ref = adjustForPath(ref);
XhtmlNode a = li.ah(ref == null ? "??" : ref.replace("\\", "/"));
a.addText(value);
} else {
CodeSystem cs = context.fetchCodeSystem(value);
if (cs != null) {
String ref = (String) cs.getUserData("path");
ref = adjustForPath(ref);
XhtmlNode a = li.ah(ref == null ? "??" : ref.replace("\\", "/"));
a.addText(value);
} else if (value.equals("http://snomed.info/sct") || value.equals("http://snomed.info/id")) {
XhtmlNode a = li.ah(value);
a.tx("SNOMED-CT");
} else {
if (value.startsWith("http://hl7.org") && !Utilities.existsInList(value, "http://hl7.org/fhir/sid/icd-10-us"))
System.out.println("Unable to resolve value set " + value);
li.addText(value);
}
}
}
use of org.hl7.fhir.r4.model.MetadataResource in project quality-measure-and-cohort-service by Alvearie.
the class MeasureImporter method convertToBundle.
/**
* Given a ZIP artifact convert the contents into a FHIR bundle
*
* @param is InputStream containing artifacts to import
* @return FHIR bundle
* @throws Exception any error
*/
public Bundle convertToBundle(InputStream is) throws Exception {
ZipInputStream zis = new ZipInputStream(is);
ZipEntry entry;
Bundle bundle = new Bundle();
bundle.setType(Bundle.BundleType.TRANSACTION);
while ((entry = zis.getNextEntry()) != null) {
if (isDeployable(entry)) {
IBaseResource resource = parser.parseResource(zis);
if (resource instanceof MetadataResource) {
MetadataResource metadataResource = (MetadataResource) resource;
if (metadataResource.hasName() && metadataResource.hasUrl() && metadataResource.hasVersion()) {
if (!metadataResource.hasId()) {
metadataResource.setId(idStrategy.generateId(metadataResource));
}
String url = metadataResource.fhirType() + "/" + metadataResource.getId();
bundle.addEntry().setFullUrl(url).setResource(metadataResource).getRequest().setUrl(url).setMethod(Bundle.HTTPVerb.PUT);
} else {
throw new IllegalArgumentException("Knowledge resources must specify at least name, version, and url");
}
}
}
}
return bundle;
}
Aggregations