001package org.hl7.fhir.validation;
002
003import org.hl7.fhir.exceptions.FHIRException;
004import org.hl7.fhir.r5.context.SimpleWorkerContext;
005import org.hl7.fhir.r5.elementmodel.Manager;
006import org.hl7.fhir.r5.model.Base;
007import org.hl7.fhir.r5.model.Coding;
008import org.hl7.fhir.r5.model.StructureDefinition;
009import org.hl7.fhir.r5.terminologies.ConceptMapEngine;
010import org.hl7.fhir.r5.utils.structuremap.ITransformerServices;
011
012import java.io.PrintWriter;
013import java.util.List;
014
015public class TransformSupportServices implements ITransformerServices {
016
017  private final PrintWriter mapLog;
018  private final SimpleWorkerContext context;
019  private List<Base> outputs;
020
021  public TransformSupportServices(List<Base> outputs,
022                                  PrintWriter mapLog,
023                                  SimpleWorkerContext context) {
024    this.outputs = outputs;
025    this.mapLog = mapLog;
026    this.context = context;
027  }
028
029  @Override
030  public void log(String message) {
031    if (mapLog != null)
032      mapLog.println(message);
033    System.out.println(message);
034  }
035
036  @Override
037  public Base createType(Object appInfo, String name) throws FHIRException {
038    StructureDefinition sd = context.fetchResource(StructureDefinition.class, name);
039    return Manager.build(context, sd);
040  }
041
042  @Override
043  public Base createResource(Object appInfo, Base res, boolean atRootofTransform) {
044    if (atRootofTransform)
045      outputs.add(res);
046    return res;
047  }
048
049  @Override
050  public Coding translate(Object appInfo, Coding source, String conceptMapUrl) throws FHIRException {
051    ConceptMapEngine cme = new ConceptMapEngine(context);
052    return cme.translate(source, conceptMapUrl);
053  }
054
055  @Override
056  public Base resolveReference(Object appContext, String url) throws FHIRException {
057    throw new FHIRException("resolveReference is not supported yet");
058  }
059
060  @Override
061  public List<Base> performSearch(Object appContext, String url) throws FHIRException {
062    throw new FHIRException("performSearch is not supported yet");
063  }
064}