Skip to content

Commit

Permalink
Merge pull request #1877 from hapifhir/2025-01-gg-obligations
Browse files Browse the repository at this point in the history
2025 01 gg obligations
  • Loading branch information
grahamegrieve authored Jan 12, 2025
2 parents 2d5a8e0 + 6b52ee5 commit cf0d398
Show file tree
Hide file tree
Showing 26 changed files with 473 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void process(String source, String dest, boolean onlyNew, boolean onlyAc
}

private void cleanValueSets(List<String> allOids, String dest) throws IOException {
cleanValueSets(allOids, new File(Utilities.path(dest)));
cleanValueSets(allOids, ManagedFileAccess.file(Utilities.path(dest)));
}

private void cleanValueSets(List<String> allOids, File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,10 @@ public Parameters translate(Parameters params) throws FHIRException {
return (Parameters) VersionConvertorFactory_10_50.convertResource(client.translate((org.hl7.fhir.dstu2.model.Parameters) VersionConvertorFactory_10_50.convertResource(params)));
}

@Override
public void setConversionLogger(ITerminologyConversionLogger logger) {
// TODO Auto-generated method stub

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,10 @@ public Parameters translate(Parameters params) throws FHIRException {
return (Parameters) VersionConvertorFactory_30_50.convertResource(client.transform((org.hl7.fhir.dstu3.model.Parameters) VersionConvertorFactory_30_50.convertResource(params)));
}

@Override
public void setConversionLogger(ITerminologyConversionLogger logger) {
// TODO Auto-generated method stub

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.utils.client.EFhirClientException;
import org.hl7.fhir.r4.utils.client.FHIRToolingClient;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.CapabilityStatement;
Expand All @@ -28,9 +30,10 @@

public class TerminologyClientR4 implements ITerminologyClient {

private final FHIRToolingClient client; // todo: use the R2 client
private final FHIRToolingClient client;
private ClientHeaders clientHeaders;
private String id;
private ITerminologyConversionLogger logger;

public TerminologyClientR4(String id, String address, String userAgent) throws URISyntaxException {
this.client = new FHIRToolingClient(address, userAgent);
Expand Down Expand Up @@ -71,7 +74,7 @@ public FhirPublication getActualVersion() {

@Override
public TerminologyCapabilities getTerminologyCapabilities() throws FHIRException {
return (TerminologyCapabilities) VersionConvertorFactory_40_50.convertResource(client.getTerminologyCapabilities());
return (TerminologyCapabilities) convertResource("getTerminologyCapabilities.response", client.getTerminologyCapabilities());
}

@Override
Expand All @@ -81,29 +84,30 @@ public String getAddress() {

@Override
public ValueSet expandValueset(ValueSet vs, Parameters p) throws FHIRException {
org.hl7.fhir.r4.model.ValueSet vs2 = vs == null ? null : (org.hl7.fhir.r4.model.ValueSet) VersionConvertorFactory_40_50.convertResource(vs);
org.hl7.fhir.r4.model.Parameters p2 = p == null ? null : (org.hl7.fhir.r4.model.Parameters) VersionConvertorFactory_40_50.convertResource(p);
org.hl7.fhir.r4.model.ValueSet vs2 = vs == null ? null : (org.hl7.fhir.r4.model.ValueSet) convertResource("expandValueset.valueset", vs);
org.hl7.fhir.r4.model.Parameters p2 = p == null ? null : (org.hl7.fhir.r4.model.Parameters) convertResource("expandValueset.parameters", p);
try {
vs2 = client.expandValueset(vs2, p2); // todo: second parameter
return (ValueSet) VersionConvertorFactory_40_50.convertResource(vs2);
return (ValueSet) convertResource("expandValueset.response", vs2);
} catch (org.hl7.fhir.r4.utils.client.EFhirClientException e) {
if (e.getServerErrors().size() > 0) {
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getCode(), e.getMessage(), (org.hl7.fhir.r5.model.OperationOutcome) VersionConvertorFactory_40_50.convertResource(e.getServerErrors().get(0)));
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getCode(), e.getMessage(), (org.hl7.fhir.r5.model.OperationOutcome) convertResource("expandValueset.error", e.getServerErrors().get(0)));
} else {
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getCode(), e.getMessage());
}
}
}


@Override
public Parameters validateCS(Parameters pin) throws FHIRException {
try {
org.hl7.fhir.r4.model.Parameters p2 = (org.hl7.fhir.r4.model.Parameters) VersionConvertorFactory_40_50.convertResource(pin);
org.hl7.fhir.r4.model.Parameters p2 = (org.hl7.fhir.r4.model.Parameters) convertResource("validateCS.request", pin);
p2 = client.operateType(org.hl7.fhir.r4.model.CodeSystem.class, "validate-code", p2);
return (Parameters) VersionConvertorFactory_40_50.convertResource(p2);
return (Parameters) convertResource("validateCS.response", p2);
} catch (EFhirClientException e) {
if (e.getServerErrors().size() == 1) {
OperationOutcome op = (OperationOutcome) VersionConvertorFactory_40_50.convertResource(e.getServerErrors().get(0));
OperationOutcome op = (OperationOutcome) convertResource("validateCS.error", e.getServerErrors().get(0));
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getCode(), e.getMessage(), op, e);
} else {
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getCode(), e.getMessage(), e);
Expand All @@ -117,12 +121,12 @@ public Parameters validateCS(Parameters pin) throws FHIRException {
@Override
public Parameters subsumes(Parameters pin) throws FHIRException {
try {
org.hl7.fhir.r4.model.Parameters p2 = (org.hl7.fhir.r4.model.Parameters) VersionConvertorFactory_40_50.convertResource(pin);
org.hl7.fhir.r4.model.Parameters p2 = (org.hl7.fhir.r4.model.Parameters) convertResource("subsumes.request", pin);
p2 = client.operateType(org.hl7.fhir.r4.model.CodeSystem.class, "subsumes", p2);
return (Parameters) VersionConvertorFactory_40_50.convertResource(p2);
return (Parameters) convertResource("subsumes.response", p2);
} catch (EFhirClientException e) {
if (e.getServerErrors().size() == 1) {
OperationOutcome op = (OperationOutcome) VersionConvertorFactory_40_50.convertResource(e.getServerErrors().get(0));
OperationOutcome op = (OperationOutcome) convertResource("subsumes.error", e.getServerErrors().get(0));
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getCode(), e.getMessage(), op, e);
} else {
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getCode(), e.getMessage(), e);
Expand All @@ -135,12 +139,12 @@ public Parameters subsumes(Parameters pin) throws FHIRException {
@Override
public Parameters validateVS(Parameters pin) throws FHIRException {
try {
org.hl7.fhir.r4.model.Parameters p2 = (org.hl7.fhir.r4.model.Parameters) VersionConvertorFactory_40_50.convertResource(pin);
org.hl7.fhir.r4.model.Parameters p2 = (org.hl7.fhir.r4.model.Parameters) convertResource("validateVS.request", pin);
p2 = client.operateType(org.hl7.fhir.r4.model.ValueSet.class, "validate-code", p2);
return (Parameters) VersionConvertorFactory_40_50.convertResource(p2);
return (Parameters) convertResource("validateVS.response", p2);
} catch (EFhirClientException e) {
if (e.getServerErrors().size() == 1) {
OperationOutcome op = (OperationOutcome) VersionConvertorFactory_40_50.convertResource(e.getServerErrors().get(0));
OperationOutcome op = (OperationOutcome) convertResource("validateVS.error", e.getServerErrors().get(0));
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getCode(), e.getMessage(), op, e);
} else {
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getCode(), e.getMessage(), e);
Expand Down Expand Up @@ -175,22 +179,22 @@ public ITerminologyClient setRetryCount(int retryCount) throws FHIRException {

@Override
public CapabilityStatement getCapabilitiesStatementQuick() throws FHIRException {
return (CapabilityStatement) VersionConvertorFactory_40_50.convertResource(client.getCapabilitiesStatementQuick());
return (CapabilityStatement) convertResource("getCapabilitiesStatementQuick.response", client.getCapabilitiesStatementQuick());
}

@Override
public CapabilityStatement getCapabilitiesStatement() throws FHIRException {
return (CapabilityStatement) VersionConvertorFactory_40_50.convertResource(client.getCapabilitiesStatement());
return (CapabilityStatement) convertResource("getCapabilitiesStatement.response", client.getCapabilitiesStatement());
}

@Override
public Parameters lookupCode(Map<String, String> params) throws FHIRException {
return (Parameters) VersionConvertorFactory_40_50.convertResource(client.lookupCode(params));
return (Parameters) convertResource("lookupCode.response", client.lookupCode(params));
}

@Override
public Parameters lookupCode(Parameters params) throws FHIRException {
return (Parameters) VersionConvertorFactory_40_50.convertResource(client.lookupCode((org.hl7.fhir.r4.model.Parameters) VersionConvertorFactory_40_50.convertResource(params)));
return (Parameters) convertResource("lookupCode.response", client.lookupCode((org.hl7.fhir.r4.model.Parameters) convertResource("lookupCode.request", params)));
}

@Override
Expand All @@ -200,8 +204,8 @@ public int getRetryCount() throws FHIRException {

@Override
public Bundle validateBatch(Bundle batch) {
org.hl7.fhir.r4.model.Bundle result = client.transaction((org.hl7.fhir.r4.model.Bundle) VersionConvertorFactory_40_50.convertResource(batch));
return result == null ? null : (Bundle) VersionConvertorFactory_40_50.convertResource(result);
org.hl7.fhir.r4.model.Bundle result = client.transaction((org.hl7.fhir.r4.model.Bundle) convertResource("validateBatch.request", batch));
return result == null ? null : (Bundle) convertResource("validateBatch.response", result);
}

@Override
Expand All @@ -216,7 +220,7 @@ public CanonicalResource read(String type, String id) {
if (r4 == null) {
throw new FHIRException("Unable to fetch resource " + Utilities.pathURL(getAddress(), type, id));
}
org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_40_50.convertResource(r4);
org.hl7.fhir.r5.model.Resource r5 = convertResource("read.result", r4);
if (r5 == null) {
throw new FHIRException("Unable to convert resource " + Utilities.pathURL(getAddress(), type, id) + " to R5 (internal representation)");
}
Expand Down Expand Up @@ -278,12 +282,55 @@ public int getUseCount() {
@Override
public Bundle search(String type, String criteria) {
org.hl7.fhir.r4.model.Bundle result = client.search(type, criteria);
return result == null ? null : (Bundle) VersionConvertorFactory_40_50.convertResource(result);
return result == null ? null : (Bundle) convertResource("search.result", result);
}

@Override
public Parameters translate(Parameters params) throws FHIRException {
return (Parameters) VersionConvertorFactory_40_50.convertResource(client.translate((org.hl7.fhir.r4.model.Parameters) VersionConvertorFactory_40_50.convertResource(params)));
return (Parameters) convertResource("translate.response", client.translate((org.hl7.fhir.r4.model.Parameters) convertResource("translate.request", params)));
}

private org.hl7.fhir.r4.model.Resource convertResource(String name, org.hl7.fhir.r5.model.Resource resource) {
if (logger != null) {
try {
logger.log(name, resource.fhirType(), "r5", new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeBytes(resource));
} catch (IOException e) {
throw new FHIRException(e);
}
}
org.hl7.fhir.r4.model.Resource res = VersionConvertorFactory_40_50.convertResource(resource);
if (logger != null) {
try {
logger.log(name, resource.fhirType(), "r4", new org.hl7.fhir.r4.formats.JsonParser().setOutputStyle(org.hl7.fhir.r4.formats.IParser.OutputStyle.PRETTY).composeBytes(res));
} catch (IOException e) {
throw new FHIRException(e);
}
}
return res;
}

private org.hl7.fhir.r5.model.Resource convertResource(String name, org.hl7.fhir.r4.model.Resource resource) {
if (logger != null && name != null) {
try {
logger.log(name, resource.fhirType(), "r4", new org.hl7.fhir.r4.formats.JsonParser().setOutputStyle(org.hl7.fhir.r4.formats.IParser.OutputStyle.PRETTY).composeBytes(resource));
} catch (IOException e) {
throw new FHIRException(e);
}
}
org.hl7.fhir.r5.model.Resource res = VersionConvertorFactory_40_50.convertResource(resource);
if (logger != null && name != null) {
try {
logger.log(name, resource.fhirType(), "r5", new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeBytes(res));
} catch (IOException e) {
throw new FHIRException(e);
}
}
return res;
}

@Override
public void setConversionLogger(ITerminologyConversionLogger logger) {
this.logger = logger;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public void renderTable(RenderingStatus status, ResourceWrapper res, List<XhtmlN
if (ad == null) {
actorId.addText(anActor.getCanonical());
} else {
actorId.ah(ad.getWebPath()).tx(ad.getTitle());
actorId.ah(ad.getWebPath()).tx(ad.present());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ private void scanObligations(List<Column> columns, List<ElementDefinition> list)
if (actor == null) {
columns.add(new Column(col, tail(col), context.formatPhrase(RenderingContext.STRUC_DEF_UNDEF_ACT, col, col)+" "));
} else {
columns.add(new Column(col, actor.getName(), context.formatPhrase(RenderingContext.STRUC_DEF_ACT, actor.present(), actor.getWebPath())+" "));
columns.add(new Column(col, actor.present(), context.formatPhrase(RenderingContext.STRUC_DEF_ACT, actor.present(), actor.getWebPath())+" "));
}
}
}
Expand Down Expand Up @@ -1761,7 +1761,6 @@ else if (definition.hasBinding())
obr.seeObligations(profile.getExtensionsByUrl(ToolingExtensions.EXT_OBLIGATION_CORE, ToolingExtensions.EXT_OBLIGATION_TOOLS));
}
obr.renderTable(status, res, gen, c, inScopeElements);

if (definition.hasMaxLength() && definition.getMaxLength()!=0) {
if (!c.getPieces().isEmpty()) { c.addPiece(gen.new Piece("br")); }
c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, context.formatPhrase(RenderingContext.GENERAL_MAX_LENGTH), null).addStyle("font-weight:bold")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ public interface ITerminologyClient {
String getUserAgent();
int getUseCount();
Bundle search(String type, String criteria);

// internal conversion logging
public interface ITerminologyConversionLogger {
void log(String name, String resourceType, String version, byte[] cnt);
}
void setConversionLogger(ITerminologyConversionLogger logger);
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,11 @@ public Parameters translate(Parameters params) throws FHIRException {
return client.translate(params);
}

@Override
public void setConversionLogger(ITerminologyConversionLogger logger) {
// TODO Auto-generated method stub

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;
import org.hl7.fhir.utilities.http.HTTPResult;
import org.hl7.fhir.utilities.http.ManagedWebAccess;
import org.hl7.fhir.utilities.json.JsonException;
Expand Down Expand Up @@ -297,8 +298,8 @@ private void executeProfile() throws IOException {
}

private void checkDownloadBaseData() throws IOException {
localData = new File(Utilities.path("[tmp]", "fhir-test-data.db"));
File localInfo = new File(Utilities.path("[tmp]", "fhir-test-data.json"));
localData = ManagedFileAccess.file(Utilities.path("[tmp]", "fhir-test-data.db"));
File localInfo = ManagedFileAccess.file(Utilities.path("[tmp]", "fhir-test-data.json"));
try {
JsonObject local = localInfo.exists() ? JsonParser.parseObject(localInfo) : null;
JsonObject json = JsonParser.parseObjectFromUrl("http://fhir.org/downloads/test-data-versions.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.poi.ss.usermodel.*;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

Expand Down Expand Up @@ -37,7 +38,7 @@ public class ExcelDataProvider extends TableDataProvider {
* @throws InvalidFormatException If the file format is invalid.
*/
public ExcelDataProvider(String filename, String sheetName) throws IOException, InvalidFormatException {
FileInputStream fis = new FileInputStream(new File(filename));
FileInputStream fis = new FileInputStream(ManagedFileAccess.file(filename));
this.workbook = WorkbookFactory.create(fis);
if (sheetName != null) {
this.sheet = workbook.getSheet(sheetName);
Expand All @@ -60,7 +61,7 @@ public ExcelDataProvider(String filename, String sheetName) throws IOException,


public ExcelDataProvider(String filename) throws InvalidFormatException, IOException {
FileInputStream fis = new FileInputStream(new File(filename));
FileInputStream fis = new FileInputStream(ManagedFileAccess.file(filename));
this.workbook = WorkbookFactory.create(fis);
this.sheet = workbook.getSheetAt(0);
loadColumnHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ public static File createDirectory(String path) throws IOException {
return ManagedFileAccess.file(path);
}

public static File createDirectoryNC(String path) throws IOException {
ManagedFileAccess.file(path).mkdirs();
return ManagedFileAccess.file(path);
}

public static String changeFileExt(String name, String ext) {
if (name.lastIndexOf('.') > -1)
return name.substring(0, name.lastIndexOf('.')) + ext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private void generate(String source, String src, String dest, String tgt, int co
// save the destination file
String fn = Utilities.path(source, "source", dest);
List<POObject> objects;
if (new File(fn).exists()) {
if (ManagedFileAccess.file(fn).exists()) {
objects = loadPOFile(fn);
} else {
objects = new ArrayList<POGenerator.POObject>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ public JsonObject add(String name, JsonElement value) throws JsonException {
propMap.put(name, p);
return this;
}

public JsonObject add(int index, String name, JsonElement value) throws JsonException {
check(name != null, "Json Property Name is null");
check(value != null, "Json Property Value is null");
if (get(name) != null) {
check(false, "Name '"+name+"' already exists (value = "+get(name).toString()+")");
}
JsonProperty p = new JsonProperty(name, value);
properties.add(index, p);
propMap.put(name, p);
return this;
}

public JsonObject addIfNotNull(String name, JsonElement value) throws JsonException {
if (value != null) {
Expand Down Expand Up @@ -347,6 +359,16 @@ public JsonArray forceArray(String name) throws JsonException {
}
return getJsonArray(name);
}

public JsonArray forceArray(int index, String name) throws JsonException {
if (has(name) && !hasArray(name)) {
remove(name);
}
if (!has(name)) {
add(index, name, new JsonArray());
}
return getJsonArray(name);
}

public List<JsonObject> getJsonObjects(String name) {
List<JsonObject> res = new ArrayList<>();
Expand Down
Loading

0 comments on commit cf0d398

Please sign in to comment.