-
Notifications
You must be signed in to change notification settings - Fork 264
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
1 parent
5e26cdb
commit 1b48661
Showing
4 changed files
with
258 additions
and
4 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
167 changes: 167 additions & 0 deletions
167
frontend/src/components/admin/menu/ApplicationProperties.js
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,167 @@ | ||
import React, { useContext, useEffect, useState } from "react"; | ||
import { | ||
getFromOpenElisServer, | ||
postToOpenElisServerJsonResponse, | ||
} from "../../utils/Utils"; | ||
import { FormattedMessage, useIntl } from "react-intl"; | ||
import { NotificationContext } from "../../layout/Layout"; | ||
import { AlertDialog } from "../../common/CustomNotification"; | ||
import { | ||
Grid, | ||
Heading, | ||
Column, | ||
Section, | ||
TextInput, | ||
Button, | ||
Loading, | ||
} from "@carbon/react"; | ||
import PageBreadCrumb from "../../common/PageBreadCrumb"; | ||
|
||
export const CommonProperties = () => { | ||
const [commonProperties, setCommonProperties] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState(null); | ||
const intl = useIntl(); | ||
|
||
const { notificationVisible, addNotification, setNotificationVisible } = | ||
useContext(NotificationContext); | ||
|
||
useEffect(() => { | ||
getFromOpenElisServer( | ||
"/rest/properties", | ||
(fetchedProperties, err) => { | ||
if (err) { | ||
setError(err); | ||
setLoading(false); // Set loading to false in case of error | ||
} else { | ||
setCommonProperties(fetchedProperties); | ||
setLoading(false); // Set loading to false after data is fetched | ||
} | ||
}, | ||
); | ||
}, []); | ||
|
||
const handleSubmit = () => { | ||
setLoading(true); | ||
const url = `/rest/properties`; | ||
let body = JSON.stringify(commonProperties); | ||
postToOpenElisServerJsonResponse(url, body, (response, err) => { | ||
console.log("response from server", response); | ||
}); | ||
addNotification({ | ||
kind: "success", | ||
message: intl.formatMessage({ id: "message.propertiesupdate.success" }), | ||
title: intl.formatMessage({ id: "notification.title" }), | ||
}); | ||
setNotificationVisible(true); | ||
|
||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div style={{ marginLeft: "12em", marginRight: "8em" }}> | ||
{notificationVisible === true ? <AlertDialog /> : ""} | ||
<PageBreadCrumb breadcrumbs={[{ label: "home.label", link: "/" }]} /> | ||
<Grid fullWidth={true}> | ||
<Column lg={16}> | ||
<Section> | ||
<Section> | ||
<Heading> | ||
<FormattedMessage | ||
id="ewfggwgewgewgweg" | ||
defaultMessage="Common Properties" | ||
/> | ||
</Heading> | ||
</Section> | ||
</Section> | ||
</Column> | ||
</Grid> | ||
{loading && <Loading />} {error && <p>Error: {error}</p>}{" "} | ||
<div className="orderLegendBody"> | ||
<Grid fullWidth={true}> | ||
<Column lg={8}> | ||
{commonProperties && ( | ||
<> | ||
{Object.keys(commonProperties) | ||
.slice( | ||
0, | ||
Math.ceil(Object.keys(commonProperties).length / 2), | ||
) | ||
.map((key) => { | ||
// Remove the prefix "org.openelisglobal" using regex | ||
let shortKey = key.replace(/^org\.openelisglobal\./, ""); | ||
|
||
return ( | ||
<div | ||
key={key} | ||
className="inlineDiv" | ||
style={{ gap: "20px" }} | ||
> | ||
<TextInput | ||
id={key+"-input"} | ||
labelText={shortKey} // Use the modified key without the prefix | ||
value={commonProperties[key]} | ||
onChange={(e) => { | ||
setCommonProperties({ | ||
...commonProperties, | ||
[key]: e.target.value, | ||
}); | ||
}} | ||
/> | ||
</div> | ||
); | ||
})} | ||
</> | ||
)} | ||
</Column> | ||
|
||
<Column lg={8}> | ||
{commonProperties && ( | ||
<> | ||
{Object.keys(commonProperties) | ||
.slice( | ||
Math.ceil(Object.keys(commonProperties).length / 2), | ||
) | ||
.map((key) => { | ||
// Remove the prefix "org.openelisglobal" using regex | ||
let shortKey = key.replace(/^org\.openelisglobal\./, ""); | ||
|
||
return ( | ||
<div | ||
key={key} | ||
className="inlineDiv" | ||
style={{ gap: "20px" }} | ||
> | ||
<TextInput | ||
id={key+"-input"} | ||
labelText={shortKey} // Use the modified key without the prefix | ||
value={commonProperties[key]} | ||
onChange={(e) => { | ||
setCommonProperties({ | ||
...commonProperties, | ||
[key]: e.target.value, | ||
}); | ||
}} | ||
/> | ||
</div> | ||
); | ||
})} | ||
</> | ||
)} | ||
</Column> | ||
</Grid> | ||
|
||
<div style={{ marginLeft: "3em" }} className="inlineDiv"> | ||
<Button type="submit" onClick={handleSubmit}> | ||
<FormattedMessage | ||
id="label.button.update" | ||
defaultMessage="Update" | ||
/> | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; |
66 changes: 66 additions & 0 deletions
66
...n/java/org/openelisglobal/menu/commonpropertiescontroller/CommonPropertiesController.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 org.openelisglobal.menu.commonpropertiescontroller; | ||
|
||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.env.MapPropertySource; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import java.util.Arrays; | ||
|
||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
@RestController | ||
@RequestMapping("/rest/properties") | ||
public class CommonPropertiesController { | ||
|
||
@Autowired | ||
private ConfigurableEnvironment env; | ||
|
||
@GetMapping | ||
public ResponseEntity<Map<String, String>> getProperties() { | ||
Map<String, String> properties = new HashMap<>(); | ||
env.getPropertySources().forEach(propertySource -> { | ||
if (propertySource instanceof MapPropertySource) { | ||
MapPropertySource mapPropertySource = (MapPropertySource) propertySource; | ||
Arrays.stream(mapPropertySource.getPropertyNames()).forEach(propertyName -> { | ||
// Filter properties with prefix starting "org.openelis" | ||
if (propertyName.startsWith("org.openelis")) { | ||
properties.put(propertyName, mapPropertySource.getProperty(propertyName).toString()); | ||
} | ||
}); | ||
} | ||
}); | ||
return ResponseEntity.ok(properties); | ||
} | ||
|
||
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<Map<String, String>> updateProperties(@RequestBody Map<String, String> updatedProperties) { | ||
Map<String, String> response = new HashMap<>(); | ||
|
||
org.springframework.core.env.MutablePropertySources propertySources = env.getPropertySources(); | ||
|
||
updatedProperties.forEach((key, value) -> { | ||
for (org.springframework.core.env.PropertySource<?> propertySource : propertySources) { | ||
if (propertySource instanceof org.springframework.core.env.MapPropertySource) { | ||
org.springframework.core.env.MapPropertySource mapPropertySource = (org.springframework.core.env.MapPropertySource) propertySource; | ||
if (mapPropertySource.containsProperty(key)) { | ||
|
||
Map<String, Object> updatedSource = new HashMap<>(mapPropertySource.getSource()); | ||
updatedSource.put(key, value); | ||
|
||
propertySources.replace(mapPropertySource.getName(), new MapPropertySource(mapPropertySource.getName(), updatedSource)); | ||
|
||
response.put(key, value); | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
return ResponseEntity.ok(response); | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -18,8 +18,21 @@ org.openelisglobal.fhir.subscriber= | |
org.openelisglobal.fhir.subscriber.resources=Task,Patient,ServiceRequest,DiagnosticReport,Observation,Specimen,Practitioner,Encounter | ||
|
||
#org.openelisglobal.facilitylist.fhirstore = http://localhost:4000/fhir/DEFAULT | ||
# org.openelisglobal.facilitylist.authurl= http://localhost:4000/auth/token | ||
# org.openelisglobal.facilitylist.username= [email protected] | ||
# org.openelisglobal.facilitylist.password= gofr | ||
# org.openelisglobal.facilitylist.auth= token | ||
org.openelisglobal.facilitylist.fhirstore = | ||
org.openelisglobal.facilitylist.authurl= | ||
org.openelisglobal.facilitylist.username= | ||
org.openelisglobal.facilitylist.password= | ||
org.openelisglobal.facilitylist.auth= | ||
facilitylist.schedule.fixedRate=864000000 | ||
|
||
# Remote FHIR server/Consolidated Server | ||
org.openelisglobal.fhirstore.username=openelis | ||
org.openelisglobal.fhirstore.password=Openelis123! | ||
org.openelisglobal.fhir.subscriber.allowHTTP=true | ||
|
||
#provider FHIR server | ||
org.openelisglobal.providerlist.fhirstore=http://localhost:8081/fhir/ | ||
org.openelisglobal.requester.identifier=Practitioner/f9badd80-ab76-11e2-9e96-0800200c9a66 | ||
org.openelisglobal.requester.lastName= | ||
org.openelisglobal.requester.firstName= | ||
org.openelisglobal.requester.phone= |