Search in sources :

Example 16 with MetadataResource

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);
        }
    }
}
Also used : DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 17 with MetadataResource

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);
    }
}
Also used : MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) DataFormatException(ca.uhn.fhir.parser.DataFormatException) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.dstu3.model.Bundle) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) Resource(org.hl7.fhir.dstu3.model.Resource) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 18 with MetadataResource

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);
// }
// }
// }
}
Also used : ValueSet(org.hl7.fhir.r4.model.ValueSet)

Example 19 with MetadataResource

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);
            }
        }
    }
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) FileOutputStream(java.io.FileOutputStream) Resource(org.hl7.fhir.r4.model.Resource) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) File(java.io.File) FileInputStream(java.io.FileInputStream) JsonParser(org.hl7.fhir.r4.formats.JsonParser)

Aggregations

MetadataResource (org.hl7.fhir.r4.model.MetadataResource)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 IOException (java.io.IOException)6 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)4 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)4 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)4 URISyntaxException (java.net.URISyntaxException)3 Resource (org.hl7.fhir.dstu3.model.Resource)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 Resource (org.hl7.fhir.r4.model.Resource)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 List (java.util.List)2 UUID (java.util.UUID)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)2