Skip to content

Commit

Permalink
Merge pull request hapifhir#1716 from hapifhir/2024-08-gg-unicode-json
Browse files Browse the repository at this point in the history
2024 08 gg unicode json
  • Loading branch information
grahamegrieve authored Aug 16, 2024
2 parents fe2a8e6 + 3ee9533 commit 48741cf
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hl7.fhir.utilities.IniFile;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;

public class Configuration {
public static final SimpleDateFormat DATE_FORMAT() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hl7.fhir.r5.conformance.profile.ProfileUtilities;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;

public class JavaExtensionsGenerator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ public Resource fixSD(StructureDefinition sd) {
}
}
}
if (VersionUtilities.isR4Ver(version) && "http://hl7.org/fhir/StructureDefinition/ExplanationOfBenefit".equals(sd.getUrl())) {
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
if (ed.hasBinding() && "http://terminology.hl7.org/CodeSystem/processpriority".equals(ed.getBinding().getValueSet())) {
ed.getBinding().setValueSet("http://hl7.org/fhir/ValueSet/process-priority");
}
}
for (ElementDefinition ed : sd.getDifferential().getElement()) {
if (ed.hasBinding() && "http://terminology.hl7.org/CodeSystem/processpriority".equals(ed.getBinding().getValueSet())) {
ed.getBinding().setValueSet("http://hl7.org/fhir/ValueSet/process-priority");
}
}
}
if (sd.getUrl().startsWith("http://hl7.org/fhir/uv/subscriptions-backport")) {
for (ElementDefinition ed : sd.getDifferential().getElement()) {
fixMarkdownR4BURLs(ed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,21 @@ public Element getExtension(String url) {
return null;
}

public List<Element> getExtensions(String url) {
List<Element> list = new ArrayList<>();
if (children != null) {
for (Element child : children) {
if (extensionList.contains(child.getName())) {
String u = child.getChildValue("url");
if (url.equals(u)) {
list.add(child);
}
}
}
}
return list;
}

public Base getExtensionValue(String url) {
if (children != null) {
for (Element child : children) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ public void renderItemOptions(XhtmlNode x, ResourceWrapper i) {
text = v.primitiveValue("code");
}
}
if (value == null) {
value = "??";
}
if (text == null) {
text = "??";
}
boolean selected = "true".equals(opt.primitiveValue("initialSelected"));
x.option(value, text, selected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,10 @@ else if (isWhitespace(c))


public static String escapeJson(String value) {
return escapeJson(value, true);
}

public static String escapeJson(String value, boolean escapeUnicodeWhitespace) {
if (value == null)
return "";

Expand All @@ -1049,7 +1053,7 @@ else if (c == '\\')
b.append("\\\\");
else if (c == ' ')
b.append(" ");
else if (isWhitespace(c)) {
else if ((c == '\r' || c == '\n') || (isWhitespace(c) && escapeUnicodeWhitespace)) {
b.append("\\u"+Utilities.padLeft(Integer.toHexString(c), '0', 4));
} else if (((int) c) < 32)
b.append("\\u" + Utilities.padLeft(Integer.toHexString(c), '0', 4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,4 +1107,5 @@ public class I18nConstants {
public static final String TYPE_SPECIFIC_CHECKS_DT_XHTML_LITERAL_HREF = "TYPE_SPECIFIC_CHECKS_DT_XHTML_LITERAL_HREF";
public static final String SM_TARGET_TYPE_UNKNOWN = "SM_TARGET_TYPE_UNKNOWN";
public static final String XHTML_XHTML_ATTRIBUTE_XML_SPACE = "XHTML_XHTML_ATTRIBUTE_XML_SPACE";
public static final String VALIDATION_HL7_PUBLISHER_MULTIPLE_WGS = "VALIDATION_HL7_PUBLISHER_MULTIPLE_WGS";
}
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ private void write(StringBuilder b, JsonElement e, boolean pretty, int indent) {
break;
case STRING:
b.append("\"");
b.append(Utilities.escapeJson(((JsonString) e).getValue()));
b.append(Utilities.escapeJson(((JsonString) e).getValue(), false));
b.append("\"");
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,4 +1137,5 @@ TYPE_SPECIFIC_CHECKS_DT_XHTML_UNKNOWN_HREF = Hyperlink scheme ''{3}'' in ''{0}''
TYPE_SPECIFIC_CHECKS_DT_XHTML_LITERAL_HREF = Hyperlink scheme ''{3}'' in ''{0}'' at ''{1}'' for ''{2}'' is not a valid hyperlinkable scheme
SM_TARGET_TYPE_UNKNOWN = The type of the target variable is not known: {0}
XHTML_XHTML_ATTRIBUTE_XML_SPACE = The attribute 'xml:space' is legal but has a fixed value of 'preserve'. It''s use is discouraged
VALIDATION_HL7_PUBLISHER_MULTIPLE_WGS = This resource has more than workgroup extension (http://hl7.org/fhir/StructureDefinition/structuredefinition-wg)

Original file line number Diff line number Diff line change
Expand Up @@ -5730,13 +5730,15 @@ public boolean checkSpecials(ValidationContext valContext, List<ValidationMessag

private boolean checkPublisherConsistency(ValidationContext valContext, List<ValidationMessage> errors, Element element, NodeStack stack, boolean contained) {

boolean ok = true;
String pub = element.getNamedChildValue("publisher", false);

ok = rule(errors, "2024-08-15", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), element.getExtensions(ToolingExtensions.EXT_WORKGROUP).size() <= 1, I18nConstants.VALIDATION_HL7_PUBLISHER_MULTIPLE_WGS) && ok;
Base wgT = element.getExtensionValue(ToolingExtensions.EXT_WORKGROUP);
String wg = wgT == null ? null : wgT.primitiveValue();
String url = element.getNamedChildValue("url");

if (contained && wg == null) {
boolean ok = true;
Element container = valContext.getRootResource();
if (element.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
// container already specified the HL7 WG, so we don't need to test
Expand Down Expand Up @@ -5775,24 +5777,24 @@ private boolean checkPublisherConsistency(ValidationContext valContext, List<Val
if (rule(errors, "2023-09-15", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), wgd != null, I18nConstants.VALIDATION_HL7_WG_UNKNOWN, wg)) {
String rpub = "HL7 International / "+wgd.getName();
if (warning(errors, "2023-09-15", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), pub != null, I18nConstants.VALIDATION_HL7_PUBLISHER_MISSING, wg, rpub)) {
boolean ok = rpub.equals(pub);
ok = rpub.equals(pub) && ok;
if (!ok && wgd.getName2() != null) {
ok = ("HL7 International / "+wgd.getName2()).equals(pub);
ok = ("HL7 International / "+wgd.getName2()).equals(pub) && ok;
warningOrError(pub.contains("/"), errors, "2023-09-15", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), ok, I18nConstants.VALIDATION_HL7_PUBLISHER_MISMATCH2, wg, rpub, "HL7 International / "+wgd.getName2(), pub);
} else {
warningOrError(pub.contains("/"), errors, "2023-09-15", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), ok, I18nConstants.VALIDATION_HL7_PUBLISHER_MISMATCH, wg, rpub, pub);
}
}
warning(errors, "2023-09-15", IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(),
Utilities.startsWithInList( wgd.getLink(), urls), I18nConstants.VALIDATION_HL7_WG_URL, wg, wgd.getLink());
return true;
return ok;
}
} else {
return true; // HL7 sid.
return ok; // HL7 sid.
}
}

return false;
return ok;
}

private boolean statusCodesConsistent(String status, String standardsStatus) {
Expand Down

0 comments on commit 48741cf

Please sign in to comment.