-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
322 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/main/java/de/uksh/medic/etl/jobs/mdr/centraxx/CxxMdrAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package de.uksh.medic.etl.jobs.mdr.centraxx; | ||
|
||
import de.uksh.medic.etl.model.FhirAttributes; | ||
import de.uksh.medic.etl.model.mdr.centraxx.CxxAttributeValue; | ||
import de.uksh.medic.etl.model.mdr.centraxx.CxxList; | ||
import de.uksh.medic.etl.settings.CxxMdrSettings; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
import org.tinylog.Logger; | ||
|
||
/** | ||
* Class to fetch attributes from a Kairos CentraXX MDR. | ||
*/ | ||
public final class CxxMdrAttributes { | ||
|
||
private CxxMdrAttributes() { | ||
} | ||
|
||
/** | ||
* Retrieves a FhirAttributes object for a specified MDR attribute. | ||
* | ||
* @param mdr Configuration for MDR. | ||
* @param mdrProfile profile / form / ItemSet where the item is defined | ||
* @param key key of the requested attribute | ||
* @return FhirAttributes object | ||
* @throws URISyntaxException | ||
*/ | ||
public static FhirAttributes getAttributes(CxxMdrSettings mdr, String mdrProfile, String key) | ||
throws URISyntaxException { | ||
|
||
if (mdr.isTokenExpired()) { | ||
CxxMdrLogin.login(mdr); | ||
} | ||
|
||
MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); | ||
form.set("code", mdrProfile); | ||
form.set("domainCode", "fhir"); | ||
form.set("itemCode", key); | ||
|
||
RestTemplate rt = new RestTemplate(); | ||
HttpHeaders headers = new HttpHeaders(); | ||
UriComponentsBuilder builder = UriComponentsBuilder | ||
.fromHttpUrl(mdr.getUrl() + "/rest/v1/itemsets/attributes/item"); | ||
builder.queryParams(form); | ||
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString()); | ||
headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString()); | ||
headers.add("Authorization", "Bearer " + mdr.getToken()); | ||
try { | ||
ResponseEntity<CxxList> response = rt.exchange(builder.build().encode().toUri(), HttpMethod.GET, | ||
new HttpEntity<>(headers), CxxList.class); | ||
CxxList l = response.getBody(); | ||
if (l != null && l.getContent() != null) { | ||
FhirAttributes ch = new FhirAttributes(); | ||
for (CxxAttributeValue av : l.getContent()) { | ||
switch (av.getAttribute()) { | ||
case SYSTEM -> ch.setSystem(new URI(av.getValue())); | ||
case SOURCE -> ch.setSource(new URI(av.getValue())); | ||
case TARGET -> ch.setTarget(new URI(av.getValue())); | ||
case ID -> ch.setId(av.getValue()); | ||
case CONCEPTMAP -> ch.setConceptMap(new URI(av.getValue())); | ||
case CODE -> ch.setCode(av.getValue()); | ||
case VERSION -> ch.setVersion(av.getValue()); | ||
default -> { | ||
} | ||
} | ||
} | ||
return ch; | ||
} | ||
return null; | ||
|
||
} catch (final HttpClientErrorException e) { | ||
Logger.error("Object " + form.get("itemCode") + " not found in MDR!"); | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package de.uksh.medic.etl.model; | ||
|
||
import java.net.URI; | ||
|
||
public class FhirAttributes { | ||
|
||
private URI system; | ||
private URI source; | ||
private URI target; | ||
private URI conceptMap; | ||
private String id; | ||
private String code; | ||
private String version; | ||
|
||
public FhirAttributes() { | ||
} | ||
|
||
public URI getSystem() { | ||
return system; | ||
} | ||
|
||
public void setSystem(URI system) { | ||
this.system = system; | ||
} | ||
|
||
public URI getSource() { | ||
return source; | ||
} | ||
|
||
public void setSource(URI source) { | ||
this.source = source; | ||
} | ||
|
||
public URI getTarget() { | ||
return target; | ||
} | ||
|
||
public void setTarget(URI target) { | ||
this.target = target; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public URI getConceptMap() { | ||
return conceptMap; | ||
} | ||
|
||
public void setConceptMap(URI conceptMap) { | ||
this.conceptMap = conceptMap; | ||
} | ||
|
||
public String getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(String code) { | ||
this.code = code; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(String version) { | ||
this.version = version; | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/de/uksh/medic/etl/model/mdr/MdrAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package de.uksh.medic.etl.model.mdr; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
/** | ||
* Enum for Attributes queried from MDR. | ||
*/ | ||
public enum MdrAttributes { | ||
/** | ||
* system attribute in MDR. | ||
*/ | ||
SYSTEM("system"), | ||
/** | ||
* source attribute in MDR. | ||
*/ | ||
SOURCE("source"), | ||
/** | ||
* target attribute in MDR. | ||
*/ | ||
TARGET("target"), | ||
/** | ||
* ID attribute in MDR. | ||
*/ | ||
ID("id"), | ||
/** | ||
* conceptMap attribute in MDR. | ||
*/ | ||
CONCEPTMAP("conceptMap"), | ||
/** | ||
* code attribute in MDR. | ||
*/ | ||
CODE("code"), | ||
/** | ||
* version attribute in MDR. | ||
*/ | ||
VERSION("version"); | ||
|
||
private final String label; | ||
|
||
MdrAttributes(String label) { | ||
this.label = label; | ||
} | ||
|
||
@Override | ||
@JsonValue | ||
public String toString() { | ||
return this.label; | ||
} | ||
|
||
/** | ||
* Look Enum up from String. | ||
* @param s string to be looked up | ||
* @return corresponding Enum | ||
*/ | ||
@JsonCreator | ||
public static MdrAttributes fromString(String s) { | ||
for (MdrAttributes a : MdrAttributes.values()) { | ||
if (a.label.equalsIgnoreCase(s)) { | ||
return a; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/de/uksh/medic/etl/model/mdr/centraxx/CxxAttributeValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.uksh.medic.etl.model.mdr.centraxx; | ||
|
||
import de.uksh.medic.etl.model.mdr.MdrAttributes; | ||
import java.util.List; | ||
|
||
/** | ||
* Model for AttributeValue in Kairos CentraXX MDR. | ||
*/ | ||
public class CxxAttributeValue { | ||
|
||
private String domain; | ||
private MdrAttributes attribute; | ||
private String value; | ||
private List<CxxLinks> links; | ||
|
||
public String getDomain() { | ||
return domain; | ||
} | ||
|
||
public MdrAttributes getAttribute() { | ||
return attribute; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public List<CxxLinks> getLinks() { | ||
return links; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/de/uksh/medic/etl/model/mdr/centraxx/CxxList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.uksh.medic.etl.model.mdr.centraxx; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Model for List in Kairos CentraXX MDR. | ||
*/ | ||
public class CxxList { | ||
|
||
private List<CxxAttributeValue> content; | ||
private List<CxxLinks> links; | ||
|
||
public List<CxxAttributeValue> getContent() { | ||
return content; | ||
} | ||
|
||
public List<CxxLinks> getLinks() { | ||
return links; | ||
} | ||
|
||
} |