Merge pull request #586 from hapifhir/gg-202108-vr-system

Gg 202108 vr system
This commit is contained in:
Grahame Grieve 2021-08-25 06:20:31 +10:00 committed by GitHub
commit 5ac31d11ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 27 deletions

View File

@ -1062,6 +1062,8 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
boolean ok = false; boolean ok = false;
String message = "No Message returned"; String message = "No Message returned";
String display = null; String display = null;
String system = null;
String code = null;
TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN; TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
for (ParametersParameterComponent p : pOut.getParameter()) { for (ParametersParameterComponent p : pOut.getParameter()) {
if (p.hasValue()) { if (p.hasValue()) {
@ -1071,6 +1073,10 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
message = ((StringType) p.getValue()).getValue(); message = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("display")) { } else if (p.getName().equals("display")) {
display = ((StringType) p.getValue()).getValue(); display = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("system")) {
system = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("code")) {
code = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("cause")) { } else if (p.getName().equals("cause")) {
try { try {
IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue()); IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue());
@ -1089,11 +1095,11 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
if (!ok) { if (!ok) {
return new ValidationResult(IssueSeverity.ERROR, message+" (from "+txClient.getAddress()+")", err).setTxLink(txLog.getLastId()); return new ValidationResult(IssueSeverity.ERROR, message+" (from "+txClient.getAddress()+")", err).setTxLink(txLog.getLastId());
} else if (message != null && !message.equals("No Message returned")) { } else if (message != null && !message.equals("No Message returned")) {
return new ValidationResult(IssueSeverity.WARNING, message+" (from "+txClient.getAddress()+")", new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()); return new ValidationResult(IssueSeverity.WARNING, message+" (from "+txClient.getAddress()+")", system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
} else if (display != null) { } else if (display != null) {
return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()); return new ValidationResult(system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
} else { } else {
return new ValidationResult(new ConceptDefinitionComponent()).setTxLink(txLog.getLastId()); return new ValidationResult(system, new ConceptDefinitionComponent().setCode(code)).setTxLink(txLog.getLastId());
} }
} }

View File

@ -538,6 +538,7 @@ public interface IWorkerContext {
class ValidationResult { class ValidationResult {
private ConceptDefinitionComponent definition; private ConceptDefinitionComponent definition;
private String system;
private IssueSeverity severity; private IssueSeverity severity;
private String message; private String message;
private TerminologyServiceErrorClass errorClass; private TerminologyServiceErrorClass errorClass;
@ -548,13 +549,15 @@ public interface IWorkerContext {
this.message = message; this.message = message;
} }
public ValidationResult(ConceptDefinitionComponent definition) { public ValidationResult(String system, ConceptDefinitionComponent definition) {
this.system = system;
this.definition = definition; this.definition = definition;
} }
public ValidationResult(IssueSeverity severity, String message, ConceptDefinitionComponent definition) { public ValidationResult(IssueSeverity severity, String message, String system, ConceptDefinitionComponent definition) {
this.severity = severity; this.severity = severity;
this.message = message; this.message = message;
this.system = system;
this.definition = definition; this.definition = definition;
} }
@ -568,12 +571,18 @@ public interface IWorkerContext {
return severity == null || severity == IssueSeverity.INFORMATION || severity == IssueSeverity.WARNING; return severity == null || severity == IssueSeverity.INFORMATION || severity == IssueSeverity.WARNING;
} }
public String getSystem() {
return system;
}
public String getDisplay() { public String getDisplay() {
// We don't want to return question-marks because that prevents something more useful from being displayed (e.g. the code) if there's no display value
// return definition == null ? "??" : definition.getDisplay();
return definition == null ? null : definition.getDisplay(); return definition == null ? null : definition.getDisplay();
} }
public String getCode() {
return definition == null ? null : definition.getCode();
}
public ConceptDefinitionComponent asConceptDefinition() { public ConceptDefinitionComponent asConceptDefinition() {
return definition; return definition;
} }

View File

@ -333,6 +333,8 @@ public class TerminologyCache {
} else { } else {
sw.write("v: {\r\n"); sw.write("v: {\r\n");
sw.write(" \"display\" : \""+Utilities.escapeJson(ce.v.getDisplay()).trim()+"\",\r\n"); sw.write(" \"display\" : \""+Utilities.escapeJson(ce.v.getDisplay()).trim()+"\",\r\n");
sw.write(" \"code\" : \""+Utilities.escapeJson(ce.v.getCode()).trim()+"\",\r\n");
sw.write(" \"system\" : \""+Utilities.escapeJson(ce.v.getSystem()).trim()+"\",\r\n");
sw.write(" \"severity\" : "+(ce.v.getSeverity() == null ? "null" : "\""+ce.v.getSeverity().toCode().trim()+"\"")+",\r\n"); sw.write(" \"severity\" : "+(ce.v.getSeverity() == null ? "null" : "\""+ce.v.getSeverity().toCode().trim()+"\"")+",\r\n");
sw.write(" \"error\" : \""+Utilities.escapeJson(ce.v.getMessage()).trim()+"\"\r\n}\r\n"); sw.write(" \"error\" : \""+Utilities.escapeJson(ce.v.getMessage()).trim()+"\"\r\n}\r\n");
} }
@ -379,7 +381,9 @@ public class TerminologyCache {
} else { } else {
IssueSeverity severity = o.get("severity") instanceof JsonNull ? null : IssueSeverity.fromCode(o.get("severity").getAsString()); IssueSeverity severity = o.get("severity") instanceof JsonNull ? null : IssueSeverity.fromCode(o.get("severity").getAsString());
String display = loadJS(o.get("display")); String display = loadJS(o.get("display"));
ce.v = new ValidationResult(severity, error, new ConceptDefinitionComponent().setDisplay(display)); String code = loadJS(o.get("code"));
String system = loadJS(o.get("system"));
ce.v = new ValidationResult(severity, error, system, new ConceptDefinitionComponent().setDisplay(display).setCode(code));
} }
nc.map.put(String.valueOf(hashNWS(ce.request)), ce); nc.map.put(String.valueOf(hashNWS(ce.request)), ce);
nc.list.add(ce); nc.list.add(ce);

View File

@ -189,9 +189,9 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
ObservationNode obs = new ObservationNode(); ObservationNode obs = new ObservationNode();
obs.ref = b.get("reference").primitiveValue(); obs.ref = b.get("reference").primitiveValue();
obs.obs = resolveReference(rw, obs.ref); obs.obs = resolveReference(rw, obs.ref);
if (obs.obs.getResource() != null) { if (obs.obs != null && obs.obs.getResource() != null) {
PropertyWrapper t = getProperty(obs.obs.getResource(), "contained"); PropertyWrapper t = getProperty(obs.obs.getResource(), "contained");
if (t.hasValues()) { if (t != null && t.hasValues()) {
obs.contained = fetchObservations(t.getValues(), rw); obs.contained = fetchObservations(t.getValues(), rw);
} }
} }
@ -239,7 +239,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
private boolean scanObsForRefRange(List<ObservationNode> observations) { private boolean scanObsForRefRange(List<ObservationNode> observations) {
for (ObservationNode o : observations) { for (ObservationNode o : observations) {
if (o.obs.getResource() != null) { if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "referenceRange"); PropertyWrapper pw = getProperty(o.obs.getResource(), "referenceRange");
if (valued(pw)) { if (valued(pw)) {
return true; return true;
@ -256,7 +256,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
private boolean scanObsForNote(List<ObservationNode> observations) { private boolean scanObsForNote(List<ObservationNode> observations) {
for (ObservationNode o : observations) { for (ObservationNode o : observations) {
if (o.obs.getResource() != null) { if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "note"); PropertyWrapper pw = getProperty(o.obs.getResource(), "note");
if (valued(pw)) { if (valued(pw)) {
return true; return true;
@ -273,7 +273,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
private boolean scanObsForIssued(List<ObservationNode> observations, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException { private boolean scanObsForIssued(List<ObservationNode> observations, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
for (ObservationNode o : observations) { for (ObservationNode o : observations) {
if (o.obs.getResource() != null) { if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "issued"); PropertyWrapper pw = getProperty(o.obs.getResource(), "issued");
if (valued(pw)) { if (valued(pw)) {
if (!Base.compareDeep(pw.value().getBase(), iss, true)) { if (!Base.compareDeep(pw.value().getBase(), iss, true)) {
@ -292,7 +292,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
private boolean scanObsForEffective(List<ObservationNode> observations, DataType eff) throws UnsupportedEncodingException, FHIRException, IOException { private boolean scanObsForEffective(List<ObservationNode> observations, DataType eff) throws UnsupportedEncodingException, FHIRException, IOException {
for (ObservationNode o : observations) { for (ObservationNode o : observations) {
if (o.obs.getResource() != null) { if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "effective[x]"); PropertyWrapper pw = getProperty(o.obs.getResource(), "effective[x]");
if (valued(pw)) { if (valued(pw)) {
if (!Base.compareDeep(pw.value().getBase(), eff, true)) { if (!Base.compareDeep(pw.value().getBase(), eff, true)) {
@ -311,7 +311,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
private boolean scanObsForFlags(List<ObservationNode> observations) throws UnsupportedEncodingException, FHIRException, IOException { private boolean scanObsForFlags(List<ObservationNode> observations) throws UnsupportedEncodingException, FHIRException, IOException {
for (ObservationNode o : observations) { for (ObservationNode o : observations) {
if (o.obs.getResource() != null) { if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "interpretation"); PropertyWrapper pw = getProperty(o.obs.getResource(), "interpretation");
if (valued(pw)) { if (valued(pw)) {
return true; return true;
@ -335,15 +335,15 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
private void addObservationToTable(XhtmlNode tbl, ObservationNode o, int i, String cs, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException { private void addObservationToTable(XhtmlNode tbl, ObservationNode o, int i, String cs, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tr = tbl.tr(); XhtmlNode tr = tbl.tr();
if (o.obs.getReference() == null) { if (o.obs != null && o.obs.getReference() == null) {
XhtmlNode td = tr.td().colspan(cs); XhtmlNode td = tr.td().colspan(cs);
td.i().tx("This Observation could not be resolved"); td.i().tx("This Observation could not be resolved");
} else { } else {
if (o.obs.getResource() != null) { if (o.obs != null && o.obs.getResource() != null) {
addObservationToTable(tr, o.obs.getResource(), i, o.obs.getReference(), refRange, flags, note, effectiveTime, issued, eff, iss); addObservationToTable(tr, o.obs.getResource(), i, o.obs.getReference(), refRange, flags, note, effectiveTime, issued, eff, iss);
} else { } else {
XhtmlNode td = tr.td().colspan(cs); XhtmlNode td = tr.td().colspan(cs);
td.i().ah(o.obs.getReference()).tx("Observation"); td.i().tx("Observation");
} }
if (o.contained != null) { if (o.contained != null) {
for (ObservationNode c : o.contained) { for (ObservationNode c : o.contained) {

View File

@ -176,7 +176,7 @@ public class ValueSetCheckerSimple extends ValueSetWorker implements ValueSetChe
res = validateCode(code, cs); res = validateCode(code, cs);
} else if (cs == null && valueset.hasExpansion() && inExpansion) { } else if (cs == null && valueset.hasExpansion() && inExpansion) {
// we just take the value set as face value then // we just take the value set as face value then
res = new ValidationResult(new ConceptDefinitionComponent().setCode(code.getCode()).setDisplay(code.getDisplay())); res = new ValidationResult(system, new ConceptDefinitionComponent().setCode(code.getCode()).setDisplay(code.getDisplay()));
} else { } else {
// well, we didn't find a code system - try the expansion? // well, we didn't find a code system - try the expansion?
// disabled waiting for discussion // disabled waiting for discussion
@ -193,7 +193,7 @@ public class ValueSetCheckerSimple extends ValueSetWorker implements ValueSetChe
Boolean ok = codeInValueSet(system, code.getCode()); Boolean ok = codeInValueSet(system, code.getCode());
if (ok == null || !ok) { if (ok == null || !ok) {
if (res == null) { if (res == null) {
res = new ValidationResult(null, null); res = new ValidationResult((IssueSeverity) null, null);
} }
if (!inExpansion && !inInclude) { if (!inExpansion && !inInclude) {
res.setMessage("Not in value set "+valueset.getUrl()).setSeverity(IssueSeverity.ERROR); res.setMessage("Not in value set "+valueset.getUrl()).setSeverity(IssueSeverity.ERROR);
@ -258,7 +258,7 @@ public class ValueSetCheckerSimple extends ValueSetWorker implements ValueSetChe
ConceptDefinitionComponent ccd = new ConceptDefinitionComponent(); ConceptDefinitionComponent ccd = new ConceptDefinitionComponent();
ccd.setCode(containsComponent.getCode()); ccd.setCode(containsComponent.getCode());
ccd.setDisplay(containsComponent.getDisplay()); ccd.setDisplay(containsComponent.getDisplay());
ValidationResult res = new ValidationResult(ccd); ValidationResult res = new ValidationResult(code.getSystem(), ccd);
return res; return res;
} }
if (containsComponent.hasContains()) { if (containsComponent.hasContains()) {
@ -300,19 +300,19 @@ public class ValueSetCheckerSimple extends ValueSetWorker implements ValueSetChe
} }
} }
if (code.getDisplay() == null) { if (code.getDisplay() == null) {
return new ValidationResult(cc); return new ValidationResult(code.getSystem(), cc);
} }
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (cc.hasDisplay()) { if (cc.hasDisplay()) {
b.append(cc.getDisplay()); b.append(cc.getDisplay());
if (code.getDisplay().equalsIgnoreCase(cc.getDisplay())) { if (code.getDisplay().equalsIgnoreCase(cc.getDisplay())) {
return new ValidationResult(cc); return new ValidationResult(code.getSystem(), cc);
} }
} }
for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) { for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
b.append(ds.getValue()); b.append(ds.getValue());
if (code.getDisplay().equalsIgnoreCase(ds.getValue())) { if (code.getDisplay().equalsIgnoreCase(ds.getValue())) {
return new ValidationResult(cc); return new ValidationResult(code.getSystem(), cc);
} }
} }
// also check to see if the value set has another display // also check to see if the value set has another display
@ -321,17 +321,17 @@ public class ValueSetCheckerSimple extends ValueSetWorker implements ValueSetChe
if (vs.hasDisplay()) { if (vs.hasDisplay()) {
b.append(vs.getDisplay()); b.append(vs.getDisplay());
if (code.getDisplay().equalsIgnoreCase(vs.getDisplay())) { if (code.getDisplay().equalsIgnoreCase(vs.getDisplay())) {
return new ValidationResult(cc); return new ValidationResult(code.getSystem(), cc);
} }
} }
for (ConceptReferenceDesignationComponent ds : vs.getDesignation()) { for (ConceptReferenceDesignationComponent ds : vs.getDesignation()) {
b.append(ds.getValue()); b.append(ds.getValue());
if (code.getDisplay().equalsIgnoreCase(ds.getValue())) { if (code.getDisplay().equalsIgnoreCase(ds.getValue())) {
return new ValidationResult(cc); return new ValidationResult(code.getSystem(), cc);
} }
} }
} }
return new ValidationResult(IssueSeverity.WARNING, context.formatMessage(I18nConstants.DISPLAY_NAME_FOR__SHOULD_BE_ONE_OF__INSTEAD_OF_, code.getSystem(), code.getCode(), b.toString(), code.getDisplay()), cc); return new ValidationResult(IssueSeverity.WARNING, context.formatMessage(I18nConstants.DISPLAY_NAME_FOR__SHOULD_BE_ONE_OF__INSTEAD_OF_, code.getSystem(), code.getCode(), b.toString(), code.getDisplay()), code.getSystem(), cc);
} }
private ConceptReferenceComponent findValueSetRef(String system, String code) { private ConceptReferenceComponent findValueSetRef(String system, String code) {