use of org.hl7.fhir.dstu3.model.MetadataResource in project quality-measure-and-cohort-service by Alvearie.
the class SHA256NameVersionIdStrategyTest method max_name_version_length___output_meets_fhir_constraints.
@Test
public void max_name_version_length___output_meets_fhir_constraints() throws Exception {
String name = RandomStringUtils.random(256, /*useLetters=*/
true, /*useNumbers=*/
true);
// There is no defined upper limit here, but we are guessing
// that three digits for each dotted triplet entry +
// delimiter + some label stuff isn't much bigger than this
String version = RandomStringUtils.random(20, /*useLetters=*/
true, /*useNumbers=*/
true);
;
MetadataResource resource = new Measure();
resource.setName(name);
resource.setVersion(version);
String generated = strategy.generateId(resource);
assertTrue(generated.matches("[A-Za-z0-9\\-\\.]{1,64}"));
}
use of org.hl7.fhir.dstu3.model.MetadataResource in project kindling by HL7.
the class SourceParser method loadResource.
private ResourceDefn loadResource(String n, Map<String, ResourceDefn> map, boolean isAbstract, boolean isTemplate, String t, boolean isInterface) throws Exception {
String folder = n;
WorkGroup wg = definitions.getWorkgroups().get(ini.getStringProperty("workgroups", n));
if (wg == null)
throw new Exception("No Workgroup found for resource " + n + ": '" + ini.getStringProperty("workgroups", n) + "'");
File f = new File(Utilities.path(srcDir, folder, n + ".svg"));
if (isTemplate) {
File spreadsheet = new CSFile((srcDir) + folder + File.separatorChar + n + "-spreadsheet.xml");
OldSpreadsheetParser sparser = new OldSpreadsheetParser("core", new CSFileInputStream(spreadsheet), spreadsheet.getName(), spreadsheet.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
ResourceDefn root;
try {
root = sparser.parseResource(isTemplate);
} catch (Exception e) {
throw new Exception("Error Parsing Resource " + n + ": " + e.getMessage(), e);
}
root.setAbstract(isAbstract);
root.setInterface(isInterface);
errors.addAll(sparser.getErrors());
setResourceProps(n, wg, root);
String sc = ini.getStringProperty("security-categorization", root.getName().toLowerCase());
if (sc != null) {
root.setSecurityCategorization(SecurityCategorization.fromCode(sc));
} else if (!Utilities.existsInList(root.getName(), "Resource", "DomainResource", "CanonicalResource", "MetadataResource", "MetadataPattern"))
throw new Exception("Must have an entry in the security-categorization section of fhir.ini for the resource " + root.getName());
for (EventDefn e : sparser.getEvents()) {
processEvent(e, root.getRoot());
}
if (map != null) {
map.put(root.getName(), root);
}
if (!isTemplate) {
definitions.getKnownResources().put(root.getName(), new DefinedCode(root.getName(), root.getRoot().getDefinition(), n));
context.getResourceNames().add(root.getName());
}
if (root.getNormativeVersion() != null || root.getNormativePackage() != null) {
root.setStatus(StandardsStatus.NORMATIVE);
}
if (f.exists()) {
parseSvgFile(f, root.getLayout(), f.getName());
}
if (map != null) {
map.put(root.getName(), root);
}
return root;
} else {
try {
new SpreadSheetReloader(context, srcDir, t, version.toCode()).process();
} catch (Exception e) {
System.out.println("Error loading spreadsheet for resource " + t + ": " + e.getMessage());
}
new SpreadSheetCreator(context, srcDir, t).generateSpreadsheet();
ResourceDefn rootNew = new ResourceParser(srcDir, definitions, context, wg, registry, version.toCode(), page.getConceptMaps()).parse(n, t);
if (f.exists()) {
parseSvgFile(f, rootNew.getLayout(), f.getName());
}
if (!isTemplate) {
definitions.getKnownResources().put(rootNew.getName(), new DefinedCode(rootNew.getName(), rootNew.getRoot().getDefinition(), n));
context.getResourceNames().add(rootNew.getName());
}
setResourceProps(n, wg, rootNew);
if (map != null) {
map.put(rootNew.getName(), rootNew);
}
return rootNew;
}
}
use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class R3ToR4Loader method loadBundle.
@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
Resource r3 = null;
if (isJson)
r3 = new JsonParser().parse(stream);
else
r3 = new XmlParser().parse(stream);
org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_30_40.convertResource(r3, advisor);
Bundle b;
if (r4 instanceof Bundle)
b = (Bundle) r4;
else {
b = new Bundle();
b.setId(UUID.randomUUID().toString().toLowerCase());
b.setType(BundleType.COLLECTION);
b.addEntry().setResource(r4).setFullUrl(r4 instanceof MetadataResource ? ((MetadataResource) r4).getUrl() : null);
}
for (CodeSystem cs : advisor.getCslist()) {
BundleEntryComponent be = b.addEntry();
be.setFullUrl(cs.getUrl());
be.setResource(cs);
}
if (killPrimitives) {
List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
remove.add(be);
}
}
b.getEntry().removeAll(remove);
}
if (patchUrls) {
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU3));
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
}
}
}
return b;
}
use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class R2ToR4Loader method loadBundle.
@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
Resource r2 = null;
if (isJson)
r2 = new JsonParser().parse(stream);
else
r2 = new XmlParser().parse(stream);
org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_10_40.convertResource(r2, advisor);
Bundle b;
if (r4 instanceof Bundle) {
b = (Bundle) r4;
} else {
b = new Bundle();
b.setId(UUID.randomUUID().toString().toLowerCase());
b.setType(BundleType.COLLECTION);
b.addEntry().setResource(r4).setFullUrl(r4 instanceof MetadataResource ? ((MetadataResource) r4).getUrl() : null);
}
// Add any code systems defined as part of processing value sets to the end of the converted Bundle
advisor.getCslist().forEach(cs -> {
BundleEntryComponent be = b.addEntry();
be.setFullUrl(cs.getUrl());
be.setResource(cs);
});
advisor.getCslist().clear();
if (killPrimitives) {
List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
remove.add(be);
}
}
b.getEntry().removeAll(remove);
}
if (patchUrls) {
b.getEntry().stream().filter(be -> be.hasResource() && be.getResource() instanceof StructureDefinition).map(be -> (StructureDefinition) be.getResource()).forEach(sd -> {
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2));
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
});
}
return b;
}
use of org.hl7.fhir.dstu3.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class R2016MayToR4Loader method loadBundle.
@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
Resource r2016may = null;
if (isJson)
r2016may = new JsonParser().parse(stream);
else
r2016may = new XmlParser().parse(stream);
org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_14_40.convertResource(r2016may, advisor);
Bundle b;
if (r4 instanceof Bundle)
b = (Bundle) r4;
else {
b = new Bundle();
b.setId(UUID.randomUUID().toString().toLowerCase());
b.setType(BundleType.COLLECTION);
b.addEntry().setResource(r4).setFullUrl(r4 instanceof MetadataResource ? ((MetadataResource) r4).getUrl() : null);
}
for (CodeSystem cs : advisor.getCslist()) {
BundleEntryComponent be = b.addEntry();
be.setFullUrl(cs.getUrl());
be.setResource(cs);
}
if (killPrimitives) {
List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
remove.add(be);
}
}
b.getEntry().removeAll(remove);
}
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
new ProfileUtilities(null, null, null).setIds(sd, false);
if (patchUrls) {
sd.setUrl(sd.getUrl().replace(URL_BASE, "http://hl7.org/fhir/2016May/"));
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
}
}
}
return b;
}
Aggregations