use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project org.hl7.fhir.core by hapifhir.
the class Conformance method copy.
public Conformance copy() {
Conformance dst = new Conformance();
copyValues(dst);
dst.url = url == null ? null : url.copy();
dst.version = version == null ? null : version.copy();
dst.name = name == null ? null : name.copy();
dst.status = status == null ? null : status.copy();
dst.experimental = experimental == null ? null : experimental.copy();
dst.publisher = publisher == null ? null : publisher.copy();
if (contact != null) {
dst.contact = new ArrayList<ConformanceContactComponent>();
for (ConformanceContactComponent i : contact) dst.contact.add(i.copy());
}
;
dst.date = date == null ? null : date.copy();
dst.description = description == null ? null : description.copy();
dst.requirements = requirements == null ? null : requirements.copy();
dst.copyright = copyright == null ? null : copyright.copy();
dst.kind = kind == null ? null : kind.copy();
dst.software = software == null ? null : software.copy();
dst.implementation = implementation == null ? null : implementation.copy();
dst.fhirVersion = fhirVersion == null ? null : fhirVersion.copy();
dst.acceptUnknown = acceptUnknown == null ? null : acceptUnknown.copy();
if (format != null) {
dst.format = new ArrayList<CodeType>();
for (CodeType i : format) dst.format.add(i.copy());
}
;
if (profile != null) {
dst.profile = new ArrayList<Reference>();
for (Reference i : profile) dst.profile.add(i.copy());
}
;
if (rest != null) {
dst.rest = new ArrayList<ConformanceRestComponent>();
for (ConformanceRestComponent i : rest) dst.rest.add(i.copy());
}
;
if (messaging != null) {
dst.messaging = new ArrayList<ConformanceMessagingComponent>();
for (ConformanceMessagingComponent i : messaging) dst.messaging.add(i.copy());
}
;
if (document != null) {
dst.document = new ArrayList<ConformanceDocumentComponent>();
for (ConformanceDocumentComponent i : document) dst.document.add(i.copy());
}
;
return dst;
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project org.hl7.fhir.core by hapifhir.
the class NPMPackageGenerator method buildPackageJson.
private void buildPackageJson(String canonical, PackageType kind, String web, String genDate, ImplementationGuide ig, List<String> fhirVersion) throws FHIRException, IOException {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (!ig.hasPackageId())
b.append("packageId");
if (!ig.hasVersion())
b.append("version");
if (!ig.hasFhirVersion())
b.append("fhirVersion");
if (!ig.hasLicense())
b.append("license");
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
if (!d.hasVersion()) {
b.append("dependsOn.version(" + d.getUri() + ")");
}
}
JsonObject npm = new JsonObject();
npm.addProperty("name", ig.getPackageId());
npm.addProperty("version", ig.getVersion());
npm.addProperty("tools-version", ToolsVersion.TOOLS_VERSION);
npm.addProperty("type", kind.getCode());
if (ig.hasLicense())
npm.addProperty("license", ig.getLicense().toCode());
npm.addProperty("canonical", canonical);
npm.addProperty("url", web);
if (ig.hasTitle())
npm.addProperty("title", ig.getTitle());
if (ig.hasDescription())
npm.addProperty("description", ig.getDescription() + " (built " + genDate + timezone() + ")");
if (kind != PackageType.CORE) {
JsonObject dep = new JsonObject();
npm.add("dependencies", dep);
for (String v : fhirVersion) {
// TODO: fix for multiple versions
dep.addProperty("hl7.fhir.core", v);
}
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
dep.addProperty(d.getPackageId(), d.getVersion());
}
}
if (ig.hasPublisher())
npm.addProperty("author", ig.getPublisher());
JsonArray m = new JsonArray();
for (ContactDetail t : ig.getContact()) {
String email = email(t.getTelecom());
String url = url(t.getTelecom());
if (t.hasName() & (email != null || url != null)) {
JsonObject md = new JsonObject();
m.add(md);
md.addProperty("name", t.getName());
if (email != null)
md.addProperty("email", email);
if (url != null)
md.addProperty("url", url);
}
}
if (m.size() > 0)
npm.add("maintainers", m);
if (ig.getManifest().hasRendering())
npm.addProperty("homepage", ig.getManifest().getRendering());
JsonObject dir = new JsonObject();
npm.add("directories", dir);
dir.addProperty("lib", "package");
dir.addProperty("example", "example");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(npm);
try {
addFile(Category.RESOURCE, "package.json", json.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
}
packageJ = npm;
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method compare.
public ProfileComparison compare(StructureDefinition left, StructureDefinition right) throws DefinitionException, FHIRFormatError, IOException {
check(left, "left");
check(right, "right");
ProfileComparison res = new ProfileComparison(left, right);
session.identify(res);
StructureDefinition sd = new StructureDefinition();
res.setUnion(sd);
session.identify(sd);
sd.setName("Union" + left.getName() + "And" + right.getName());
sd.setTitle("Union of " + left.getTitle() + " And " + right.getTitle());
sd.setStatus(left.getStatus());
sd.setDate(new Date());
StructureDefinition sd1 = new StructureDefinition();
res.setIntersection(sd1);
session.identify(sd1);
sd1.setName("Intersection" + left.getName() + "And" + right.getName());
sd1.setTitle("Intersection of " + left.getTitle() + " And " + right.getTitle());
sd1.setStatus(left.getStatus());
sd1.setDate(new Date());
compareMetadata(left, right, res.getMetadata(), res);
comparePrimitives("fhirVersion", left.getFhirVersionElement(), right.getFhirVersionElement(), res.getMetadata(), IssueSeverity.WARNING, res);
comparePrimitives("kind", left.getKindElement(), right.getKindElement(), res.getMetadata(), IssueSeverity.WARNING, res);
comparePrimitives("abstract", left.getAbstractElement(), right.getAbstractElement(), res.getMetadata(), IssueSeverity.WARNING, res);
comparePrimitives("type", left.getTypeElement(), right.getTypeElement(), res.getMetadata(), IssueSeverity.ERROR, res);
comparePrimitives("baseDefinition", left.getBaseDefinitionElement(), right.getBaseDefinitionElement(), res.getMetadata(), IssueSeverity.ERROR, res);
if (left.getType().equals(right.getType())) {
DefinitionNavigator ln = new DefinitionNavigator(session.getContextLeft(), left);
DefinitionNavigator rn = new DefinitionNavigator(session.getContextRight(), right);
StructuralMatch<ElementDefinitionNode> sm = new StructuralMatch<ElementDefinitionNode>(new ElementDefinitionNode(left, ln.current()), new ElementDefinitionNode(right, rn.current()));
compareElements(res, sm, ln.path(), null, ln, rn);
res.combined = sm;
}
return res;
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method makeBaseDefinition.
public static StructureDefinition makeBaseDefinition(FHIRVersion fhirVersion) {
StructureDefinition base = new StructureDefinition();
base.setId("Base");
base.setUrl("http://hl7.org/fhir/StructureDefinition/Base");
base.setVersion(fhirVersion.toCode());
base.setName("Base");
base.setStatus(PublicationStatus.ACTIVE);
base.setDate(new Date());
base.setFhirVersion(fhirVersion);
base.setKind(StructureDefinitionKind.COMPLEXTYPE);
base.setAbstract(true);
base.setType("Base");
ElementDefinition e = base.getSnapshot().getElementFirstRep();
e.setId("Base");
e.setPath("Base");
e.setMin(0);
e.setMax("*");
e.getBase().setPath("Base");
e.getBase().setMin(0);
e.getBase().setMax("*");
e.setIsModifier(false);
e = base.getDifferential().getElementFirstRep();
e.setId("Base");
e.setPath("Base");
e.setMin(0);
e.setMax("*");
return base;
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project org.hl7.fhir.core by hapifhir.
the class SHCParser method parse.
public List<NamedElement> parse(InputStream stream) throws IOException, FHIRFormatError, DefinitionException, FHIRException {
List<NamedElement> res = new ArrayList<>();
String src = TextFile.streamToString(stream).trim();
List<String> list = new ArrayList<>();
String pfx = null;
if (src.startsWith("{")) {
JsonObject json = JsonTrackingParser.parseJson(src);
if (checkProperty(json, "$", "verifiableCredential", true, "Array")) {
pfx = "verifiableCredential";
JsonArray arr = json.getAsJsonArray("verifiableCredential");
int i = 0;
for (JsonElement e : arr) {
if (!(e instanceof JsonPrimitive)) {
logError(line(e), col(e), "$.verifiableCredential[" + i + "]", IssueType.STRUCTURE, "Wrong Property verifiableCredential in JSON Payload. Expected : String but found " + JSONUtil.type(e), IssueSeverity.ERROR);
} else {
list.add(e.getAsString());
}
i++;
}
} else {
return res;
}
} else {
list.add(src);
}
int c = 0;
for (String ssrc : list) {
String prefix = pfx == null ? "" : pfx + "[" + Integer.toString(c) + "].";
c++;
JWT jwt = null;
try {
jwt = decodeJWT(ssrc);
} catch (Exception e) {
logError(1, 1, prefix + "JWT", IssueType.INVALID, "Unable to decode JWT token", IssueSeverity.ERROR);
return res;
}
map = jwt.map;
checkNamedProperties(jwt.getPayload(), prefix + "payload", "iss", "nbf", "vc");
checkProperty(jwt.getPayload(), prefix + "payload", "iss", true, "String");
logError(1, 1, prefix + "JWT", IssueType.INFORMATIONAL, "The FHIR Validator does not check the JWT signature " + "(see https://demo-portals.smarthealth.cards/VerifierPortal.html or https://github.com/smart-on-fhir/health-cards-dev-tools) (Issuer = '" + jwt.getPayload().get("iss").getAsString() + "')", IssueSeverity.INFORMATION);
checkProperty(jwt.getPayload(), prefix + "payload", "nbf", true, "Number");
JsonObject vc = jwt.getPayload().getAsJsonObject("vc");
if (vc == null) {
logError(1, 1, "JWT", IssueType.STRUCTURE, "Unable to find property 'vc' in the payload", IssueSeverity.ERROR);
return res;
}
String path = prefix + "payload.vc";
checkNamedProperties(vc, path, "type", "credentialSubject");
if (!checkProperty(vc, path, "type", true, "Array")) {
return res;
}
JsonArray type = vc.getAsJsonArray("type");
int i = 0;
for (JsonElement e : type) {
if (!(e instanceof JsonPrimitive)) {
logError(line(e), col(e), path + ".type[" + i + "]", IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : String but found " + JSONUtil.type(e), IssueSeverity.ERROR);
} else {
types.add(e.getAsString());
}
i++;
}
if (!types.contains("https://smarthealth.cards#health-card")) {
logError(line(vc), col(vc), path, IssueType.STRUCTURE, "Card does not claim to be of type https://smarthealth.cards#health-card, cannot validate", IssueSeverity.ERROR);
return res;
}
if (!checkProperty(vc, path, "credentialSubject", true, "Object")) {
return res;
}
JsonObject cs = vc.getAsJsonObject("credentialSubject");
path = path + ".credentialSubject";
if (!checkProperty(cs, path, "fhirVersion", true, "String")) {
return res;
}
JsonElement fv = cs.get("fhirVersion");
if (!VersionUtilities.versionsCompatible(context.getVersion(), fv.getAsString())) {
logError(line(fv), col(fv), path + ".fhirVersion", IssueType.STRUCTURE, "Card claims to be of version " + fv.getAsString() + ", cannot be validated against version " + context.getVersion(), IssueSeverity.ERROR);
return res;
}
if (!checkProperty(cs, path, "fhirBundle", true, "Object")) {
return res;
}
// ok. all checks passed, we can now validate the bundle
Element e = jsonParser.parse(cs.getAsJsonObject("fhirBundle"), map);
if (e != null) {
res.add(new NamedElement(path, e));
}
}
return res;
}
Aggregations