use of org.hl7.fhir.r5.formats.IParser in project clinical_quality_language by cqframework.
the class DataRequirementsProcessorTest method TestLibraryDataRequirementsRecursive.
@Test
public void TestLibraryDataRequirementsRecursive() {
CqlTranslatorOptions cqlTranslatorOptions = new CqlTranslatorOptions();
cqlTranslatorOptions.getFormats().add(CqlTranslator.Format.JSON);
cqlTranslatorOptions.setCollapseDataRequirements(true);
try {
CqlTranslator translator = createTranslator("DataRequirements/DataRequirementsLibraryTest.cql", cqlTranslatorOptions);
translator.toELM();
assertTrue(translator.getErrors().isEmpty());
libraryManager.cacheLibrary(translator.getTranslatedLibrary());
DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor();
org.hl7.fhir.r5.model.Library moduleDefinitionLibrary = dqReqTrans.gatherDataRequirements(libraryManager, translator.getTranslatedLibrary(), cqlTranslatorOptions, null, false);
assertTrue(moduleDefinitionLibrary.getType().getCode("http://terminology.hl7.org/CodeSystem/library-type").equalsIgnoreCase("module-definition"));
DataRequirement encounterRequirement = null;
for (DataRequirement dr : moduleDefinitionLibrary.getDataRequirement()) {
if (dr.getType() == Enumerations.FHIRAllTypes.ENCOUNTER) {
encounterRequirement = dr;
break;
}
}
assertTrue(encounterRequirement != null);
FhirContext context = getFhirContext();
IParser parser = context.newJsonParser();
String moduleDefString = parser.setPrettyPrint(true).encodeResourceToString(moduleDefinitionLibrary);
logger.debug(moduleDefString);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
use of org.hl7.fhir.r5.formats.IParser in project cqf-ruler by DBCG.
the class STU3CarePlanToCdsCard method convert.
private static List<CdsCard> convert(RequestGroup requestGroup) {
List<CdsCard> cards = new ArrayList<>();
// links
List<CdsCard.Links> links = new ArrayList<>();
if (requestGroup.hasExtension()) {
for (Extension extension : requestGroup.getExtension()) {
CdsCard.Links link = new CdsCard.Links();
if (extension.getValue() instanceof Attachment) {
Attachment attachment = (Attachment) extension.getValue();
if (attachment.hasUrl()) {
link.setUrl(attachment.getUrl());
}
if (attachment.hasTitle()) {
link.setLabel(attachment.getTitle());
}
if (attachment.hasExtension()) {
link.setType(attachment.getExtensionFirstRep().getValue().primitiveValue());
}
} else {
throw new RuntimeException("Invalid link extension type: " + extension.getValue().fhirType());
}
links.add(link);
}
}
if (requestGroup.hasAction()) {
for (RequestGroup.RequestGroupActionComponent action : requestGroup.getAction()) {
IParser jsonParser = FhirContext.forCached(FhirVersionEnum.DSTU3).newJsonParser().setPrettyPrint(true);
CdsCard card = new CdsCard(jsonParser);
// basic
if (action.hasTitle()) {
card.setSummary(action.getTitle());
}
if (action.hasDescription()) {
card.setDetail(action.getDescription());
}
if (action.hasExtension()) {
card.setIndicator(action.getExtensionFirstRep().getValue().toString());
}
// source
if (action.hasDocumentation()) {
// Assuming first related artifact has everything
RelatedArtifact documentation = action.getDocumentationFirstRep();
CdsCard.Source source = new CdsCard.Source();
if (documentation.hasDisplay()) {
source.setLabel(documentation.getDisplay());
}
if (documentation.hasUrl()) {
source.setUrl(documentation.getUrl());
}
if (documentation.hasDocument() && documentation.getDocument().hasUrl()) {
source.setIcon(documentation.getDocument().getUrl());
}
card.setSource(source);
}
if (action.hasSelectionBehavior()) {
card.setSelectionBehavior(action.getSelectionBehavior().toCode());
}
// suggestions
// TODO - uuid
boolean hasSuggestions = false;
CdsCard.Suggestions suggestions = new CdsCard.Suggestions();
CdsCard.Suggestions.Action actions = new CdsCard.Suggestions.Action();
if (action.hasLabel()) {
suggestions.setLabel(action.getLabel());
hasSuggestions = true;
if (action.hasDescription()) {
actions.setDescription(action.getDescription());
}
if (action.hasType() && !action.getType().getCode().equals("fire-event")) {
String code = action.getType().getCode();
actions.setType(CdsCard.Suggestions.Action.ActionType.valueOf(code.equals("remove") ? "delete" : code));
}
if (action.hasResource()) {
if (actions.getType().name().equalsIgnoreCase("create")) {
action.getResourceTarget().setId((String) null);
}
actions.setResource(action.getResourceTarget());
}
}
if (hasSuggestions) {
suggestions.addAction(actions);
card.addSuggestion(suggestions);
}
if (!links.isEmpty()) {
card.setLinks(links);
}
cards.add(card);
}
}
return cards;
}
use of org.hl7.fhir.r5.formats.IParser in project beneficiary-fhir-data by CMSgov.
the class HHAClaimTransformerV2Test method before.
@BeforeEach
public void before() {
claim = generateClaim();
ExplanationOfBenefit genEob = HHAClaimTransformerV2.transform(new MetricRegistry(), claim, Optional.empty());
IParser parser = fhirContext.newJsonParser();
String json = parser.encodeResourceToString(genEob);
eob = parser.parseResource(ExplanationOfBenefit.class, json);
}
use of org.hl7.fhir.r5.formats.IParser in project beneficiary-fhir-data by CMSgov.
the class BeneficiaryTransformerV2Test method createPatient.
private void createPatient(RequestHeaders reqHeaders) {
Patient genPatient = BeneficiaryTransformerV2.transform(new MetricRegistry(), beneficiary, reqHeaders);
IParser parser = fhirContext.newJsonParser();
String json = parser.encodeResourceToString(genPatient);
patient = parser.parseResource(Patient.class, json);
}
use of org.hl7.fhir.r5.formats.IParser in project beneficiary-fhir-data by CMSgov.
the class SNFClaimTransformerV2Test method before.
@BeforeEach
public void before() {
claim = generateClaim();
ExplanationOfBenefit genEob = SNFClaimTransformerV2.transform(new MetricRegistry(), claim, Optional.empty());
IParser parser = fhirContext.newJsonParser();
String json = parser.encodeResourceToString(genEob);
eob = parser.parseResource(ExplanationOfBenefit.class, json);
}
Aggregations