use of org.hl7.fhir.r4.model.BaseResource in project redmatch by aehrc.
the class RedmatchGrammarCodeSystemGenerator method createBaseCodeSystem.
private CodeSystem createBaseCodeSystem(VersionedFhirPackage fhirPackage) {
CodeSystem cs = new CodeSystem();
cs.setId("redmatch-" + fhirPackage.getName());
cs.setUrl("http://redmatch." + fhirPackage.getName());
cs.setVersion(fhirPackage.getVersion());
cs.setName("Redmatch Validation Code System for " + fhirPackage.getName());
cs.setStatus(PublicationStatus.ACTIVE);
cs.setDescription("A code system with all the valid paths used to refer to attributes of resources in " + fhirPackage.getName());
cs.setValueSet("http://redmatch." + fhirPackage.getName() + "?vs");
cs.setHierarchyMeaning(CodeSystemHierarchyMeaning.ISA);
cs.setContent(CodeSystemContentMode.COMPLETE);
cs.setExperimental(false);
cs.setCompositional(false);
cs.setVersionNeeded(false);
cs.addProperty().setCode("parent").setDescription("Parent codes.").setType(PropertyType.CODE);
cs.addProperty().setCode("root").setDescription("Indicates if this concept is a root concept.").setType(PropertyType.BOOLEAN);
cs.addProperty().setCode("deprecated").setDescription("Indicates if this concept is deprecated.").setType(PropertyType.BOOLEAN);
cs.addProperty().setCode("parentResourceOrProfile").setDescription("If this concept represents an attribute then this property represents the resource or profile" + "that contains the attribute. If this concepts is a profile or resource then the parent resource is Object.").setType(PropertyType.CODE);
cs.addProperty().setCode("min").setDescription("Minimum cardinality").setType(PropertyType.INTEGER);
cs.addProperty().setCode("max").setDescription("Maximum cardinality").setType(PropertyType.STRING);
cs.addProperty().setCode("type").setDescription("Data type for this element.").setType(PropertyType.STRING);
cs.addProperty().setCode("targetProfile").setDescription("If this code represents a Reference attribute, contains an allowed target profile.").setType(PropertyType.STRING);
cs.addProperty().setCode("profile").setDescription("Indicates if this code represents a profile.").setType(PropertyType.BOOLEAN);
cs.addProperty().setCode("baseResource").setDescription("For profiles, indicates the resource the profile constrains.").setType(PropertyType.CODE);
cs.addProperty().setCode("extensionUrl").setDescription("If this code represents an extension, then this is its url.").setType(PropertyType.STRING);
cs.addProperty().setCode("profileUrl").setDescription("If this code represents a profile, then this is its url.").setType(PropertyType.STRING);
cs.addFilter().setCode("root").setValue("True or false.").addOperator(FilterOperator.EQUAL);
cs.addFilter().setCode("deprecated").setValue("True or false.").addOperator(FilterOperator.EQUAL);
cs.addFilter().setCode("parentResourceOrProfile").setValue("The parent resource or profile code.").addOperator(FilterOperator.EQUAL);
cs.addFilter().setCode("profile").setValue("True or false.").addOperator(FilterOperator.EQUAL);
// Create root concept
ConceptDefinitionComponent objectRoot = cs.addConcept().setCode("Object").setDisplay("Object");
objectRoot.addProperty().setCode("root").setValue(new BooleanType(true));
objectRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
ConceptDefinitionComponent complexTypeRoot = cs.addConcept().setCode("ComplexType").setDisplay("ComplexType");
complexTypeRoot.addProperty().setCode("root").setValue(new BooleanType(false));
complexTypeRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
complexTypeRoot.addProperty().setCode("parent").setValue(new CodeType("Object"));
ConceptDefinitionComponent resourceRoot = cs.addConcept().setCode("Resource").setDisplay("Resource");
resourceRoot.addProperty().setCode("root").setValue(new BooleanType(false));
resourceRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
resourceRoot.addProperty().setCode("parent").setValue(new CodeType("Object"));
ConceptDefinitionComponent profileRoot = cs.addConcept().setCode("Profile").setDisplay("Profile");
profileRoot.addProperty().setCode("root").setValue(new BooleanType(false));
profileRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
profileRoot.addProperty().setCode("parent").setValue(new CodeType("Object"));
return cs;
}
use of org.hl7.fhir.r4.model.BaseResource in project CRD by HL7-DaVinci.
the class CdsConnectFileStore method processFhirFiles.
private void processFhirFiles(List<CdsConnectFile> files, String topic) {
// process the fhir resource files
// setup the proper FHIR Context for the version of FHIR we are dealing with
FhirContext r4ctx = new org.hl7.davinci.r4.FhirComponents().getFhirContext();
IParser r4parser = r4ctx.newJsonParser();
// suppress the unknown element warnings
r4parser.setParserErrorHandler(new SuppressParserErrorHandler());
// process all of the files found within the topic/artifact
for (CdsConnectFile file : files) {
String path = file.getPath();
String filename = file.getFilename();
if (filename.endsWith(".json")) {
logger.info(" process: FHIR Resource: " + filename);
String[] parts = filename.split("-");
if (parts.length > 2) {
// String resourceType = parts[0];
String fhirVersion = parts[1];
String name = parts[2];
IBaseResource baseResource = null;
byte[] fileContents = file.getCqlBundle();
if (fhirVersion.equalsIgnoreCase("R4")) {
baseResource = r4parser.parseResource(new ByteArrayInputStream(fileContents));
}
processFhirResource(baseResource, path, filename, fhirVersion, topic);
}
}
}
}
use of org.hl7.fhir.r4.model.BaseResource in project CRD by HL7-DaVinci.
the class GitHubFileStore method processFhirFolder.
private void processFhirFolder(String topic, String fhirVersion, String fhirPath) {
fhirVersion = fhirVersion.toUpperCase();
logger.info(" GitHubFileStore::processFhirFolder(): " + fhirVersion + ": " + fhirPath);
// setup the proper FHIR Context for the version of FHIR we are dealing with
FhirContext ctx = null;
if (fhirVersion.equalsIgnoreCase("R4")) {
ctx = new org.hl7.davinci.r4.FhirComponents().getFhirContext();
} else {
logger.warn("unsupported FHIR version: " + fhirVersion + ", skipping folder");
return;
}
IParser parser = ctx.newJsonParser();
// suppress the unknown element warnings
parser.setParserErrorHandler(new SuppressParserErrorHandler());
for (String folder : connection.getDirectory(fhirPath)) {
if (folder.equalsIgnoreCase("resources")) {
String fullFolderPath = fhirPath + "/" + folder;
for (String resource : connection.getDirectory(fullFolderPath)) {
String filename = resource;
String fullFilePath = fullFolderPath + "/" + filename;
logger.info(" process: FHIR Resource: " + filename);
String[] parts = filename.split("-");
if (parts.length > 2) {
// = parts[0];
String resourceType;
if (!parts[1].equalsIgnoreCase(fhirVersion)) {
logger.warn("GitHubFileStore::processFhirFolder() warning: FhirVersion doesn't match!");
continue;
}
InputStream inputStream = connection.getFile(fullFilePath);
if (inputStream != null) {
IBaseResource baseResource = parser.parseResource(inputStream);
processFhirResource(baseResource, filename, filename, fhirVersion, topic);
} else {
logger.warn("could not find file: " + fullFilePath);
continue;
}
}
}
}
}
}
use of org.hl7.fhir.r4.model.BaseResource in project dpc-app by CMSgov.
the class RESTUtils method bulkResourceHandler.
/**
* Helper method for bulk submitting a {@link Bundle} of specific resources
*
* @param clazz - {@link Class} of type of filter {@link Bundle} entries
* @param params - {@link Parameters} which has a {@link Parameters#getParameterFirstRep()}
* @param resourceAction - {@link Function} which performs the actual bulk action for a single {@link BaseResource} of type {@link T}
* @param <T> - {@link T} generic type parameter which extends {@link BaseResource}
* @return - {@link Bundle} containing the processed results from the bulk submission
*/
@SuppressWarnings("unchecked")
public static <T extends BaseResource> List<T> bulkResourceHandler(Class<T> clazz, Parameters params, Function<T, Response> resourceAction) {
final Bundle resourceBundle = (Bundle) params.getParameterFirstRep().getResource();
final Bundle bundle = new Bundle();
bundle.setType(Bundle.BundleType.COLLECTION);
return resourceBundle.getEntry().stream().filter(Bundle.BundleEntryComponent::hasResource).map(Bundle.BundleEntryComponent::getResource).filter(resource -> resource.getClass().equals(clazz)).map(clazz::cast).map(resource -> {
final Response response = resourceAction.apply(resource);
if (HttpStatus.isSuccess(response.getStatus())) {
return (Resource) response.getEntity();
}
// If there's an error, rethrow the original method
throw new WebApplicationException(response);
}).map(r -> (T) r).collect(Collectors.toList());
}
use of org.hl7.fhir.r4.model.BaseResource in project kindling by HL7.
the class ProfileGenerator method generate.
public StructureDefinition generate(Profile pack, ConstraintStructure profile, ResourceDefn resource, String id, String html, ImplementationGuideDefn usage, List<ValidationMessage> issues, ResourceDefn baseResource) throws Exception {
if (profile.getResource() != null)
return profile.getResource();
StructureDefinition p = new StructureDefinition();
p.setId(FormatUtilities.makeId(id));
p.setUrl("http://hl7.org/fhir/StructureDefinition/" + id);
if (usage != null && !usage.isCore()) {
if (!id.startsWith(usage.getCode() + "-"))
throw new Exception("Error: " + id + " must start with " + usage.getCode() + "-");
}
if (!resource.getRoot().getTypes().isEmpty() && (resource.getRoot().getTypes().get(0).getProfile() != null))
p.setBaseDefinition(resource.getRoot().getTypes().get(0).getProfile());
else
p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + resource.getName());
if (definitions.hasType(resource.getName()))
p.setKind(StructureDefinitionKind.COMPLEXTYPE);
else
p.setKind(StructureDefinitionKind.RESOURCE);
p.setType(resource.getName());
p.setDerivation(TypeDerivationRule.CONSTRAINT);
p.setAbstract(false);
p.setUserData("filename", id);
p.setUserData("path", ((usage == null || usage.isCore()) ? "" : usage.getCode() + File.separator) + id + ".html");
p.setTitle(pack.metadata("display"));
p.setFhirVersion(version);
p.setVersion(version.toCode());
if (pack.hasMetadata("summary-" + profile.getTitle()))
ToolingExtensions.addMarkdownExtension(p, "http://hl7.org/fhir/StructureDefinition/structuredefinition-summary", pack.metadata("summary-" + profile.getTitle()));
ToolResourceUtilities.updateUsage(p, usage.getCode());
p.setName(pack.metadata("name"));
p.setPublisher(pack.metadata("author.name"));
if (pack.hasMetadata("author.reference"))
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, pack.metadata("author.reference")));
// <code> opt Zero+ Coding assist with indexing and finding</code>
p.setDescription(resource.getRoot().getShortDefn());
if (!p.hasDescriptionElement() && pack.hasMetadata("description"))
p.setDescription(preProcessMarkdown(pack.metadata("description"), "pack.description"));
p.setPurpose(resource.getRoot().getRequirements());
if (!p.hasPurpose() && pack.hasMetadata("requirements"))
p.setPurpose(pack.metadata("requirements"));
p.setExperimental(Utilities.existsInList(pack.metadata("Experimental"), "y", "Y", "true", "TRUE", "1"));
if (pack.hasMetadata("date"))
p.setDateElement(Factory.newDateTime(pack.metadata("date").substring(0, 10)));
else
p.setDate(genDate.getTime());
if (pack.hasMetadata("fmm-level"))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(pack.getFmmLevel()));
else if (pack.hasMetadata("fmm"))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(pack.metadata("fmm")));
else if (!Utilities.noString(resource.getFmmLevel()))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(resource.getFmmLevel()));
else if (baseResource != null && !Utilities.noString(baseResource.getFmmLevel()))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(baseResource.getFmmLevel()));
if (pack.hasMetadata("workgroup"))
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, pack.getWg());
else if (resource.getWg() != null)
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, resource.getWg().getCode());
else if (baseResource != null && baseResource.getWg() != null)
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, baseResource.getWg().getCode());
if (pack.hasMetadata("Standards-Status"))
ToolingExtensions.setStandardsStatus(p, StandardsStatus.fromCode(pack.metadata("Standards-Status")), null);
else
ToolingExtensions.setStandardsStatus(p, resource.getStatus(), null);
if (pack.hasMetadata("status"))
p.setStatus(PublicationStatus.fromCode(pack.metadata("status")));
if (pack.getMetadata().containsKey("code"))
for (String s : pack.getMetadata().get("code")) if (!Utilities.noString(s))
p.getKeyword().add(Factory.makeCoding(s));
if (pack.hasMetadata("datadictionary"))
ToolingExtensions.setStringExtension(p, "http://hl7.org/fhir/StructureDefinition/datadictionary", pack.metadata("datadictionary"));
Set<String> containedSlices = new HashSet<String>();
p.setDifferential(new StructureDefinitionDifferentialComponent());
defineElement(pack, p, p.getDifferential().getElement(), resource.getRoot(), resource.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, null, null, false);
List<String> names = new ArrayList<String>();
names.addAll(resource.getSearchParams().keySet());
Collections.sort(names);
for (String pn : names) {
pack.getSearchParameters().add(makeSearchParam(p, pack.getId() + "-" + resource.getName() + "-" + pn, resource.getName(), resource.getSearchParams().get(pn), resource));
}
StructureDefinition base = definitions.getSnapShotForBase(p.getBaseDefinition());
List<String> errors = new ArrayList<String>();
new ProfileUtilities(context, null, pkp).sortDifferential(base, p, p.getName(), errors, false);
for (String s : errors) issues.add(new ValidationMessage(Source.ProfileValidator, IssueType.STRUCTURE, -1, -1, p.getUrl(), s, IssueSeverity.WARNING));
reset();
// ok, c is the differential. now we make the snapshot
new ProfileUtilities(context, issues, pkp).generateSnapshot(base, p, "http://hl7.org/fhir/StructureDefinition/" + p.getType(), "http://hl7.org/fhir", p.getName());
reset();
p.getDifferential().getElement().get(0).getType().clear();
p.getSnapshot().getElement().get(0).getType().clear();
addElementConstraintToSnapshot(p);
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.addText("to do");
p.setText(new Narrative());
p.getText().setStatus(NarrativeStatus.GENERATED);
p.getText().setDiv(div);
new ProfileUtilities(context, issues, pkp).setIds(p, false);
checkHasTypes(p);
return p;
}
Aggregations