
001package org.hl7.fhir.r4.terminologies; 002 003import org.hl7.fhir.r4.context.IWorkerContext; 004import org.hl7.fhir.r4.model.*; 005 006public class ConceptTranslationEngine { 007 private final IWorkerContext context; 008 009 public ConceptTranslationEngine(IWorkerContext worker) { 010 this.context = worker; 011 } 012 013 public Parameters translateCode(String s, ConceptMap cm) { 014 Parameters p = new Parameters(); 015 boolean matched = false; 016 for (ConceptMap.ConceptMapGroupComponent grp : cm.getGroup()) { 017 for (ConceptMap.SourceElementComponent src : grp.getElement()) { 018 if (src.getCode().equals(s)) { 019 for (ConceptMap.TargetElementComponent tgt : src.getTarget()) { 020 matched = true; 021 Parameters.ParametersParameterComponent match = p.addParameter(); 022 match.setName("match"); 023 match.addPart().setName("equivalence").setValue(new CodeType(tgt.getEquivalence().toCode())); 024 match.addPart().setName("concept").setValue(new Coding().setCode(tgt.getCode()).setSystem(grp.getTarget())); 025 // todo: dependencies and products 026 } 027 } 028 } 029 } 030 // todo: unmapped 031 p.addParameter("result", matched); 032 return p; 033 } 034 035 public Parameters translateCoding(Coding coding, ConceptMap cm) { 036 Parameters p = new Parameters(); 037 boolean matched = false; 038 for (ConceptMap.ConceptMapGroupComponent grp : cm.getGroup()) { 039 if (grp.getSourceElement().equals(coding.getSystem())) { 040 for (ConceptMap.SourceElementComponent src : grp.getElement()) { 041 if (src.getCode().equals(coding.getCode())) { 042 for (ConceptMap.TargetElementComponent tgt : src.getTarget()) { 043 matched = true; 044 Parameters.ParametersParameterComponent match = p.addParameter(); 045 match.setName("match"); 046 match.addPart().setName("equivalence").setValue(new CodeType(tgt.getEquivalence().toCode())); 047 match.addPart().setName("concept").setValue(new Coding().setCode(tgt.getCode()).setSystem(grp.getTarget())); 048 // todo: dependencies and products 049 } 050 } 051 } 052 } 053 } 054 // todo: unmapped 055 p.addParameter("result", matched); 056 return p; 057 } 058}