use of org.hl7.fhir.r4b.model.CodeableReference in project kindling by HL7.
the class ProfileGenerator method convertElements.
public void convertElements(ElementDefn src, StructureDefinition ed, String path) throws Exception {
ElementDefinition dst = new ElementDefinition();
if (!ed.hasDifferential())
ed.setDifferential(new StructureDefinitionDifferentialComponent());
ed.getDifferential().getElement().add(dst);
String thisPath = path == null ? "Extension" : path;
dst.setId(thisPath);
dst.setPath(thisPath);
if (!Utilities.noString(src.getProfileName()))
dst.setSliceName(src.getProfileName());
dst.setShort(src.getShortDefn());
dst.setDefinition(preProcessMarkdown(src.getDefinition(), "Element Definition"));
dst.setComment(preProcessMarkdown(src.getComments(), "Element Comments"));
if (src.getMaxCardinality() != null) {
if (src.getMaxCardinality() == Integer.MAX_VALUE)
dst.setMax("*");
else
dst.setMax(src.getMaxCardinality().toString());
}
if (src.getMinCardinality() != null)
dst.setMin(src.getMinCardinality());
if (src.getFixed() != null)
dst.setFixed(src.getFixed());
if (src.hasMustSupport())
dst.setMustSupport(src.isMustSupport());
if (src.hasModifier())
dst.setIsModifier(src.isModifier());
if (dst.getIsModifier())
dst.setIsModifierReason(src.getModifierReason());
if (src.hasSummaryItem() && dst.getPath().contains("."))
dst.setIsSummaryElement(Factory.newBoolean(src.isSummary()));
for (Invariant id : src.getStatedInvariants()) dst.addCondition(id.getId());
// dDst.
for (TypeRef t : src.getTypes()) {
if (t.hasParams()) {
for (String tp : t.getParams()) {
if (definitions.hasLogicalModel(tp)) {
for (String tpn : definitions.getLogicalModel(tp).getImplementations()) {
ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
String pr = "http://hl7.org/fhir/StructureDefinition/" + tpn;
type.addTargetProfile(pr);
}
} else {
ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
String pr = t.hasProfile() ? t.getProfile() : // this should only happen if t.getParams().size() == 1
"http://hl7.org/fhir/StructureDefinition/" + (tp.equals("Any") ? "Resource" : tp);
if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("canonical") || type.getWorkingCode().equals("CodeableReference"))
type.addTargetProfile(pr);
else
type.addProfile(pr);
}
}
} else if (t.isWildcardType()) {
for (String n : TypesUtilities.wildcardTypes(version.toString())) dst.getType(n);
} else {
if (definitions != null && definitions.getConstraints().containsKey(t.getName())) {
ProfiledType ct = definitions.getConstraints().get(t.getName());
ElementDefinition.TypeRefComponent type = dst.getType(ct.getBaseType());
type.addProfile("http://hl7.org/fhir/StructureDefinition/" + ct.getName());
} else if ("Extension.url".equals(path)) {
// juat don't populate it
// ElementDefinition.TypeRefComponent tt = dst.addType();
// tt.setCodeElement(new UriType());
// tt.getFormatCommentsPre().add("Note: special primitive values do not have an assigned type. e.g. this is compiler magic. XML, JSON and RDF types provided by extension");
// ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_JSON_TYPE, "string");
// ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_XML_TYPE, "xs:anyURI");
// ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_RDF_TYPE, "xs:anyURI");
} else {
ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
if (t.hasProfile())
if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("CodeableReference"))
type.addTargetProfile(t.getProfile());
else
type.addProfile(t.getProfile());
}
}
}
if (definitions != null) {
// igtodo - catch this
for (String mu : definitions.getMapTypes().keySet()) {
if (src.hasMapping(mu)) {
addMapping(ed, dst, mu, src.getMapping(mu), null);
}
}
}
for (String in : src.getInvariants().keySet()) {
ElementDefinitionConstraintComponent con = new ElementDefinitionConstraintComponent();
Invariant inv = src.getInvariants().get(in);
con.setKey(inv.getId());
if (!con.hasKey()) {
extensionCounter++;
con.setKey("exd-" + Integer.toString(extensionCounter));
}
con.setRequirements(inv.getRequirements());
if (Utilities.noString(inv.getSeverity()))
con.setSeverity(ConstraintSeverity.ERROR);
else
con.setSeverity(ConstraintSeverity.fromCode(inv.getSeverity()));
con.setHuman(inv.getEnglish());
con.setXpath(inv.getXpath());
if (!"n/a".equals(inv.getExpression()))
con.setExpression(inv.getExpression());
dst.getConstraint().add(con);
}
if (src.hasBinding())
dst.setBinding(generateBinding(src.getBinding()));
if (src.getElements().isEmpty()) {
if (path == null)
throw new Exception("?error parsing extension");
} else {
ElementDefn url = src.getElements().get(0);
if (!url.getName().equals("url"))
throw new Exception("first child of extension should be 'url', not " + url.getName() + " for structure definition " + ed.getUrl());
convertElements(url, ed, thisPath + ".url");
// this pair might leave elements out of order, but we're going to sort them later
if (!hasValue(src)) {
ElementDefn value = new ElementDefn();
value.setName("value[x]");
value.setMinCardinality(0);
value.setMaxCardinality(0);
convertElements(value, ed, thisPath + ".value[x]");
} else {
ElementDefn ext = new ElementDefn();
// can't have an extension if you have a value
ext.setName("extension");
ext.setMaxCardinality(0);
convertElements(ext, ed, thisPath + ".extension");
}
if (src.getElements().size() == 2 && src.getElements().get(0).getName().equals("url") && src.getElements().get(1).getName().equals("value[x]")) {
ElementDefn value = src.getElements().get(1);
value.setMinCardinality(1);
convertElements(value, ed, thisPath + ".value[x]");
} else {
for (ElementDefn child : src.getElements()) {
if (child != url) {
if (child.getName().startsWith("value") && !child.getName().startsWith("valueSet"))
convertElements(child, ed, thisPath + "." + child.getName());
else {
if (child.getElements().size() == 0 || !child.getElements().get(0).getName().equals("url")) {
ElementDefn childUrl = new ElementDefn();
childUrl.setName("url");
childUrl.setXmlAttribute(true);
childUrl.getTypes().add(new TypeRef("uri"));
childUrl.setFixed(new UriType(child.getName()));
child.getElements().add(0, childUrl);
}
if (!hasValue(child)) {
ElementDefn value = new ElementDefn();
value.setName("value[x]");
value.setMinCardinality(0);
value.setMaxCardinality(0);
child.getElements().add(value);
}
convertElements(child, ed, thisPath + ".extension");
}
}
}
}
}
}
use of org.hl7.fhir.r4b.model.CodeableReference in project org.hl7.fhir.core by hapifhir.
the class CommunicationRequest10_50 method convertCommunicationRequest.
public static org.hl7.fhir.dstu2.model.CommunicationRequest convertCommunicationRequest(org.hl7.fhir.r5.model.CommunicationRequest src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.CommunicationRequest tgt = new org.hl7.fhir.dstu2.model.CommunicationRequest();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
if (src.hasCategory())
tgt.setCategory(CodeableConcept10_50.convertCodeableConcept(src.getCategoryFirstRep()));
if (src.hasInformationProvider())
tgt.setSender(Reference10_50.convertReference(src.getInformationProviderFirstRep()));
for (org.hl7.fhir.r5.model.Reference t : src.getRecipient()) tgt.addRecipient(Reference10_50.convertReference(t));
for (org.hl7.fhir.r5.model.CommunicationRequest.CommunicationRequestPayloadComponent t : src.getPayload()) tgt.addPayload(convertCommunicationRequestPayloadComponent(t));
for (org.hl7.fhir.r5.model.CodeableConcept t : src.getMedium()) tgt.addMedium(CodeableConcept10_50.convertCodeableConcept(t));
if (src.hasRequester())
tgt.setRequester(Reference10_50.convertReference(src.getRequester()));
if (src.hasStatus())
tgt.setStatusElement(convertCommunicationRequestStatus(src.getStatusElement()));
if (src.hasEncounter())
tgt.setEncounter(Reference10_50.convertReference(src.getEncounter()));
if (src.hasOccurrence())
tgt.setScheduled(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getOccurrence()));
for (CodeableReference t : src.getReason()) if (t.hasConcept())
tgt.addReason(CodeableConcept10_50.convertCodeableConcept(t.getConcept()));
if (src.hasAuthoredOnElement())
tgt.setRequestedOnElement(DateTime10_50.convertDateTime(src.getAuthoredOnElement()));
if (src.hasSubject())
tgt.setSubject(Reference10_50.convertReference(src.getSubject()));
if (src.hasPriority())
tgt.setPriority(convertPriorityCode(src.getPriority()));
return tgt;
}
use of org.hl7.fhir.r4b.model.CodeableReference in project org.hl7.fhir.core by hapifhir.
the class DeviceUseStatement10_50 method convertDeviceUseStatement.
public static org.hl7.fhir.dstu2.model.DeviceUseStatement convertDeviceUseStatement(org.hl7.fhir.r5.model.DeviceUsage src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.DeviceUseStatement tgt = new org.hl7.fhir.dstu2.model.DeviceUseStatement();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
if (src.getBodySite().hasConcept())
tgt.setBodySite(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getBodySite().getConcept()));
if (src.getDevice().hasReference())
tgt.setDevice(Reference10_50.convertReference(src.getDevice().getReference()));
for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
for (CodeableReference t : src.getReason()) if (t.hasConcept())
tgt.addIndication(CodeableConcept10_50.convertCodeableConcept(t.getConcept()));
for (Annotation t : src.getNote()) tgt.addNotes(t.getText());
if (src.hasDateAssertedElement())
tgt.setRecordedOnElement(DateTime10_50.convertDateTime(src.getDateAssertedElement()));
if (src.hasPatient())
tgt.setSubject(Reference10_50.convertReference(src.getPatient()));
if (src.hasTiming())
tgt.setTiming(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getTiming()));
return tgt;
}
use of org.hl7.fhir.r4b.model.CodeableReference in project org.hl7.fhir.core by hapifhir.
the class Communication10_50 method convertCommunication.
public static org.hl7.fhir.dstu2.model.Communication convertCommunication(org.hl7.fhir.r5.model.Communication src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.Communication tgt = new org.hl7.fhir.dstu2.model.Communication();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
if (src.hasCategory())
tgt.setCategory(CodeableConcept10_50.convertCodeableConcept(src.getCategoryFirstRep()));
if (src.hasSender())
tgt.setSender(Reference10_50.convertReference(src.getSender()));
for (org.hl7.fhir.r5.model.Reference t : src.getRecipient()) tgt.addRecipient(Reference10_50.convertReference(t));
for (org.hl7.fhir.r5.model.Communication.CommunicationPayloadComponent t : src.getPayload()) tgt.addPayload(convertCommunicationPayloadComponent(t));
for (org.hl7.fhir.r5.model.CodeableConcept t : src.getMedium()) tgt.addMedium(CodeableConcept10_50.convertCodeableConcept(t));
if (src.hasStatus())
tgt.setStatusElement(convertCommunicationStatus(src.getStatusElement()));
if (src.hasEncounter())
tgt.setEncounter(Reference10_50.convertReference(src.getEncounter()));
if (src.hasSentElement())
tgt.setSentElement(DateTime10_50.convertDateTime(src.getSentElement()));
if (src.hasReceivedElement())
tgt.setReceivedElement(DateTime10_50.convertDateTime(src.getReceivedElement()));
for (CodeableReference t : src.getReason()) if (t.hasConcept())
tgt.addReason(CodeableConcept10_50.convertCodeableConcept(t.getConcept()));
if (src.hasSubject())
tgt.setSubject(Reference10_50.convertReference(src.getSubject()));
return tgt;
}
use of org.hl7.fhir.r4b.model.CodeableReference in project org.hl7.fhir.core by hapifhir.
the class CarePlan10_50 method convertCarePlanActivityDetailComponent.
public static org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityDetailComponent convertCarePlanActivityDetailComponent(org.hl7.fhir.r5.model.CarePlan.CarePlanActivityPlannedActivityDetailComponent src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityDetailComponent tgt = new org.hl7.fhir.dstu2.model.CarePlan.CarePlanActivityDetailComponent();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
if (src.hasCode())
tgt.setCode(CodeableConcept10_50.convertCodeableConcept(src.getCode()));
for (CodeableReference t : src.getReason()) if (t.hasConcept())
tgt.addReasonCode(CodeableConcept10_50.convertCodeableConcept(t.getConcept()));
for (CodeableReference t : src.getReason()) if (t.hasReference())
tgt.addReasonReference(Reference10_50.convertReference(t.getReference()));
for (org.hl7.fhir.r5.model.Reference t : src.getGoal()) tgt.addGoal(Reference10_50.convertReference(t));
if (src.hasStatus())
tgt.setStatusElement(convertCarePlanActivityStatus(src.getStatusElement()));
if (src.hasDoNotPerformElement())
tgt.setProhibitedElement(Boolean10_50.convertBoolean(src.getDoNotPerformElement()));
if (src.hasScheduled())
tgt.setScheduled(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getScheduled()));
if (src.getLocation().hasReference())
tgt.setLocation(Reference10_50.convertReference(src.getLocation().getReference()));
for (org.hl7.fhir.r5.model.Reference t : src.getPerformer()) tgt.addPerformer(Reference10_50.convertReference(t));
if (src.hasProduct())
tgt.setProduct(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getProduct()));
if (src.hasDailyAmount())
tgt.setDailyAmount(SimpleQuantity10_50.convertSimpleQuantity(src.getDailyAmount()));
if (src.hasQuantity())
tgt.setQuantity(SimpleQuantity10_50.convertSimpleQuantity(src.getQuantity()));
if (src.hasDescriptionElement())
tgt.setDescriptionElement(String10_50.convertString(src.getDescriptionElement()));
return tgt;
}
Aggregations