use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method testSlicingTask8742.
private void testSlicingTask8742() throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Organization").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBaseDefinition(base.getUrl());
focus.setType(base.getType());
focus.setDerivation(TypeDerivationRule.CONSTRAINT);
ElementDefinition id = focus.getDifferential().addElement();
id.setPath("Organization.address");
id.setMin(1);
id.setMax("1");
id.setMustSupport(true);
id = focus.getDifferential().addElement();
id.setPath("Organization.address.extension");
id.setSliceName("USLabCountycodes");
id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
id.setShort("County/Parish FIPS codes");
id.setDefinition("County/Parish FIPS codes.");
id.setRequirements("County/Parish Code SHALL use FIPS 6-4 ( INCITS 31:2009).");
id.setMin(0);
id.setMax("1");
id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/us-core-county");
id.setMustSupport(true);
id.getBinding().setStrength(BindingStrength.REQUIRED).setDescription("FIPS codes for US counties and county equivalent entities.").setValueSet(new Reference().setReference("http://hl7.org/fhir/ValueSet/fips-county"));
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
// 14 for address with one sliced extension
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 13;
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation test 8742 failed");
} else
System.out.println("Snap shot generation test 8742 passed");
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class SnapShotGenerationTests method findContainedProfile.
private StructureDefinition findContainedProfile(String url, SnapShotGenerationTestsContext context) throws DefinitionException, FHIRException {
for (Resource r : context.tests.getContained()) {
if (r instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) r;
if (sd.getUrl().equals(url)) {
StructureDefinition p = sd.copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context, null, null);
pu.setIds(p, false);
pu.generateSnapshot(getSD(p.getBaseDefinition(), context), p, p.getUrl(), p.getName());
return p;
}
}
}
return null;
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method generateSnapshot.
@Override
public void generateSnapshot(StructureDefinition p, boolean logical) throws DefinitionException, FHIRException {
if ((!p.hasSnapshot() || isProfileNeedsRegenerate(p)) && (logical || p.getKind() != StructureDefinitionKind.LOGICAL)) {
if (!p.hasBaseDefinition())
throw new DefinitionException(formatMessage(I18nConstants.PROFILE___HAS_NO_BASE_AND_NO_SNAPSHOT, p.getName(), p.getUrl()));
StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBaseDefinition());
if (sd == null && "http://hl7.org/fhir/StructureDefinition/Base".equals(p.getBaseDefinition())) {
sd = ProfileUtilities.makeBaseDefinition(p.getFhirVersion());
}
if (sd == null) {
throw new DefinitionException(formatMessage(I18nConstants.PROFILE___BASE__COULD_NOT_BE_RESOLVED, p.getName(), p.getUrl(), p.getBaseDefinition()));
}
List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
List<String> errors = new ArrayList<String>();
ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
pu.setAutoFixSliceNames(true);
pu.setThrowException(false);
if (xverManager == null) {
xverManager = new XVerExtensionManager(this);
}
pu.setXver(xverManager);
if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT) {
pu.sortDifferential(sd, p, p.getUrl(), errors, true);
}
pu.setDebug(false);
for (String err : errors) msgs.add(new ValidationMessage(Source.ProfileValidator, IssueType.EXCEPTION, p.getUserString("path"), "Error sorting Differential: " + err, ValidationMessage.IssueSeverity.ERROR));
pu.generateSnapshot(sd, p, p.getUrl(), Utilities.extractBaseUrl(sd.getUserString("path")), p.getName());
for (ValidationMessage msg : msgs) {
if ((!ignoreProfileErrors && msg.getLevel() == ValidationMessage.IssueSeverity.ERROR) || msg.getLevel() == ValidationMessage.IssueSeverity.FATAL)
throw new DefinitionException(formatMessage(I18nConstants.PROFILE___ELEMENT__ERROR_GENERATING_SNAPSHOT_, p.getName(), p.getUrl(), msg.getLocation(), msg.getMessage()));
}
if (!p.hasSnapshot())
throw new FHIRException(formatMessage(I18nConstants.PROFILE___ERROR_GENERATING_SNAPSHOT, p.getName(), p.getUrl()));
pu = null;
}
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method selectTypes.
private void selectTypes(StructureDefinition profile, QuestionnaireItemComponent sub, TypeRefComponent t, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> source, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> dest) throws FHIRFormatError {
List<QuestionnaireResponse.QuestionnaireResponseItemComponent> temp = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : source) if (instanceOf(t, (Element) g.getUserData("object")))
temp.add(g);
for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) source.remove(g);
for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) {
// it should be empty
assert (g.getItem().size() == 0);
QuestionnaireResponse.QuestionnaireResponseItemComponent q = g.addItem();
q.setLinkId(g.getLinkId() + "._type");
q.setText("type");
QuestionnaireResponseItemAnswerComponent a = q.addAnswer();
if (t.hasTarget()) {
for (UriType u : t.getTargetProfile()) {
if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
Coding cc = new Coding();
a.setValue(cc);
cc.setCode(u.getValue().substring(40));
cc.setSystem("http://hl7.org/fhir/resource-types");
}
}
} else {
Coding cc = new Coding();
a.setValue(cc);
ProfileUtilities pu = new ProfileUtilities(context, null, null);
StructureDefinition ps = null;
if (t.hasProfile())
ps = pu.getProfile(profile, t.getProfile().get(0).getValue());
if (ps != null) {
cc.setCode(t.getProfile().get(0).getValue());
cc.setSystem("http://hl7.org/fhir/resource-types");
} else {
cc.setCode(t.getWorkingCode());
cc.setSystem("http://hl7.org/fhir/data-types");
}
}
// 1st: create the subgroup
QuestionnaireResponse.QuestionnaireResponseItemComponent subg = a.addItem();
dest.add(subg);
subg.setLinkId(sub.getLinkId());
subg.setText(sub.getText());
subg.setUserData("object", g.getUserData("object"));
}
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method makeTypeList.
private ValueSet makeTypeList(StructureDefinition profile, List<TypeRefComponent> types, String path) {
ValueSet vs = new ValueSet();
vs.setName("Type options for " + path);
vs.setDescription(vs.present());
vs.setStatus(PublicationStatus.ACTIVE);
vs.setExpansion(new ValueSetExpansionComponent());
vs.getExpansion().setIdentifier(Factory.createUUID());
vs.getExpansion().setTimestampElement(DateTimeType.now());
for (TypeRefComponent t : types) {
if (t.hasTarget()) {
for (UriType u : t.getTargetProfile()) {
if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
cc.setCode(u.getValue().substring(40));
cc.setSystem("http://hl7.org/fhir/resource-types");
cc.setDisplay(cc.getCode());
}
}
} else if (!t.hasProfile()) {
ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
cc.setCode(t.getWorkingCode());
cc.setDisplay(t.getWorkingCode());
cc.setSystem("http://hl7.org/fhir/data-types");
} else
for (UriType u : t.getProfile()) {
ProfileUtilities pu = new ProfileUtilities(context, null, null);
StructureDefinition ps = pu.getProfile(profile, u.getValue());
if (ps != null) {
ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
cc.setCode(u.getValue());
cc.setDisplay(ps.getType());
cc.setSystem("http://hl7.org/fhir/resource-types");
}
}
}
return vs;
}
Aggregations