Java源码示例:org.hl7.fhir.r4.model.CanonicalType
示例1
private void addReferenceQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, List<CanonicalType> profileURL, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
// var
// rn : String;
// i : integer;
// q : TFhirQuestionnaireGroupQuestion;
ToolingExtensions.addFhirType(group, "Reference");
QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.REFERENCE, path, "value", group.getText(), answerGroups);
group.setText(null);
CommaSeparatedStringBuilder rn = new CommaSeparatedStringBuilder();
for (UriType u : profileURL)
if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/"))
rn.append(u.getValue().substring(40));
if (rn.length() == 0)
ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
else {
ToolingExtensions.addAllowedResource(q, rn.toString());
ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
}
for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups)
ag.setText(null);
}
示例2
public static String readStringExtension(Element c, String uri) {
Extension ex = ExtensionHelper.getExtension(c, uri);
if (ex == null)
return null;
if (ex.getValue() instanceof UriType)
return ((UriType) ex.getValue()).getValue();
if (ex.getValue() instanceof CanonicalType)
return ((CanonicalType) ex.getValue()).getValue();
if (ex.getValue() instanceof CodeType)
return ((CodeType) ex.getValue()).getValue();
if (ex.getValue() instanceof IntegerType)
return ((IntegerType) ex.getValue()).asStringValue();
if ((ex.getValue() instanceof MarkdownType))
return ((MarkdownType) ex.getValue()).getValue();
if (!(ex.getValue() instanceof StringType))
return null;
return ((StringType) ex.getValue()).getValue();
}
示例3
public static org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent convertImplementationGuidePackageResourceComponent(org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageResourceComponent src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent tgt = new org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent();
VersionConvertor_14_40.copyElement(src, tgt);
if (src.hasExampleFor()) {
Type t = VersionConvertor_14_40.convertType(src.getExampleFor());
tgt.setExample(t instanceof org.hl7.fhir.r4.model.Reference ? new CanonicalType(((org.hl7.fhir.r4.model.Reference) t).getReference()) : t);
} else if (src.hasExample())
tgt.setExample(new org.hl7.fhir.r4.model.BooleanType(src.getExample()));
if (src.hasName())
tgt.setNameElement(VersionConvertor_14_40.convertString(src.getNameElement()));
if (src.hasDescription())
tgt.setDescriptionElement(VersionConvertor_14_40.convertString(src.getDescriptionElement()));
if (src.hasSourceReference())
tgt.setReference(VersionConvertor_14_40.convertReference(src.getSourceReference()));
else if (src.hasSourceUriType())
tgt.setReference(new org.hl7.fhir.r4.model.Reference(src.getSourceUriType().getValue()));
return tgt;
}
示例4
public Object evaluateInContext(DomainResource instance, String cql, String patientId) {
Iterable<CanonicalType> libraries = getLibraryReferences(instance);
String source = String.format(
"library LocalLibrary using FHIR version '4.0.0' include FHIRHelpers version '4.0.0' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s",
buildIncludes(libraries), instance.fhirType(), instance.fhirType(), instance.fhirType(), cql);
LibraryLoader libraryLoader = LibraryHelper.createLibraryLoader(this.getLibraryResourceProvider());
org.cqframework.cql.elm.execution.Library library = TranslatorHelper.translateLibrary(source,
libraryLoader.getLibraryManager(), libraryLoader.getModelManager());
// resolve execution context
Context context = setupContext(instance, patientId, libraryLoader, library);
return context.resolveExpressionRef("Expression").evaluate(context);
}
示例5
public static CodeSystem makeShareable(CodeSystem cs) {
if (!cs.hasMeta())
cs.setMeta(new Meta());
for (UriType t : cs.getMeta().getProfile())
if (t.getValue().equals("http://hl7.org/fhir/StructureDefinition/shareablecodesystem"))
return cs;
cs.getMeta().getProfile().add(new CanonicalType("http://hl7.org/fhir/StructureDefinition/shareablecodesystem"));
return cs;
}
示例6
public static ValueSet makeShareable(ValueSet vs) {
if (!vs.hasMeta())
vs.setMeta(new Meta());
for (UriType t : vs.getMeta().getProfile())
if (t.getValue().equals("http://hl7.org/fhir/StructureDefinition/shareablevalueset"))
return vs;
vs.getMeta().getProfile().add(new CanonicalType("http://hl7.org/fhir/StructureDefinition/shareablevalueset"));
return vs;
}
示例7
private String canonicalList(List<CanonicalType> list) {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder("|");
for (CanonicalType c : list) {
String v = c.getValue();
if (v.startsWith("http://hl7.org/fhir/StructureDefinition/"))
v = v.substring(40);
b.append(v);
}
return b.toString();
}
示例8
public static org.hl7.fhir.dstu2016may.model.Extension convertExtension(org.hl7.fhir.r4.model.Extension src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2016may.model.Extension tgt = new org.hl7.fhir.dstu2016may.model.Extension();
copyElement(src, tgt);
if (src.hasUrlElement())
tgt.setUrlElement(convertUri(src.getUrlElement()));
if (src.hasValue())
if (CANONICAL_URLS.contains(src.getUrl()) && src.getValue() instanceof org.hl7.fhir.r4.model.CanonicalType)
tgt.setValue(convertCanonicalToReference((CanonicalType) src.getValue()));
else
tgt.setValue(convertType(src.getValue()));
return tgt;
}
示例9
public static String getId(CanonicalType canonical) {
if (canonical.hasValue()) {
String id = canonical.getValue();
String temp = id.contains("/") ? id.substring(id.lastIndexOf("/") + 1) : id;
return temp.split("\\|")[0];
}
throw new RuntimeException("CanonicalType must have a value for id extraction");
}
示例10
public static String getResourceName(CanonicalType canonical) {
if (canonical.hasValue()) {
String id = canonical.getValue();
if (id.contains("/")) {
id = id.replace(id.substring(id.lastIndexOf("/")), "");
return id.contains("/") ? id.substring(id.lastIndexOf("/") + 1) : id;
}
return null;
}
throw new RuntimeException("CanonicalType must have a value for resource name extraction");
}
示例11
private String buildIncludes(Iterable<CanonicalType> references) {
StringBuilder builder = new StringBuilder();
for (CanonicalType reference : references) {
if (builder.length() > 0) {
builder.append(" ");
}
builder.append("include ");
// TODO: This assumes the libraries resource id is the same as the library name,
// need to work this out better
Library lib =this.libraryResourceProvider.resolveLibraryById(CanonicalHelper.getId(reference));
if (lib.hasName()) {
builder.append(lib.getName());
}
else {
throw new RuntimeException("Library name unknown");
}
if (reference.hasValue() && reference.getValue().split("\\|").length > 1) {
builder.append(" version '");
builder.append(reference.getValue().split("\\|")[1]);
builder.append("'");
}
builder.append(" called ");
builder.append(lib.getName());
}
return builder.toString();
}
示例12
public Object evaluateInContext(DomainResource instance, String cql, String patientId, Boolean aliasedExpression) {
Iterable<CanonicalType> libraries = getLibraryReferences(instance);
if (aliasedExpression) {
Object result = null;
for (CanonicalType reference : libraries) {
Library lib =this.libraryResourceProvider.resolveLibraryById(CanonicalHelper.getId(reference));
if (lib == null)
{
throw new RuntimeException("Library with id " + reference.getIdBase() + "not found");
}
LibraryLoader libraryLoader = LibraryHelper.createLibraryLoader(this.getLibraryResourceProvider());
// resolve primary library
org.cqframework.cql.elm.execution.Library library = LibraryHelper.resolveLibraryById(lib.getId(), libraryLoader, this.libraryResourceProvider);
// resolve execution context
Context context = setupContext(instance, patientId, libraryLoader, library);
result = context.resolveExpressionRef(cql).evaluate(context);
if (result != null) {
return result;
}
}
throw new RuntimeException("Could not find Expression in Referenced Libraries");
}
else {
return evaluateInContext(instance, cql, patientId);
}
}
示例13
private boolean profilesMatch(List<String> profiles, List<CanonicalType> profile) {
return profiles == null || profiles.size() == 0 || profile.size() == 0 || (profiles.size() == 1 && profiles.get(0).equals(profile.get(0).getValue()));
}
示例14
static public CanonicalType convertReferenceToCanonical(Reference src) throws FHIRException {
CanonicalType dst = new CanonicalType(src.getReference());
copyElement(src, dst);
return dst;
}
示例15
static public Reference convertCanonicalToReference(CanonicalType src) throws FHIRException {
Reference dst = new Reference(src.getValue());
copyElement(src, dst);
return dst;
}
示例16
private Iterable<CanonicalType> getLibraryReferences(DomainResource instance) {
List<CanonicalType> references = new ArrayList<>();
if (instance.hasContained()) {
for (Resource resource : instance.getContained()) {
if (resource instanceof Library) {
resource.setId(resource.getIdElement().getIdPart().replace("#", ""));
getLibraryResourceProvider().update((Library) resource);
// getLibraryLoader().putLibrary(resource.getIdElement().getIdPart(),
// getLibraryLoader().toElmLibrary((Library) resource));
}
}
}
if (instance instanceof ActivityDefinition) {
references.addAll(((ActivityDefinition) instance).getLibrary());
}
else if (instance instanceof PlanDefinition) {
references.addAll(((PlanDefinition) instance).getLibrary());
}
else if (instance instanceof Measure) {
references.addAll(((Measure) instance).getLibrary());
}
for (Extension extension : instance
.getExtensionsByUrl("http://hl7.org/fhir/StructureDefinition/cqif-library")) {
Type value = extension.getValue();
if (value instanceof CanonicalType) {
references.add((CanonicalType) value);
}
else {
throw new RuntimeException("Library extension does not have a value of type reference");
}
}
return cleanReferences(references);
}
示例17
@SuppressWarnings("unchecked")
private void createBundle(){
try {
Date now = new Date();
this.bundle = new Bundle();
bundle.setId("BundleFromPractitioner");
bundle.setMeta(new Meta().setLastUpdated(now).setProfile(Collections.singletonList(
new CanonicalType("http://fhir.ch/ig/ch-crl/StructureDefinition/ch-crl-bundle"))));
bundle.setType(BundleType.DOCUMENT);
BundleEntryComponent compositionEntry = bundle.addEntry();
Composition composition = new Composition();
compositionEntry.setResource(composition);
composition.setId("CompFromPractitioner");
composition.setMeta(new Meta().setLastUpdated(now)
.setProfile(Collections.singletonList(new CanonicalType(
"http://fhir.ch/ig/ch-crl/StructureDefinition/ch-crl-composition"))));
composition.setStatus(CompositionStatus.FINAL);
composition.setType(new CodeableConcept(
new Coding("http://loinc.org", "72134-0", "Cancer event report")));
composition.setDate(now);
composition.setTitle("Report to the Cancer Registry");
BundleEntryComponent subjectEntry = bundle.addEntry();
IFhirTransformer<Patient, IPatient> patientTransformer =
(IFhirTransformer<Patient, IPatient>) FhirTransformersHolder
.getTransformerFor(Patient.class, IPatient.class);
Patient subject = patientTransformer.getFhirObject(patient)
.orElseThrow(() -> new IllegalStateException("Could not create subject"));
subject.getExtension().clear();
fixAhvIdentifier(subject);
subjectEntry.setResource(subject);
BundleEntryComponent practitionerEntry = bundle.addEntry();
IFhirTransformer<Practitioner, IMandator> practitionerTransformer =
(IFhirTransformer<Practitioner, IMandator>) FhirTransformersHolder
.getTransformerFor(Practitioner.class, IMandator.class);
Practitioner practitioner = practitionerTransformer.getFhirObject(author)
.orElseThrow(() -> new IllegalStateException("Could not create autor"));
practitioner.getExtension().clear();
practitioner.getIdentifier().clear();
practitionerEntry.setResource(practitioner);
BundleEntryComponent documentReferenceEntry = bundle.addEntry();
DocumentReference documentReference = new DocumentReference();
documentReferenceEntry.setResource(documentReference);
documentReference.setId(document.getId());
DocumentReferenceContentComponent content = documentReference.addContent();
content.setAttachment(new Attachment().setContentType("application/pdf")
.setData(IOUtils.toByteArray(document.getContent())));
composition.setSubject(new Reference(subject));
composition.setAuthor(Collections.singletonList(new Reference(practitioner)));
SectionComponent section = composition.addSection();
section.addEntry(new Reference(documentReference));
} catch (IOException e) {
LoggerFactory.getLogger(getClass()).error("Error creating FHIR bundle", e);
throw new IllegalStateException("Error creating FHIR bundle", e);
}
}