Skip to content

Commit 5072657

Browse files
restored white space changes.
1 parent 0fa7a72 commit 5072657

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

docker/service/src/main/java/uk/nhs/adaptors/scr/mappings/from/fhir/CompositionMapper.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import static uk.nhs.adaptors.scr.utils.FhirHelper.randomUUID;
2121

2222
/**
23-
* An FHIR SCR will contain multiple resource-types. The parent resourceType
24-
* will be Bundle.
25-
* Others may include Composition, Practitioner, PractitionerRole, Organization
26-
* and Patient.
23+
* An FHIR SCR will contain multiple resource-types. The parent resourceType will be Bundle.
24+
* Others may include Composition, Practitioner, PractitionerRole, Organization and Patient.
2725
* This is the FHIR to HL7 mapper of the Composition resource type.
2826
*
2927
* See: src/test/resources/gp_summary/standard_gp_summary.json
@@ -75,25 +73,21 @@ private static void validateCategory(Composition composition) {
7573
}
7674
Coding category = composition.getCategoryFirstRep().getCodingFirstRep();
7775
if (!SNOMED_SYSTEM.equals(category.getSystem())) {
78-
throw new FhirValidationException(
79-
"Composition.category.coding.system not supported: " + category.getSystem());
76+
throw new FhirValidationException("Composition.category.coding.system not supported: " + category.getSystem());
8077
}
8178
if (!CARE_PROFESSIONAL_DOC_CODE.equals(category.getCode())) {
8279
throw new FhirValidationException("Composition.category.coding.code not supported: " + category.getCode());
8380
}
8481
if (!CARE_PROFESSIONAL_DOC_DISPLAY.equals(category.getDisplay())) {
85-
throw new FhirValidationException(
86-
"Composition.category.coding.display not supported: " + category.getDisplay());
82+
throw new FhirValidationException("Composition.category.coding.display not supported: " + category.getDisplay());
8783
}
8884
}
8985

90-
private static void setCompositionRelatesToId(GpSummary gpSummary, Composition composition)
91-
throws FhirMappingException {
86+
private static void setCompositionRelatesToId(GpSummary gpSummary, Composition composition) throws FhirMappingException {
9287
if (composition.hasRelatesTo()) {
9388
var relatesTo = composition.getRelatesToFirstRep();
9489
if (!REPLACES.equals(relatesTo.getCode())) {
95-
throw new FhirValidationException(
96-
"Unsupported Composition.relatesTo.code element: " + relatesTo.getCode());
90+
throw new FhirValidationException("Unsupported Composition.relatesTo.code element: " + relatesTo.getCode());
9791
}
9892
if (relatesTo.getTargetIdentifier().hasValue()) {
9993
gpSummary.setCompositionRelatesToId(relatesTo.getTargetIdentifier().getValue());

docker/service/src/main/java/uk/nhs/adaptors/scr/mappings/from/hl7/HtmlParser.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,45 +48,44 @@ public List<Composition.SectionComponent> parse(Node html) {
4848
removeEmptyNodes(html);
4949

5050
var bodyNode = xmlUtils.getNodesByXPath(html, "./body").stream()
51-
.findFirst()
52-
.orElseThrow(() -> new IllegalStateException("Missing body node in html"));
51+
.findFirst()
52+
.orElseThrow(() -> new IllegalStateException("Missing body node in html"));
5353

5454
var childNodes = bodyNode.getChildNodes();
5555
if (childNodes.getLength() != 0 && !H2.equals(childNodes.item(0).getNodeName())) {
5656
throw new IllegalStateException("First body node must be H2");
5757
}
5858

59-
// this will hold a list of paris: H2 node as key and all next nodes (until next
60-
// H2 or body end) as a new Document
59+
// this will hold a list of paris: H2 node as key and all next nodes (until next H2 or body end) as a new Document
6160
var items = new ArrayList<Pair<Node, Document>>();
6261
Document targetDocument = null;
6362
for (int i = 0; i < childNodes.getLength(); i++) {
6463
var currentNode = childNodes.item(i);
6564
if (H2.equals(currentNode.getNodeName())) {
66-
// since this is the H2, we begin to capture following nodes as a new Document
65+
//since this is the H2, we begin to capture following nodes as a new Document
6766
targetDocument = createNewDocument("div", "http://www.w3.org/1999/xhtml");
6867
items.add(Pair.of(currentNode, targetDocument));
6968
} else {
7069
if (targetDocument == null) {
7170
throw new IllegalStateException("Target document not initialized");
7271
}
7372
targetDocument.getDocumentElement()
74-
.appendChild(targetDocument.importNode(currentNode, true));
73+
.appendChild(targetDocument.importNode(currentNode, true));
7574
}
7675
}
7776

7877
return items.stream()
79-
.map(kv -> ParsedHtml
80-
.builder()
81-
.html(serialize(kv.getValue()))
82-
.h2Value(kv.getKey().getTextContent())
83-
.h2Id(Optional.ofNullable(kv.getKey().getAttributes())
84-
.map(h2IdAttribute -> h2IdAttribute.getNamedItem("id"))
85-
.map(Node::getNodeValue)
86-
.orElse(null))
87-
.build())
88-
.map(HtmlParser::buildSectionComponent)
89-
.collect(Collectors.toList());
78+
.map(kv -> ParsedHtml
79+
.builder()
80+
.html(serialize(kv.getValue()))
81+
.h2Value(kv.getKey().getTextContent())
82+
.h2Id(Optional.ofNullable(kv.getKey().getAttributes())
83+
.map(h2IdAttribute -> h2IdAttribute.getNamedItem("id"))
84+
.map(Node::getNodeValue)
85+
.orElse(null))
86+
.build())
87+
.map(HtmlParser::buildSectionComponent)
88+
.collect(Collectors.toList());
9089
}
9190

9291
@SneakyThrows
@@ -108,30 +107,32 @@ public static String serialize(Document document) {
108107
@SneakyThrows
109108
public static void removeEmptyNodes(Node document) {
110109
XPathExpression xpathExp = XPathFactory.newInstance().newXPath()
111-
.compile("//text()[normalize-space(.) = '']");
110+
.compile("//text()[normalize-space(.) = '']");
112111
NodeList emptyTextNodes = (NodeList) xpathExp.evaluate(document, XPathConstants.NODESET);
113112
for (int i = 0; i < emptyTextNodes.getLength(); i++) {
114113
Node emptyTextNode = emptyTextNodes.item(i);
115114
emptyTextNode.getParentNode().removeChild(emptyTextNode);
116115
}
117116

117+
118118
}
119119

120+
120121
private static Composition.SectionComponent buildSectionComponent(ParsedHtml parsedHtml) {
121122
var sectionComponent = new Composition.SectionComponent()
122-
.setTitle(parsedHtml.h2Value)
123-
.setText(buildNarrative(parsedHtml.html));
123+
.setTitle(parsedHtml.h2Value)
124+
.setText(buildNarrative(parsedHtml.html));
124125
if (StringUtils.isNotBlank(parsedHtml.h2Id)) {
125126
sectionComponent.setCode(new CodeableConcept()
126-
.addCoding(new Coding()
127-
.setCode(parsedHtml.h2Id)));
127+
.addCoding(new Coding()
128+
.setCode(parsedHtml.h2Id)));
128129
}
129130
return sectionComponent;
130131
}
131132

132133
private static Narrative buildNarrative(String html) {
133134
var narrative = new Narrative()
134-
.setStatus(Narrative.NarrativeStatus.GENERATED);
135+
.setStatus(Narrative.NarrativeStatus.GENERATED);
135136
narrative.setDivAsString(html);
136137
return narrative;
137138
}

0 commit comments

Comments
 (0)