use of org.hl7.fhir.r4b.model.DataType in project kindling by HL7.
the class DictHTMLGenerator method encodeValue.
private String encodeValue(DataType value) throws Exception {
if (value == null || value.isEmpty())
return null;
if (value instanceof PrimitiveType)
return Utilities.escapeXml(((PrimitiveType) value).asStringValue());
ByteArrayOutputStream bs = new ByteArrayOutputStream();
XmlParser parser = new XmlParser();
parser.setOutputStyle(OutputStyle.PRETTY);
parser.compose(bs, null, value);
String[] lines = bs.toString().split("\\r?\\n");
StringBuilder b = new StringBuilder();
for (String s : lines) {
if (!Utilities.noString(s) && !s.startsWith("<?")) {
// eliminate the xml header
b.append(Utilities.escapeXml(s).replace(" ", " ") + "<br/>");
}
}
return b.toString();
}
use of org.hl7.fhir.r4b.model.DataType in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandler method evaluateMeasure.
@POST
@Path("/evaluation")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Evaluates a measure bundle for a single patient", notes = EVALUATION_API_NOTES, response = String.class, tags = { "Measure Evaluation" }, nickname = "evaluate_measure", extensions = { @Extension(properties = { @ExtensionProperty(name = DarkFeatureSwaggerFilter.DARK_FEATURE_NAME, value = CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION) }) })
@ApiImplicitParams({ // This is necessary for the dark launch feature
@ApiImplicitParam(access = DarkFeatureSwaggerFilter.DARK_FEATURE_CONTROLLED, paramType = "header", dataType = "string"), // These are necessary to create a proper view of the request body that is all wrapped up in the Liberty IMultipartBody parameter
@ApiImplicitParam(name = REQUEST_DATA_PART, value = EXAMPLE_REQUEST_DATA_JSON, dataTypeClass = MeasureEvaluation.class, required = true, paramType = "form", type = "file"), @ApiImplicitParam(name = MEASURE_PART, value = EXAMPLE_MEASURE_ZIP, dataTypeClass = File.class, required = true, paramType = "form", type = "file") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful Operation: This API returns the JSON representation of a FHIR MeasureReport. A full example can be found at https://www.hl7.org/fhir/measurereport-cms146-cat1-example.html"), @ApiResponse(code = 400, message = "Bad Request", response = ServiceErrorList.class), @ApiResponse(code = 500, message = "Server Error", response = ServiceErrorList.class) })
public Response evaluateMeasure(@Context HttpServletRequest request, @ApiParam(value = ServiceBaseConstants.MINOR_VERSION_DESCRIPTION, required = true, defaultValue = ServiceBuildConstants.DATE) @QueryParam(CohortEngineRestHandler.VERSION) String version, @ApiParam(hidden = true, type = "file", required = true) IMultipartBody multipartBody) {
final String methodName = MethodNames.EVALUATE_MEASURE.getName();
Response response = null;
// Error out if feature is not enabled
ServiceBaseUtility.isDarkFeatureEnabled(CohortEngineRestConstants.DARK_LAUNCHED_MEASURE_EVALUATION);
try {
// Perform api setup
Response errorResponse = ServiceBaseUtility.apiSetup(version, logger, methodName);
if (errorResponse != null) {
return errorResponse;
}
if (multipartBody == null) {
throw new IllegalArgumentException("A multipart/form-data body is required");
}
IAttachment metadataAttachment = multipartBody.getAttachment(REQUEST_DATA_PART);
if (metadataAttachment == null) {
throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", REQUEST_DATA_PART));
}
IAttachment measureAttachment = multipartBody.getAttachment(MEASURE_PART);
if (measureAttachment == null) {
throw new IllegalArgumentException(String.format("Missing '%s' MIME attachment", MEASURE_PART));
}
// deserialize the MeasuresEvaluation request
ObjectMapper om = new ObjectMapper();
MeasureEvaluation evaluationRequest = om.readValue(metadataAttachment.getDataHandler().getInputStream(), MeasureEvaluation.class);
// validate the contents of the evaluationRequest
validateBean(evaluationRequest);
FhirContext fhirContext = FhirContext.forR4();
try (InputStream is = measureAttachment.getDataHandler().getInputStream();
RetrieveCacheContext retrieveCacheContext = new DefaultRetrieveCacheContext()) {
MeasureEvaluator evaluator = createMeasureEvaluator(is, evaluationRequest.getDataServerConfig(), evaluationRequest.getTerminologyServerConfig(), evaluationRequest.isExpandValueSets(), evaluationRequest.getSearchPageSize(), retrieveCacheContext, fhirContext);
MeasureReport report = evaluator.evaluatePatientMeasure(evaluationRequest.getPatientId(), evaluationRequest.getMeasureContext(), evaluationRequest.getEvidenceOptions());
// The default serializer gets into an infinite loop when trying to serialize MeasureReport, so we use the
// HAPI encoder instead.
IParser parser = fhirContext.newJsonParser();
ResponseBuilder responseBuilder = Response.status(Response.Status.OK).header("Content-Type", "application/json").entity(parser.encodeResourceToString(report));
response = responseBuilder.build();
}
} catch (Throwable e) {
// map any exceptions caught into the proper REST error response objects
response = new CohortServiceExceptionMapper().toResponse(e);
} finally {
// Perform api cleanup
Response errorResponse = ServiceBaseUtility.apiCleanup(logger, methodName);
if (errorResponse != null) {
response = errorResponse;
}
}
return response;
}
use of org.hl7.fhir.r4b.model.DataType in project quality-measure-and-cohort-service by Alvearie.
the class SparkCqlEvaluator method createDataTypeAliases.
private Map<String, String> createDataTypeAliases(List<ContextDefinition> filteredContexts, CqlToElmTranslator translator) {
Set<String> dataTypes = filteredContexts.stream().map(ContextDefinition::getPrimaryDataType).collect(Collectors.toSet());
Collection<ModelInfo> modelInfos = translator.getRegisteredModelInfos().values();
Map<String, String> dataTypeAliases = new HashMap<>();
for (ModelInfo modelInfo : modelInfos) {
modelInfo.getTypeInfo().stream().filter(ClassInfo.class::isInstance).map(ClassInfo.class::cast).filter(classInfo -> dataTypes.contains(classInfo.getName())).forEach(info -> {
String dataType = info.getName();
QName baseType = ModelUtils.getBaseTypeName(modelInfo, info);
if (baseType != null) {
// for inheritance types
dataTypeAliases.put(dataType, baseType.getLocalPart());
}
Collection<String> choiceTypes = ModelUtils.getChoiceTypeNames(info);
// for choice types
choiceTypes.forEach(choiceType -> dataTypeAliases.put(dataType, choiceType));
});
}
return dataTypeAliases;
}
use of org.hl7.fhir.r4b.model.DataType in project drug-formulary-ri by HL7-DaVinci.
the class PatientAuthorizationInterceptor method verify.
/**
* Helper method to verify and decode the access token
*
* @param token - the access token
* @param fhirBaseUrl - the base url of this FHIR server
* @return the base interface Patient ID datatype if the jwt token is verified
* and contains a patient ID in it claim, otherwise null.
* @throws SignatureVerificationException
* @throws TokenExpiredException
* @throws JWTVerificationException
*/
private IIdType verify(String token, String fhirBaseUrl) throws SignatureVerificationException, TokenExpiredException, JWTVerificationException {
Algorithm algorithm = Algorithm.RSA256(OauthEndpointController.getPublicKey(), null);
logger.fine("Verifying JWT token iss and aud is " + fhirBaseUrl);
JWTVerifier verifier = JWT.require(algorithm).withIssuer(fhirBaseUrl).withAudience(fhirBaseUrl).build();
DecodedJWT jwt = verifier.verify(token);
String patientId = jwt.getClaim("patient_id").asString();
if (patientId != null)
return new IdType("Patient", patientId);
return null;
}
use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.
the class ElementDefinition30_50 method convertElementDefinitionBindingComponent.
public static ElementDefinition.ElementDefinitionBindingComponent convertElementDefinitionBindingComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionBindingComponent src) throws FHIRException {
if (src == null)
return null;
ElementDefinition.ElementDefinitionBindingComponent tgt = new ElementDefinition.ElementDefinitionBindingComponent();
ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt, VersionConvertor_30_50.EXT_SRC_TYPE);
if (src.hasStrength())
tgt.setStrengthElement(Enumerations30_50.convertBindingStrength(src.getStrengthElement()));
if (src.hasDescription())
tgt.setDescriptionElement(String30_50.convertString(src.getDescriptionElement()));
if (src.hasValueSet()) {
DataType t = ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getValueSet());
if (t instanceof org.hl7.fhir.r5.model.Reference) {
tgt.setValueSet(((org.hl7.fhir.r5.model.Reference) t).getReference());
tgt.getValueSetElement().addExtension(VersionConvertor_30_50.EXT_SRC_TYPE, new org.hl7.fhir.r5.model.UrlType("Reference"));
} else {
tgt.setValueSet(t.primitiveValue());
tgt.getValueSetElement().addExtension(VersionConvertor_30_50.EXT_SRC_TYPE, new org.hl7.fhir.r5.model.UrlType("uri"));
}
tgt.setValueSet(VersionConvertorConstants.refToVS(tgt.getValueSet()));
}
return tgt;
}
Aggregations