use of org.hl7.fhir.r4.model.CanonicalType in project pathling by aehrc.
the class ConformanceProvider method buildResources.
@Nonnull
private List<CapabilityStatementRestResourceComponent> buildResources() {
final List<CapabilityStatementRestResourceComponent> resources = new ArrayList<>();
final Set<ResourceType> supported = FhirServer.supportedResourceTypes();
final Set<ResourceType> supportedResourceTypes = supported.isEmpty() ? EnumSet.noneOf(ResourceType.class) : EnumSet.copyOf(supported);
for (final ResourceType resourceType : supportedResourceTypes) {
final CapabilityStatementRestResourceComponent resource = new CapabilityStatementRestResourceComponent(new CodeType(resourceType.toCode()));
resource.setProfile(FHIR_RESOURCE_BASE + resourceType.toCode());
// Add the search operation to all resources.
final ResourceInteractionComponent search = new ResourceInteractionComponent();
search.setCode(TypeRestfulInteraction.SEARCHTYPE);
resource.getInteraction().add(search);
// Add the create and update operations to all resources.
final ResourceInteractionComponent create = new ResourceInteractionComponent();
final ResourceInteractionComponent update = new ResourceInteractionComponent();
create.setCode(TypeRestfulInteraction.CREATE);
update.setCode(TypeRestfulInteraction.UPDATE);
resource.getInteraction().add(create);
resource.getInteraction().add(update);
// Add the `aggregate` operation to all resources.
final CanonicalType aggregateOperationUri = new CanonicalType(getOperationUri("aggregate"));
final CapabilityStatementRestResourceOperationComponent aggregateOperation = new CapabilityStatementRestResourceOperationComponent(new StringType("aggregate"), aggregateOperationUri);
resource.addOperation(aggregateOperation);
// Add the `fhirPath` search parameter to all resources.
final CapabilityStatementRestResourceOperationComponent searchOperation = new CapabilityStatementRestResourceOperationComponent();
searchOperation.setName("fhirPath");
searchOperation.setDefinition(getOperationUri("search"));
resource.addOperation(searchOperation);
resources.add(resource);
}
// Add the read operation to the OperationDefinition resource.
final String opDefCode = ResourceType.OPERATIONDEFINITION.toCode();
final CapabilityStatementRestResourceComponent opDefResource = new CapabilityStatementRestResourceComponent(new CodeType(opDefCode));
opDefResource.setProfile(FHIR_RESOURCE_BASE + opDefCode);
final ResourceInteractionComponent readInteraction = new ResourceInteractionComponent();
readInteraction.setCode(TypeRestfulInteraction.READ);
opDefResource.addInteraction(readInteraction);
resources.add(opDefResource);
return resources;
}
use of org.hl7.fhir.r4.model.CanonicalType in project eCRNow by drajer-health.
the class ApplicationUtils method getCovidValueSetByIds.
public static Set<ValueSet> getCovidValueSetByIds(List<CanonicalType> valueSetIdList) {
Set<ValueSet> valueSets = new HashSet<>();
if (Optional.ofNullable(valueSetIdList).isPresent()) {
for (CanonicalType canonicalType : valueSetIdList) {
logger.debug("Checking Value set {}", canonicalType.getValueAsString());
for (ValueSet valueSet : ValueSetSingleton.getInstance().getValueSets()) {
if (valueSet.getId().equalsIgnoreCase(canonicalType.getValueAsString()) && isACovidValueSet(valueSet)) {
logger.debug("Found a Covid Value Set for Grouper using Id {}", valueSet.getId());
valueSets.add(valueSet);
break;
} else if ((valueSet.getUrl() != null) && (valueSet.getUrl().equalsIgnoreCase(canonicalType.getValueAsString())) && isACovidValueSet(valueSet)) {
logger.debug("Urls Matched for a Covid Value Set {}", valueSet.getId());
valueSets.add(valueSet);
break;
}
}
for (ValueSet valueSet : ValueSetSingleton.getInstance().getCovidValueSets()) {
if (valueSet.getId().equalsIgnoreCase(canonicalType.getValueAsString()) && isACovidValueSet(valueSet)) {
logger.debug("Found a Covid Value Set for Grouper using Id {}", valueSet.getId());
valueSets.add(valueSet);
break;
} else if ((valueSet.getUrl() != null) && (valueSet.getUrl().equalsIgnoreCase(canonicalType.getValueAsString())) && isACovidValueSet(valueSet)) {
logger.debug("Urls Matched for a Covid Value Set {}", valueSet.getId());
valueSets.add(valueSet);
break;
}
}
}
}
return valueSets;
}
use of org.hl7.fhir.r4.model.CanonicalType in project eCRNow by drajer-health.
the class ValueSetServiceImpl method createValueSetGrouper.
@Override
public void createValueSetGrouper(ValueSet valueSet) {
List<CanonicalType> valuesetList = null;
ValueSetGrouperModel valueSetGrouperModel = null;
ValueSetComposeComponent valueSetComposeComponent = valueSet.getCompose();
List<ConceptSetComponent> conceptSetComponentList = valueSetComposeComponent.getInclude();
for (ConceptSetComponent conceptSetComponent : conceptSetComponentList) {
valuesetList = conceptSetComponent.getValueSet();
for (CanonicalType canonicalType : valuesetList) {
valueSetGrouperModel = new ValueSetGrouperModel();
valueSetGrouperModel.setValueSetGrouper(valueSet.getUrl());
valueSetGrouperModel.setValueSetId(canonicalType.getValueAsString());
valueSetDao.createValuesetGrouper(valueSetGrouperModel);
}
}
}
use of org.hl7.fhir.r4.model.CanonicalType in project eCRNow by drajer-health.
the class ActionData method print.
public void print() {
if (logger.isInfoEnabled()) {
logger.info(" *** Printing Action Data *** ");
if (fhirDataType != null)
logger.info(" Fhir Data Type = {}", fhirDataType.toString());
if (triggerType != null)
logger.info(" Trigger Type = {}", triggerType.toString());
logger.info(" Path = {}", path);
if (valueSet != null)
logger.info(" ValueSet Canonical URL = {}", valueSet.getValue());
if (profiles != null) {
for (CanonicalType ct : profiles) {
logger.info(" Profile Name = {}", ct.getValue());
}
}
logger.info(" *** End Printing Action Data *** ");
}
}
use of org.hl7.fhir.r4.model.CanonicalType in project redmatch by aehrc.
the class FhirExporter method getValue.
/**
* Resolves a value.
*
* @param value The value specified in the transformation rules.
* @param fhirType The type of the FHIR attribute where this value will be set.
* @param vertex A vertex with patient data.
* @param recordId The id of this record. Used to create the references to FHIR ids.
* @param enumFactory If the type is an enumeration, this is the factory to create an instance.
* @param fhirPackage The target FHIR package.
* @return The value or null if the value cannot be determined. This can also be a list.
*/
private Base getValue(Value value, Class<?> fhirType, JsonObject vertex, String recordId, Class<?> enumFactory, VersionedFhirPackage fhirPackage) throws IOException {
// If this is a field-based value then make sure that there is a value and if not return null
if (value instanceof FieldBasedValue) {
FieldBasedValue fbv = (FieldBasedValue) value;
// Account for field ids of the form xx___y
String fieldId = fbv.getFieldId();
String shortFieldId = null;
String regex = "(?<fieldId>.*)___\\d+$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(fieldId);
if (matcher.find()) {
shortFieldId = matcher.group("fieldId");
log.debug("Transformed fieldId into '" + fieldId + "'");
}
boolean hasValue = false;
JsonElement jsonElement = vertex.get(fieldId);
if (jsonElement != null) {
String rawValue = jsonElement.getAsString();
if (!rawValue.isEmpty()) {
hasValue = true;
}
}
if (!hasValue && shortFieldId != null) {
jsonElement = vertex.get(shortFieldId);
if (jsonElement != null) {
String rawValue = jsonElement.getAsString();
if (!rawValue.isEmpty()) {
hasValue = true;
}
}
}
if (!hasValue) {
return null;
}
}
if (value instanceof BooleanValue) {
return new BooleanType(((BooleanValue) value).getValue());
} else if (value instanceof CodeLiteralValue) {
String code = ((CodeLiteralValue) value).getCode();
return getCode(code, enumFactory);
} else if (value instanceof ConceptLiteralValue) {
ConceptLiteralValue clv = (ConceptLiteralValue) value;
String system = clv.getSystem();
String code = clv.getCode();
String display = clv.getDisplay() != null ? clv.getDisplay() : "";
return getConcept(system, code, display, fhirType);
} else if (value instanceof DoubleValue) {
return new DecimalType(((DoubleValue) value).getValue());
} else if (value instanceof IntegerValue) {
return new IntegerType(((IntegerValue) value).getValue());
} else if (value instanceof ReferenceValue) {
ReferenceValue rv = (ReferenceValue) value;
Reference ref = new Reference();
String resourceType = rv.getResourceType();
String resourceId = rv.getResourceId();
boolean unique = uniqueIds.contains(resourceType + "<" + resourceId + ">");
CodeInfo codeInfo = terminologyService.lookup(fhirPackage, resourceType);
if (codeInfo.isProfile()) {
resourceType = StringUtils.getLastPath(codeInfo.getBaseResource());
}
if (unique) {
// This is a reference to a unique resource - no need to append row id
if (fhirResourceMap.containsKey(resourceId)) {
ref.setReference("/" + resourceType + "/" + resourceId);
} else {
log.debug("Did not find resource " + resourceType + "/" + resourceId);
}
} else {
if (fhirResourceMap.containsKey(resourceId + "-" + recordId)) {
ref.setReference("/" + resourceType + "/" + resourceId + "-" + recordId);
} else {
log.debug("Did not find resource " + resourceType + "/" + resourceId + "-" + recordId);
}
}
return ref;
} else if (value instanceof StringValue) {
if (fhirType.equals(StringType.class)) {
return new StringType(((StringValue) value).getStringValue());
} else if (fhirType.equals(MarkdownType.class)) {
return new MarkdownType(((StringValue) value).getStringValue());
} else if (fhirType.equals(IdType.class)) {
return new IdType(((StringValue) value).getStringValue());
} else if (fhirType.equals(UriType.class)) {
return new UriType(((StringValue) value).getStringValue());
} else if (fhirType.equals(OidType.class)) {
return new OidType(((StringValue) value).getStringValue());
} else if (fhirType.equals(UuidType.class)) {
return new UuidType(((StringValue) value).getStringValue());
} else if (fhirType.equals(CanonicalType.class)) {
return new CanonicalType(((StringValue) value).getStringValue());
} else if (fhirType.equals(UrlType.class)) {
return new UrlType(((StringValue) value).getStringValue());
} else {
throw new TransformationException("Got StringValue for FHIR type " + fhirType.getName() + ". This should not happen!");
}
} else if (value instanceof CodeSelectedValue) {
CodeSelectedValue csv = (CodeSelectedValue) value;
String fieldId = csv.getFieldId();
Mapping m = getSelectedMapping(fieldId, vertex);
if (m == null) {
throw new TransformationException("Mapping for field " + fieldId + " is required but was not found.");
}
return getTarget(m).getCodeElement();
} else if (value instanceof ConceptSelectedValue) {
ConceptSelectedValue csv = (ConceptSelectedValue) value;
String fieldId = csv.getFieldId();
Mapping m = getSelectedMapping(fieldId, vertex);
if (m == null) {
throw new TransformationException("Mapping for field " + fieldId + " is required but was not found.");
}
if (fhirType.isAssignableFrom(Coding.class)) {
return getTarget(m);
} else if (fhirType.isAssignableFrom(CodeableConcept.class)) {
return new CodeableConcept().addCoding(getTarget(m));
} else {
throw new TransformationException("FHIR type of field " + fieldId + " (" + fhirType + ") is incompatible with CONCEPT_SELECTED.");
}
} else if (value instanceof ConceptValue) {
// Ontoserver REDCap plugin format: 74400008|Appendicitis|http://snomed.info/sct
ConceptValue cv = (ConceptValue) value;
String fieldId = cv.getFieldId();
Mapping m = getMapping(fieldId);
if (m != null) {
if (fhirType.isAssignableFrom(Coding.class)) {
return getTarget(m);
} else if (fhirType.isAssignableFrom(CodeableConcept.class)) {
return new CodeableConcept().addCoding(getTarget(m));
} else {
throw new TransformationException("FHIR type of field " + fieldId + " (" + fhirType + ") is incompatible with CONCEPT.");
}
} else {
au.csiro.redmatch.model.Field field = doc.getSchema().getField(fieldId);
Coding c = field.getCoding(vertex);
if (c != null) {
if (fhirType.isAssignableFrom(Coding.class)) {
return c;
} else if (fhirType.isAssignableFrom(CodeableConcept.class)) {
return new CodeableConcept().addCoding(c);
} else {
throw new TransformationException("FHIR type of field " + fieldId + " (" + fhirType + ") is incompatible with CONCEPT.");
}
}
}
throw new TransformationException("Could not get concept for field " + fieldId + ".");
} else if (value instanceof FieldValue) {
FieldValue fv = (FieldValue) value;
String fieldId = fv.getFieldId();
FieldValue.DatePrecision pr = fv.getDatePrecision();
au.csiro.redmatch.model.Field field = doc.getSchema().getField(fieldId);
return field.getValue(vertex, fhirType, pr);
} else {
throw new TransformationException("Unable to get VALUE for " + value);
}
}
Aggregations