Skip to content

Commit

Permalink
MAT-6785: more mappings for CqlLookups, update SimpleXML schema to ac…
Browse files Browse the repository at this point in the history
…count for some gaps and issues
  • Loading branch information
nmorasb committed Mar 5, 2024
1 parent 9660460 commit 777f375
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

package generated.gov.cms.madie.simplexml;

import java.util.ArrayList;
import java.util.List;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlType;

/**
Expand All @@ -21,7 +22,7 @@
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="lib" type="{}libType"/>
* <element name="lib" type="{}libType" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
Expand All @@ -34,24 +35,29 @@
propOrder = {"lib"})
public class AllUsedCQLLibsType {

@XmlElement(required = true)
protected LibType lib;
protected List<LibType> lib;

/**
* Gets the value of the lib property.
*
* @return possible object is {@link LibType }
*/
public LibType getLib() {
return lib;
}

/**
* Sets the value of the lib property.
* <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any
* modification you make to the returned list will be present inside the JAXB object. This is why
* there is not a <CODE>set</CODE> method for the lib property.
*
* <p>For example, to add a new item, do as follows:
*
* <pre>
* getLib().add(newItem);
* </pre>
*
* <p>Objects of the following type(s) are allowed in the list {@link LibType }
*
* @param value allowed object is {@link LibType }
* @return The value of the lib property.
*/
public void setLib(LibType value) {
this.lib = value;
public List<LibType> getLib() {
if (lib == null) {
lib = new ArrayList<>();
}
return this.lib;
}
}
36 changes: 21 additions & 15 deletions src/main/java/generated/gov/cms/madie/simplexml/ArgumentsType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

package generated.gov.cms.madie.simplexml;

import java.util.ArrayList;
import java.util.List;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlType;

/**
Expand All @@ -21,7 +22,7 @@
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="argument" type="{}argumentType"/>
* <element name="argument" type="{}argumentType" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
Expand All @@ -34,24 +35,29 @@
propOrder = {"argument"})
public class ArgumentsType {

@XmlElement(required = true)
protected ArgumentType argument;
protected List<ArgumentType> argument;

/**
* Gets the value of the argument property.
*
* @return possible object is {@link ArgumentType }
*/
public ArgumentType getArgument() {
return argument;
}

/**
* Sets the value of the argument property.
* <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any
* modification you make to the returned list will be present inside the JAXB object. This is why
* there is not a <CODE>set</CODE> method for the argument property.
*
* <p>For example, to add a new item, do as follows:
*
* <pre>
* getArgument().add(newItem);
* </pre>
*
* <p>Objects of the following type(s) are allowed in the list {@link ArgumentType }
*
* @param value allowed object is {@link ArgumentType }
* @return The value of the argument property.
*/
public void setArgument(ArgumentType value) {
this.argument = value;
public List<ArgumentType> getArgument() {
if (argument == null) {
argument = new ArrayList<>();
}
return this.argument;
}
}
36 changes: 21 additions & 15 deletions src/main/java/generated/gov/cms/madie/simplexml/ParametersType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

package generated.gov.cms.madie.simplexml;

import java.util.ArrayList;
import java.util.List;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlType;

/**
Expand All @@ -21,7 +22,7 @@
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="parameter" type="{}parameterType"/>
* <element name="parameter" type="{}parameterType" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
Expand All @@ -34,24 +35,29 @@
propOrder = {"parameter"})
public class ParametersType {

@XmlElement(required = true)
protected ParameterType parameter;
protected List<ParameterType> parameter;

/**
* Gets the value of the parameter property.
*
* @return possible object is {@link ParameterType }
*/
public ParameterType getParameter() {
return parameter;
}

/**
* Sets the value of the parameter property.
* <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any
* modification you make to the returned list will be present inside the JAXB object. This is why
* there is not a <CODE>set</CODE> method for the parameter property.
*
* <p>For example, to add a new item, do as follows:
*
* <pre>
* getParameter().add(newItem);
* </pre>
*
* <p>Objects of the following type(s) are allowed in the list {@link ParameterType }
*
* @param value allowed object is {@link ParameterType }
* @return The value of the parameter property.
*/
public void setParameter(ParameterType value) {
this.parameter = value;
public List<ParameterType> getParameter() {
if (parameter == null) {
parameter = new ArrayList<>();
}
return this.parameter;
}
}
8 changes: 5 additions & 3 deletions src/main/java/gov/cms/madie/resources/PackageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gov.cms.madie.services.PackagingService;
import gov.cms.madie.models.measure.Measure;
import gov.cms.madie.services.SimpleXmlService;
import gov.cms.madie.services.TranslationServiceClient;
import jakarta.xml.bind.JAXBException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -28,6 +29,7 @@ public class PackageController {
private final PackagingService packagingService;
private final SimpleXmlService simpleXmlService;
private final HqmfService hqmfService;
private final TranslationServiceClient translationServiceClient;

@PutMapping(
value = "/package",
Expand Down Expand Up @@ -56,9 +58,9 @@ public String getMeasureSimpleXml(
@RequestHeader("Authorization") String accessToken)
throws JAXBException {
if (measure.getModel() != null && measure.getModel().contains("QDM")) {
// TODO: replace this with fetch CqlLookups from translator
CqlLookups cqlLookups = CqlLookups.builder().build();
return simpleXmlService.measureToSimpleXml((QdmMeasure) measure, cqlLookups);
QdmMeasure qdmMeasure = (QdmMeasure) measure;
CqlLookups cqlLookups = translationServiceClient.getCqlLookups(qdmMeasure, accessToken);
return simpleXmlService.measureToSimpleXml(qdmMeasure, cqlLookups);
}
throw new UnsupportedModelException("Unsupported model type: " + measure.getModel());
}
Expand Down
115 changes: 114 additions & 1 deletion src/main/java/gov/cms/madie/services/MeasureMapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package gov.cms.madie.services;

import generated.gov.cms.madie.simplexml.*;
import gov.cms.madie.dto.CQLCode;
import gov.cms.madie.dto.CQLCodeSystem;
import gov.cms.madie.dto.CQLDefinition;
import gov.cms.madie.dto.CQLFunctionArgument;
import gov.cms.madie.dto.CQLParameter;
import gov.cms.madie.dto.CqlLookups;
import gov.cms.madie.models.common.Organization;
import gov.cms.madie.models.common.Version;
import gov.cms.madie.models.measure.BaseConfigurationTypes;
Expand Down Expand Up @@ -29,17 +35,20 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface MeasureMapper {

@Mapping(target = "cqlLookUp", source = "cqlLookups")
@Mapping(target = "measureDetails", source = "measure")
@Mapping(target = "measureGrouping", source = "measure")
@Mapping(target = "supplementalDataElements", source = "measure.supplementalData")
@Mapping(target = "riskAdjustmentVariables", source = "measure.riskAdjustments")
MeasureType measureToMeasureType(QdmMeasure measure);
MeasureType measureToMeasureType(QdmMeasure measure, CqlLookups cqlLookups);

@Mapping(target = "title", source = "measureName")
@Mapping(target = "measureModel", source = "model")
Expand Down Expand Up @@ -359,4 +368,108 @@ default FinalizedDateType instantToFinalizedDateType(Measure measure) {
.format(measure.getLastModifiedAt()));
return finalizedDateType;
}

@Mapping(target = "definitions", source = "definitions")
@Mapping(target = "functions", source = "definitions")
CqlLookUpType cqlLookupsToCqlLookUpType(CqlLookups cqlLookups);

default CodeSystemsType cqlCodeSystemsToCodeSystemsType(Set<CQLCodeSystem> codeSystems) {
if (!CollectionUtils.isEmpty(codeSystems)) {
CodeSystemsType codeSystemsType = new CodeSystemsType();
codeSystemsType.getCodeSystem().addAll(cqlCodeSystemsToCodeSystems(codeSystems));
return codeSystemsType;
}

return null;
}

default CodesType cqlCodesToCodesType(Set<CQLCode> cqlCodes) {
if (!CollectionUtils.isEmpty(cqlCodes)) {
CodesType codesType = new CodesType();
codesType.getCode().addAll(cqlCodesToCodes(cqlCodes));
return codesType;
}

return null;
}

default ParametersType cqlParametersToParametersType(Set<CQLParameter> cqlParameters) {
if (!CollectionUtils.isEmpty(cqlParameters)) {
ParametersType parametersType = new ParametersType();
parametersType.getParameter().addAll(cqlParametersToParameterTypes(cqlParameters));
return parametersType;
}
return null;
}

List<ParameterType> cqlParametersToParameterTypes(Set<CQLParameter> cqlParameters);

default DefinitionsType cqlDefinitionsToDefinitionsType(Set<CQLDefinition> cqlDefinitions) {
if (!CollectionUtils.isEmpty(cqlDefinitions)) {
Set<CQLDefinition> defsWithoutFuncs =
cqlDefinitions.stream().filter(d -> !d.isFunction()).collect(Collectors.toSet());
if (!CollectionUtils.isEmpty(defsWithoutFuncs)) {
DefinitionsType definitionsType = new DefinitionsType();
definitionsType.getDefinition().addAll(cqlDefinitionsToDefinitionTypes(defsWithoutFuncs));
return definitionsType;
}
}

return null;
}

default FunctionsType cqlDefinitionsToFunctionsType(Set<CQLDefinition> cqlDefinitions) {
if (!CollectionUtils.isEmpty(cqlDefinitions)) {
Set<CQLDefinition> defsOnlyFuncs =
cqlDefinitions.stream().filter(CQLDefinition::isFunction).collect(Collectors.toSet());
if (!CollectionUtils.isEmpty(defsOnlyFuncs)) {
FunctionsType functionsType = new FunctionsType();
functionsType.getFunction().addAll(cqlDefinitionsToFunctionTypes(defsOnlyFuncs));
return functionsType;
}
}

return null;
}

List<CodeSystemType> cqlCodeSystemsToCodeSystems(Set<CQLCodeSystem> codeSystems);

List<CodeType> cqlCodesToCodes(Set<CQLCode> cqlCodes);

@Mapping(
target = "codeSystemOID",
expression =
"java(org.apache.commons.lang3.StringUtils.replaceChars(cqlCode.getCodeSystemOID(), \"urn:oid:\",\"\"))")
@Mapping(target = "codeOID", source = "id")
@Mapping(target = "isValidatedWithVsac", source = "isValidatedWithVsac")
@Mapping(
target = "isCodeSystemVersionIncluded",
expression = "java(String.valueOf(cqlCode.isCodeSystemVersionIncluded()))")
CodeType cqlCodeToCodeType(CQLCode cqlCode);

List<DefinitionType> cqlDefinitionsToDefinitionTypes(Set<CQLDefinition> cqlDefinitions);

List<FunctionType> cqlDefinitionsToFunctionTypes(Set<CQLDefinition> cqlDefinitions);

@Mapping(target = "logic", source = "definitionLogic")
DefinitionType cqlDefinitionToDefinitionType(CQLDefinition cqlDefinition);

@Mapping(target = "logic", source = "definitionLogic")
@Mapping(target = "arguments", source = "functionArguments")
FunctionType cqlDefinitionToFunctionType(CQLDefinition cqlDefinition);

default ArgumentsType functionArgumentsToArgumentsType(
List<CQLFunctionArgument> functionArguments) {
if (!CollectionUtils.isEmpty(functionArguments)) {
ArgumentsType argumentsType = new ArgumentsType();
argumentsType.getArgument().addAll(functionArgumentsToArgumentTypes(functionArguments));
return argumentsType;
}
return null;
}

List<ArgumentType> functionArgumentsToArgumentTypes(List<CQLFunctionArgument> functionArguments);

@Mapping(target = "type", source = "argumentType")
ArgumentType functionArgumentToArgumentType(CQLFunctionArgument functionArguments);
}
2 changes: 1 addition & 1 deletion src/main/java/gov/cms/madie/services/SimpleXmlService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SimpleXmlService {
public String measureToSimpleXml(QdmMeasure measure, CqlLookups cqlLookups) throws JAXBException {
StringWriter sw = new StringWriter();
if (measure != null) {
MeasureType measureType = measureMapper.measureToMeasureType(measure);
MeasureType measureType = measureMapper.measureToMeasureType(measure, cqlLookups);
JAXBElement<MeasureType> jaxbElement =
new JAXBElement<>(new QName(null, "measure"), MeasureType.class, measureType);
simpleXmlMarshaller.marshal(jaxbElement, sw);
Expand Down
Loading

0 comments on commit 777f375

Please sign in to comment.