use of org.hl7.fhir.r4.model.MetadataResource in project kindling by HL7.
the class ExampleInspector method fetch.
@Override
public Element fetch(IResourceValidator validator, Object appContext, String url) throws IOException, FHIRException {
String[] parts = url.split("\\/");
if (parts.length == 2 && definitions.hasResource(parts[0])) {
ResourceDefn r = definitions.getResourceByName(parts[0]);
for (Example e : r.getExamples()) {
if (e.getElement() == null && e.hasXml()) {
e.setElement(new org.hl7.fhir.r5.elementmodel.XmlParser(context).parse(e.getXml()));
if (e.getElement().getProperty().getStructure().getBaseDefinition().contains("MetadataResource")) {
String urle = e.getElement().getChildValue("url");
String v = e.getElement().getChildValue("url");
if (urle != null && urle.startsWith("http://hl7.org/fhir") && !version.toCode().equals(v)) {
e.getElement().setChildValue("version", version.toCode());
}
}
}
if (e.getElement() != null) {
if (e.getElement().fhirType().equals("Bundle")) {
for (Base b : e.getElement().listChildrenByName("entry")) {
if (b.getChildByName("resource").hasValues()) {
Element res = (Element) b.getChildByName("resource").getValues().get(0);
if (res.fhirType().equals(parts[0]) && parts[1].equals(res.getChildValue("id"))) {
return res;
}
}
}
} else if (e.getElement().fhirType().equals(parts[0]) && e.getId().equals(parts[1])) {
return e.getElement();
}
}
}
try {
if (parts[0].equals("StructureDefinition"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(StructureDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
if (parts[0].equals("OperationDefinition"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(OperationDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
if (parts[0].equals("SearchParameter"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(SearchParameter.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
if (parts[0].equals("ValueSet"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(ValueSet.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
if (parts[0].equals("CodeSystem"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(CodeSystem.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
} catch (Exception e) {
return null;
}
return null;
} else
return null;
}
use of org.hl7.fhir.r4.model.MetadataResource in project quality-measure-and-cohort-service by Alvearie.
the class SHA256NameVersionIdStrategyTest method different_versions_same_name___output_different_ids.
@Test
public void different_versions_same_name___output_different_ids() throws Exception {
String name = "COL-InitialPopulation";
List<String> versions = Arrays.asList("1.0.0", "1.2.0", "2.1.0");
Set<String> ids = new HashSet<>();
for (String version : versions) {
MetadataResource resource = new Measure();
resource.setName(name);
resource.setVersion(version);
ids.add(strategy.generateId(resource));
}
assertEquals(versions.size(), ids.size());
}
use of org.hl7.fhir.r4.model.MetadataResource in project quality-measure-and-cohort-service by Alvearie.
the class SHA256NameVersionIdStrategyTest method same_input_multiple_times___always_same_output.
@Test
public void same_input_multiple_times___always_same_output() throws Exception {
String name = "COL-Denominator";
String version = "1.1.0";
MetadataResource resource = new Measure();
resource.setName(name);
resource.setVersion(version);
Set<String> ids = new HashSet<>();
for (int i = 0; i < 1000; i++) {
ids.add(strategy.generateId(resource));
}
assertEquals(1, ids.size());
}
use of org.hl7.fhir.r4.model.MetadataResource in project org.hl7.fhir.core by hapifhir.
the class R2ToR3Loader method loadBundle.
@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
Resource r2;
if (isJson)
r2 = new JsonParser().parse(stream);
else
r2 = new XmlParser().parse(stream);
org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_10_30.convertResource(r2, advisor_10_30);
Bundle b;
if (r3 instanceof Bundle) {
b = (Bundle) r3;
} else {
b = new Bundle();
b.setId(UUID.randomUUID().toString().toLowerCase());
b.setType(BundleType.COLLECTION);
b.addEntry().setResource(r3).setFullUrl(r3 instanceof MetadataResource ? ((MetadataResource) r3).getUrl() : null);
}
advisor_10_30.getCslist().forEach(cs -> {
BundleEntryComponent be = b.addEntry();
be.setFullUrl(cs.getUrl());
be.setResource(cs);
});
advisor_10_30.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.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);
}
}
}
Aggregations