possible fix

This commit is contained in:
Gjergj Sheldija 2024-09-03 15:41:58 +02:00
parent 8e908da1ab
commit 973ab9e56f
4 changed files with 65 additions and 9 deletions

View File

@ -296,7 +296,10 @@ public class LanguageUtils {
}
}
}
for (Element c : element.getChildren()) {
// Create a copy of the children collection before iterating
List<Element> childrenCopy = new ArrayList<>(element.getChildren());
for (Element c : childrenCopy) {
if (!c.getName().equals("designation")) {
t = t + importFromTranslations(element, c, translations, usedUnits);
}

View File

@ -1,15 +1,20 @@
package org.hl7.fhir.r5.elementmodel;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.formats.JsonCreatorDirect;
import org.hl7.fhir.r5.test.utils.CompareUtilities;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer;
import org.hl7.fhir.utilities.i18n.PoGetTextProducer;
import org.hl7.fhir.utilities.tests.ResourceLoaderTests;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
class LanguageUtilsTest implements ResourceLoaderTests {
@ -27,11 +32,24 @@ class LanguageUtilsTest implements ResourceLoaderTests {
List<LanguageFileProducer.TranslationUnit> res = new ArrayList<>();
res.addAll(lp.loadSource(getResourceAsInputStream("languageUtils", "CodeSystem-answer.po")));
List<ValidationMessage> lvm = new ArrayList<>();
lvm.add(new ValidationMessage());
LanguageUtils languageUtils = new LanguageUtils(context);
int result = languageUtils.importFromTranslations(element, res, null);
int result = languageUtils.importFromTranslations(element, res, lvm);
Writer generatedResource = new StringWriter();
jp.compose(element, new JsonCreatorDirect(generatedResource, false, false));
assert result == 3;
InputStream translatedResource = getResourceAsInputStream("languageUtils", "CodeSystem-answer-translated.json");
String text = new BufferedReader(new InputStreamReader(translatedResource))
.lines()
.collect(Collectors.joining("\n"));
String msg = CompareUtilities.checkJsonSrcIsSame("", generatedResource.toString(),text, null);
Assertions.assertNull(msg);
}
}

View File

@ -0,0 +1,38 @@
{
"resourceType" : "CodeSystem",
"id" : "basic-answer",
"language" : "en",
"url" : "https://example.com/CodeSystem/basic-answer",
"version" : "0.1.0",
"name" : "BasicAnswer",
"title" : "Administration-Method",
"status" : "active",
"date" : "2024-04-07",
"publisher" : "Sample",
"description" : "Basic answers for any kind of questions.",
"caseSensitive" : false,
"content" : "complete",
"count" : 3,
"concept" : [ {
"code" : "ok",
"display" : "OK",
"designation" : [ {
"language" : "it",
"value" : "OK"
} ]
}, {
"code" : "yes",
"display" : "Yes",
"designation" : [ {
"language" : "it",
"value" : "Si"
} ]
}, {
"code" : "no",
"display" : "No",
"designation" : [ {
"language" : "it",
"value" : "No"
} ]
} ]
}

View File

@ -10,18 +10,15 @@
"concept": [
{
"code": "ok",
"display": "OK",
"definition": "KO"
"display": "OK"
},
{
"code": "yes",
"display": "Yes",
"definition": "seY"
"display": "Yes"
},
{
"code": "no",
"display": "No",
"definition": "oN"
"display": "No"
}
],
"language": "en",