more fixing for language handling issues

This commit is contained in:
Grahame Grieve 2023-04-18 09:40:49 +08:00
parent 81d26c5160
commit 02bd1d8ce7
8 changed files with 58 additions and 21 deletions

View File

@ -534,8 +534,8 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
private void setTerminologyOptions(ValidationOptions options, Parameters pIn) {
if (options != null) {
if (options.hasLanguages()) {
pIn.addParameter("displayLanguage", options.getLanguages().get(0));
for (String s : options.getLanguages()) {
pIn.addParameter("displayLanguage", s);
}
}
}

View File

@ -1007,8 +1007,8 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
private void setTerminologyOptions(ValidationOptions options, Parameters pIn) {
if (options.hasLanguages()) {
pIn.addParameter("displayLanguage", options.getLanguages().get(0));
for (String s : options.getLanguages()) {
pIn.addParameter("displayLanguage", s);
}
if (options.getValueSetMode() != ValueSetMode.ALL_CHECKS) {
pIn.addParameter("valueSetMode", options.getValueSetMode().toString());

View File

@ -1084,8 +1084,11 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
} catch (VSCheckerException e) {
localError = e.getMessage();
issues.addAll(e.getIssues());
if (e.getIssues() != null) {
issues.addAll(e.getIssues());
}
} catch (Exception e) {
// e.printStackTrace();
localError = e.getMessage();
}
}

View File

@ -858,6 +858,7 @@ public class I18nConstants {
public static final String UNKNOWN_CODESYSTEM = "UNKNOWN_CODESYSTEM";
public static final String UNKNOWN_CODESYSTEM_VERSION = "UNKNOWN_CODESYSTEM_VERSION";
public static final String VALUESET_TOO_COSTLY = "VALUESET_TOO_COSTLY";
public static final String NO_VALID_DISPLAY_FOUND = "NO_VALID_DISPLAY_FOUND";
}

View File

@ -1,14 +1,17 @@
package org.hl7.fhir.utilities.validation;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import org.hl7.fhir.utilities.Utilities;
import java.util.HashSet;
public class ValidationOptions {
public enum ValueSetMode {
ALL_CHECKS, CHECK_MEMERSHIP_ONLY, NO_MEMBERSHIP_CHECK
}
private List<String> languages = new ArrayList<>();
private Set<String> languages = new HashSet<>();
private boolean useServer = true;
private boolean useClient = true;
private boolean guessSystem = false;
@ -36,7 +39,7 @@ public class ValidationOptions {
*
* @return
*/
public List<String> getLanguages() {
public Set<String> getLanguages() {
return languages;
}
@ -121,6 +124,9 @@ public class ValidationOptions {
public ValidationOptions withLanguage(String language) {
if (language == null) {
return this;
}
ValidationOptions n = this.copy();
n.languages.add(language);
return n;
@ -249,6 +255,14 @@ public class ValidationOptions {
"\"guessSystem\":\""+Boolean.toString(guessSystem)+"\", \"valueSetMode\":\""+valueSetMode.toString()+"\", \"versionFlexible\":\""+Boolean.toString(versionFlexible)+"\"";
}
public String langSummary() {
if (languages.size() == 0) {
return "--";
} else {
return String.join("|", Utilities.sorted(languages));
}
}

View File

@ -462,8 +462,8 @@ Version_mismatch_The_context_has_version__loaded_and_the_new_content_being_loade
Error_reading__from_package__ = Error reading {0} from package {1}#{2}: {3}
Error_parsing_ = Error parsing {0}:{1}
Unable_to_connect_to_terminology_server_Use_parameter_tx_na_tun_run_without_using_terminology_services_to_validate_LOINC_SNOMED_ICDX_etc_Error__ = Unable to connect to terminology server. Use parameter ''-tx n/a'' to run without using terminology services to validate LOINC, SNOMED, ICD-X etc. Error = {0}
Display_Name_for__should_be_one_of__instead_of_one = Wrong Display Name ''{4}'' for {1}#{2} - should be ''{3}'',
Display_Name_for__should_be_one_of__instead_of_other = Wrong Display Name ''{4}'' for {1}#{2} - should be one of {0} choices: ''{3}''
Display_Name_for__should_be_one_of__instead_of_one = Wrong Display Name ''{4}'' for {1}#{2} - should be ''{3}'' (for the language(s) ''{5}'')
Display_Name_for__should_be_one_of__instead_of_other = Wrong Display Name ''{4}'' for {1}#{2} - should be one of {0} choices: ''{3}'' for the language(s) ''{5}''
Unknown_Code__in_ = Unknown Code ''{0}'' in the system ''{1}''
UNKNOWN_CODE__IN_FRAGMENT = Unknown Code ''{0}'' in the system ''{1}'' - note that the code system is labeled as a fragment, so the code may be valid in some other fragment
Code_found_in_expansion_however_ = Code found in expansion, however: {0}
@ -910,5 +910,8 @@ UNKNOWN_CODESYSTEM = The CodeSystem {0} is unknown
UNKNOWN_CODESYSTEM_VERSION = The CodeSystem {0} version {1} is unknown. ValidVersions: {2}
UNABLE_TO_INFER_CODESYSTEM = The System URI could not be determined for the code {0} in the ValueSet {1}
VALUESET_TOO_COSTLY = The value set {0} has too many codes to display ({1})
NO_VALID_DISPLAY_FOUND_one = No valid Display Names found for {1}#{2} in the language {3}
NO_VALID_DISPLAY_FOUND_other = No valid Display Names found for {1}#{2} in the languages {3}

View File

@ -6386,7 +6386,14 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
// no delay on this one?
public ValidationResult checkCodeOnServer(NodeStack stack, String code, String system, String version, String display, boolean checkDisplay) {
return context.validateCode(baseOptions.withLanguage(stack.getWorkingLang()), system, version, code, checkDisplay ? display : null);
String lang = stack.getWorkingLang();
if (lang == null) {
lang = validationLanguage;
}
if (lang == null) {
lang = "en"; // ubiquitious default languauge
}
return context.validateCode(baseOptions.withLanguage(lang), system, version, code, checkDisplay ? display : null);
}
public ValidationResult checkCodeOnServer(NodeStack stack, ValueSet valueset, Coding c, boolean checkMembership) {

View File

@ -159,16 +159,22 @@ public class ValueSetValidator extends BaseValidator {
if (parent.isDebug()) {
System.out.println(" : Validate "+batch.size()+" codes from "+system+" for "+vsid);
}
context.validateCodeBatch(ValidationOptions.defaults(), batch, null);
if (parent.isDebug()) {
System.out.println(" : .. "+(System.currentTimeMillis()-t)+"ms");
}
for (VSCodingValidationRequest cv : batch) {
if (version == null) {
ok = warningOrHint(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE, system, cv.getCoding().getCode()) && ok;
} else {
ok = warningOrHint(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER, system, version, cv.getCoding().getCode()) && ok;
try {
context.validateCodeBatch(ValidationOptions.defaults(), batch, null);
if (parent.isDebug()) {
System.out.println(" : .. "+(System.currentTimeMillis()-t)+"ms");
}
for (VSCodingValidationRequest cv : batch) {
if (version == null) {
ok = warningOrHint(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE, system, cv.getCoding().getCode()) && ok;
} else {
ok = warningOrHint(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER, system, version, cv.getCoding().getCode()) && ok;
}
}
} catch (Exception e) {
ok = false;
VSCodingValidationRequest cv = batch.get(0);
rule(errors, NO_RULE_DATE, IssueType.EXCEPTION, cv.getStack().getLiteralPath(), false, e.getMessage());
}
}
@ -215,6 +221,9 @@ public class ValueSetValidator extends BaseValidator {
} else {
boolean ok = vv.isOk();
warning(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, stack.getLiteralPath(), ok, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER, system, version, code);
if (vv.getMessage() != null) {
hint(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, stack.getLiteralPath(), false, vv.getMessage());
}
}
}
return true;