use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method cacheResource.
public void cacheResource(Resource r) throws FHIRException {
synchronized (lock) {
Map<String, Resource> map = allResourcesById.get(r.fhirType());
if (map == null) {
map = new HashMap<String, Resource>();
allResourcesById.put(r.fhirType(), map);
}
map.put(r.getId(), r);
if (r instanceof MetadataResource) {
MetadataResource m = (MetadataResource) r;
String url = m.getUrl();
if (!allowLoadingDuplicates && hasResource(r.getClass(), url))
throw new DefinitionException("Duplicate Resource " + url);
if (r instanceof StructureDefinition)
seeMetadataResource((StructureDefinition) m, structures, false);
else if (r instanceof ValueSet)
seeMetadataResource((ValueSet) m, valueSets, false);
else if (r instanceof CodeSystem)
seeMetadataResource((CodeSystem) m, codeSystems, false);
else if (r instanceof ImplementationGuide)
seeMetadataResource((ImplementationGuide) m, guides, false);
else if (r instanceof CapabilityStatement)
seeMetadataResource((CapabilityStatement) m, capstmts, false);
else if (r instanceof SearchParameter)
seeMetadataResource((SearchParameter) m, searchParameters, false);
else if (r instanceof PlanDefinition)
seeMetadataResource((PlanDefinition) m, plans, false);
else if (r instanceof OperationDefinition)
seeMetadataResource((OperationDefinition) m, operations, false);
else if (r instanceof Questionnaire)
seeMetadataResource((Questionnaire) m, questionnaires, true);
else if (r instanceof ConceptMap)
seeMetadataResource((ConceptMap) m, maps, false);
else if (r instanceof StructureMap)
seeMetadataResource((StructureMap) m, transforms, false);
else if (r instanceof NamingSystem)
systems.add((NamingSystem) r);
}
}
}
use of org.hl7.fhir.dstu3.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)");
}
seeResource(e.getFullUrl(), e.getResource());
}
} else if (f instanceof MetadataResource) {
MetadataResource m = (MetadataResource) f;
seeResource(m.getUrl(), m);
}
}
use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method findReleventMaps.
private List<UsedConceptMap> findReleventMaps(ValueSet vs) throws FHIRException {
List<UsedConceptMap> res = new ArrayList<UsedConceptMap>();
for (MetadataResource md : context.allConformanceResources()) {
if (md instanceof ConceptMap) {
ConceptMap cm = (ConceptMap) md;
if (isSource(vs, cm.getSource())) {
ConceptMapRenderInstructions re = findByTarget(cm.getTarget());
if (re != null) {
ValueSet vst = cm.hasTarget() ? context.fetchResource(ValueSet.class, cm.hasTargetCanonicalType() ? cm.getTargetCanonicalType().getValue() : cm.getTargetUriType().asStringValue()) : null;
res.add(new UsedConceptMap(re, vst == null ? cm.getUserString("path") : vst.getUserString("path"), cm));
}
}
}
}
return res;
// Map<ConceptMap, String> mymaps = new HashMap<ConceptMap, String>();
// for (ConceptMap a : context.findMapsForSource(vs.getUrl())) {
// String url = "";
// ValueSet vsr = context.fetchResource(ValueSet.class, ((Reference) a.getTarget()).getReference());
// if (vsr != null)
// url = (String) vsr.getUserData("filename");
// mymaps.put(a, url);
// }
// Map<ConceptMap, String> mymaps = new HashMap<ConceptMap, String>();
// for (ConceptMap a : context.findMapsForSource(cs.getValueSet())) {
// String url = "";
// ValueSet vsr = context.fetchResource(ValueSet.class, ((Reference) a.getTarget()).getReference());
// if (vsr != null)
// url = (String) vsr.getUserData("filename");
// mymaps.put(a, url);
// }
// also, look in the contained resources for a concept map
// for (Resource r : cs.getContained()) {
// if (r instanceof ConceptMap) {
// ConceptMap cm = (ConceptMap) r;
// if (((Reference) cm.getSource()).getReference().equals(cs.getValueSet())) {
// String url = "";
// ValueSet vsr = context.fetchResource(ValueSet.class, ((Reference) cm.getTarget()).getReference());
// if (vsr != null)
// url = (String) vsr.getUserData("filename");
// mymaps.put(cm, url);
// }
// }
// }
}
use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class Unbundler method unbundle.
private static void unbundle(String src) throws FHIRFormatError, FileNotFoundException, IOException {
String folder = Utilities.getDirectoryForFile(src);
Bundle bnd = (Bundle) new JsonParser().parse(new FileInputStream(src));
for (BundleEntryComponent be : bnd.getEntry()) {
Resource r = be.getResource();
if (r != null) {
if (StringUtils.isBlank(r.getId())) {
if (r instanceof MetadataResource)
r.setId(tail((MetadataResource) r));
}
if (!StringUtils.isBlank(r.getId())) {
String tgt = Utilities.path(folder, r.fhirType() + "-" + r.getId() + ".json");
if (!new File(tgt).exists())
new JsonParser().compose(new FileOutputStream(tgt), r);
}
}
}
}
Aggregations