Skip to content

Commit

Permalink
added properties controller
Browse files Browse the repository at this point in the history
  • Loading branch information
konavivekramakrishna committed Mar 22, 2024
1 parent 5e26cdb commit 1b48661
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 4 deletions.
8 changes: 8 additions & 0 deletions frontend/src/components/admin/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
SideNavMenu,
SideNavMenuItem,
} from "@carbon/react";
import { CommonProperties } from "./menu/ApplicationProperties";


function Admin() {
const intl = useIntl();
Expand Down Expand Up @@ -75,6 +77,9 @@ function Admin() {
<SideNavMenuItem href="#studyMenuManagement">
<FormattedMessage id="sidenav.label.admin.menu.study" />
</SideNavMenuItem>
<SideNavMenuItem href="#commonproperties">
<FormattedMessage id="sidenav.label.admin.menu.commonproperties" defaultMessage={"Common Properties"} />
</SideNavMenuItem>
</SideNavMenu>
<SideNavLink
renderIcon={Catalog}
Expand Down Expand Up @@ -113,6 +118,9 @@ function Admin() {
<PathRoute path="#studyMenuManagement">
<StudyMenuManagement />
</PathRoute>
<PathRoute path="#commonproperties">
<CommonProperties />
</PathRoute>
</>
);
}
Expand Down
167 changes: 167 additions & 0 deletions frontend/src/components/admin/menu/ApplicationProperties.js
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>
</>
);
};
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);
}
}


21 changes: 17 additions & 4 deletions volume/properties/common.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=

0 comments on commit 1b48661

Please sign in to comment.