use of org.hl7.fhir.r5.model.Questionnaire in project CRD by HL7-DaVinci.
the class QuestionnaireValueSetProcessor method findAndReplaceValueSetReferences.
/**
* Recursively visits every questionnaire item and replaces every `answerValueSet` that isn't a local
* hash (#) reference into a local reference. This fills the valueSetMap with the loaded valuesets.
*
* @param itemComponents The item components to visit.
* @param valueSetMap A mapping of ValueSet urls to loaded valuesets that should be filled as references are found.
* @param fileStore The file store that is used to load valuesets from.
* @param baseUrl The base url of the server from the request. Used to identify local valuesets.
*/
private void findAndReplaceValueSetReferences(List<QuestionnaireItemComponent> itemComponents, Map<String, ValueSet> valueSetMap, FileStore fileStore, String baseUrl) {
for (QuestionnaireItemComponent itemComponent : itemComponents) {
// If there is an answerValueSet field we need to do some work on this item
if (itemComponent.hasAnswerValueSet()) {
// Only look for a valueset to embed if it does not appear to be a hash reference
if (!itemComponent.getAnswerValueSet().startsWith("#")) {
logger.info("answerValueSet found with url - " + itemComponent.getAnswerValueSet());
String valueSetId = findAndLoadValueSet(itemComponent.getAnswerValueSet(), valueSetMap, fileStore, baseUrl);
if (valueSetId != null) {
itemComponent.getAnswerValueSet();
itemComponent.setAnswerValueSet("#" + valueSetId);
logger.info("answerValueSet replaced with - " + itemComponent.getAnswerValueSet());
} else {
logger.warn("Referenced ValueSet: " + itemComponent.getAnswerValueSet() + " was not found.");
}
}
}
// Recurse down into child items.
if (itemComponent.hasItem()) {
findAndReplaceValueSetReferences(itemComponent.getItem(), valueSetMap, fileStore, baseUrl);
}
}
}
use of org.hl7.fhir.r5.model.Questionnaire in project CRD by HL7-DaVinci.
the class SubQuestionnaireProcessor method processItem.
/**
* Determines if this item is a sub-questionnaire reference and returns the items to replace it with. Returns the same list
* otherwise. Also recursively continues scanning if this is just a grouping item.
*
* @param item The item to check for sub-questionnaire referece.
* @param fileStore The FileStore to be used for fetching sub-questionnaires.
* @param baseUrl The base url from the server.
* @param containedList List of contained resources to put in the assembled Questionnaire. This will be filled while iterating.
* @param extensionList List of extensions to put in the assembled Questionnaire. This will be filled while iterating.
* @return New list of items to replace this item with.
*/
private List<QuestionnaireItemComponent> processItem(QuestionnaireItemComponent item, FileStore fileStore, String baseUrl, Hashtable<String, org.hl7.fhir.r4.model.Resource> containedList, List<Extension> extensionList) {
// find if item has an extension is sub-questionnaire
Extension e = item.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/sub-questionnaire");
if (e != null) {
// read sub questionnaire from file store
CanonicalType value = e.castToCanonical(e.getValue());
logger.info("SubQuestionnaireProcessor::parseItem(): Looking for SubQuestionnaire " + value);
// strip the type off of the id if it is there
String id = value.asStringValue();
String[] parts = id.split("/");
if (parts.length > 1) {
id = parts[1];
}
boolean expandRootItem = false;
Extension expand = item.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/sub-questionnaire-expand");
if (expand != null) {
expandRootItem = expand.castToBoolean(expand.getValue()).booleanValue();
}
FileResource subFileResource = fileStore.getFhirResourceById("R4", "questionnaire", id, baseUrl, false);
if (subFileResource != null) {
Questionnaire subQuestionnaire = (Questionnaire) this.parseFhirFileResource(subFileResource);
if (subQuestionnaire != null) {
// merge extensions
for (Extension subExtension : subQuestionnaire.getExtension()) {
if (extensionList.stream().noneMatch(ext -> ext.equalsDeep(subExtension))) {
extensionList.add(subExtension);
}
}
// merge contained resources
for (org.hl7.fhir.r4.model.Resource r : subQuestionnaire.getContained()) {
containedList.put(r.getId(), r);
}
List<QuestionnaireItemComponent> rootItems = subQuestionnaire.getItem();
// there are more than one root items in sub questionnaire, don't expand
if (!expandRootItem || rootItems.size() > 1) {
return rootItems;
} else {
return rootItems.get(0).getItem();
}
} else {
// SubQuestionnaire could not be loaded
logger.warn("SubQuestionnaireProcessor::parseItem(): Could not load SubQuestionnaire " + value.asStringValue());
return Arrays.asList(item);
}
} else {
// SubQuestionnaire could not be found
logger.warn("SubQuestionnaireProcessor::parseItem(): Could not find SubQuestionnaire " + value.asStringValue());
return Arrays.asList(item);
}
}
// parse sub-items
this.processItemList(item.getItem(), fileStore, baseUrl, containedList, extensionList);
return Arrays.asList(item);
}
use of org.hl7.fhir.r5.model.Questionnaire in project CRD by HL7-DaVinci.
the class QuestionnaireController method addQuestionSetToQuestionnaireResponse.
/**
* Adds the given set of questions to the contained questionniare in the questionnaire response.
* @param inputQuestionnaireResponse
* @param questionSet
*/
private static void addQuestionSetToQuestionnaireResponse(QuestionnaireResponse inputQuestionnaireResponse, List<QuestionnaireItemComponent> questionSet) {
// Add the next question set to the QuestionnaireResponse.contained[0].item[].
Questionnaire containedQuestionnaire = (Questionnaire) inputQuestionnaireResponse.getContained().get(0);
questionSet.forEach(questionItem -> containedQuestionnaire.addItem(questionItem));
}
use of org.hl7.fhir.r5.model.Questionnaire in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveTask.
private Task resolveTask(ActivityDefinition activityDefinition, String patientId) {
Task task = new Task();
task.setStatus(Task.TaskStatus.DRAFT);
task.setIntent(Task.TaskIntent.PROPOSAL);
task.setFor(new Reference(patientId));
Task.ParameterComponent input = new Task.ParameterComponent();
if (activityDefinition.hasCode()) {
task.setCode(activityDefinition.getCode());
input.setType(activityDefinition.getCode());
}
// Extension defined by CPG-on-FHIR for Questionnaire canonical URI
Extension collectsWith = activityDefinition.getExtensionByUrl("http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-collectWith");
if (collectsWith != null && collectsWith.getValueAsPrimitive().toString() != null) {
CanonicalType uri = new CanonicalType(collectsWith.getValueAsPrimitive().toString());
input.setValue(uri);
}
if (activityDefinition.hasRelatedArtifact()) {
for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
if (artifact.hasUrl()) {
Attachment attachment = new Attachment().setUrl(artifact.getUrl());
if (artifact.hasDisplay()) {
attachment.setTitle(artifact.getDisplay());
}
input.setValue(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
}
// TODO - other relatedArtifact types
}
}
// If input has been populated, then add it to the Task.
if (input.getType() != null || input.getValue() != null) {
task.addInput(input);
}
return task;
}
use of org.hl7.fhir.r5.model.Questionnaire in project cqf-ruler by DBCG.
the class ExtractProvider method getQuestionnaireCodeMap.
private Map<String, Coding> getQuestionnaireCodeMap(String questionnaireUrl) {
String url = mySdcProperties.getExtract().getEndpoint();
if (null == url || url.length() < 1) {
throw new IllegalArgumentException("Unable to transmit observation bundle. No observation.endpoint defined in sdc properties.");
}
String user = mySdcProperties.getExtract().getUsername();
String password = mySdcProperties.getExtract().getPassword();
IGenericClient client = Clients.forUrl(myFhirContext, url);
Clients.registerBasicAuth(client, user, password);
Questionnaire questionnaire = client.read().resource(Questionnaire.class).withUrl(questionnaireUrl).execute();
return createCodeMap(questionnaire);
}
Aggregations