Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily expose abdm health facility config directly #6197

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 79 additions & 2 deletions src/Components/ABDM/ConfigureHealthFacility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as Notification from "../../Utils/Notifications.js";
import { navigate } from "raviger";
import { Cancel, Submit } from "../Common/components/ButtonV2";
import TextFormField from "../Form/FormFields/TextFormField";
import { classNames } from "../../Utils/utils";
const Loading = lazy(() => import("../Common/Loading"));

const initForm = {
Expand Down Expand Up @@ -47,7 +48,7 @@ export const ConfigureHealthFacility = (props: any) => {
setIsLoading(true);
const res = await dispatchAction(healthFacilityActions.read(facilityId));

if (res.status === 200 && res?.data) {
if (res?.status === 200 && res?.data) {
const formData = {
...state.form,
hf_id: res.data.hf_id,
Expand Down Expand Up @@ -84,6 +85,32 @@ export const ConfigureHealthFacility = (props: any) => {
hf_id: state.form.hf_id,
})
);
} else if (state.form.hf_id === state.form.health_facility?.hf_id) {
res = await dispatchAction(
healthFacilityActions.registerService(facilityId)
);

if (res?.status === 200 && res?.data) {
if (res.data?.registered) {
dispatch({
type: "set_form",
form: {
...state.form,
health_facility: {
...state.form?.health_facility,
registered: res.data.registered,
},
},
});

return;
}
}

Notification.Error({
msg: "Service registration failed, please try again later",
});
return;
} else {
res = await dispatchAction(
healthFacilityActions.create({
Expand Down Expand Up @@ -127,6 +154,49 @@ export const ConfigureHealthFacility = (props: any) => {
<TextFormField
name="hf_id"
label="Health Facility Id"
trailing={
<p
className={classNames(
"tooltip cursor-pointer text-sm",
state.form.health_facility?.registered
? "text-primary-600 hover:text-primary-800"
: "text-warning-600 hover:text-warning-800"
)}
>
{state.form.health_facility?.registered ? (
<>
<div className="tooltip-text tooltip-top -left-48 flex flex-col gap-4">
<span className="text-gray-100">
The ABDM health facility is successfully linked with
care{" "}
<strong>and registered as a service in bridge</strong>
</span>
<span className="text-green-100">
No Action Required.
</span>
</div>
Registered
</>
) : (
<>
<div className="tooltip-text tooltip-top -left-48 flex flex-col gap-4">
<span className="text-gray-100">
The ABDM health facility is successfully linked with
care{" "}
<strong>
but not registered as a service in bridge
</strong>
</span>
<span className="text-warning-100">
Click on <strong>Link Health Facility</strong> to
register the service
</span>
</div>
Not Registered
</>
)}
</p>
}
required
value={state.form.hf_id}
onChange={(e) => handleChange(e)}
Expand All @@ -136,7 +206,14 @@ export const ConfigureHealthFacility = (props: any) => {
</div>
<div className="flex flex-col gap-3 sm:flex-row sm:justify-between">
<Cancel onClick={() => navigate(`/facility/${facilityId}`)} />
<Submit onClick={handleSubmit} label="Update" />
<Submit
onClick={handleSubmit}
disabled={
state.form.hf_id === state.form.health_facility?.hf_id &&
state.form.health_facility?.registered
}
label="Link Health Facility"
/>
</div>
</form>
</div>
Expand Down
9 changes: 2 additions & 7 deletions src/Components/Facility/UpdateFacilityMiddleware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { navigate } from "raviger";
import { Cancel, Submit } from "../Common/components/ButtonV2";
import TextFormField from "../Form/FormFields/TextFormField";
import Page from "../Common/components/Page";
import useConfig from "../../Common/hooks/useConfig";
import { ConfigureHealthFacility } from "../ABDM/ConfigureHealthFacility";
const Loading = lazy(() => import("../Common/Loading"));

Expand Down Expand Up @@ -52,7 +51,6 @@ export const UpdateFacilityMiddleware = (props: any) => {
const { facilityId } = props;
const dispatchAction: any = useDispatch();
const [isLoading, setIsLoading] = useState(false);
const config = useConfig();

const fetchData = useCallback(
async (status: statusType) => {
Expand Down Expand Up @@ -169,11 +167,8 @@ export const UpdateFacilityMiddleware = (props: any) => {
</div>
</form>
</div>
{config.enable_abdm ? (
<ConfigureHealthFacility facilityId={facilityId} />
) : (
<></>
)}

<ConfigureHealthFacility facilityId={facilityId} />
</Page>
);
};
9 changes: 9 additions & 0 deletions src/Redux/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,15 @@ export const healthFacilityActions = {
facility_id: id,
});
},

registerService: (id: string) => {
return fireRequest(
"registerHealthFacilityAsService",
[],
{},
{ facility_id: id }
);
},
};

export const listAssetAvailability = (params: object) =>
Expand Down
5 changes: 5 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,11 @@ const routes: Routes = {
method: "PATCH",
},

registerHealthFacilityAsService: {
path: "/api/v1/abdm/health_facility/{facility_id}/register_service/",
method: "POST",
},

// Asset Availability endpoints

listAssetAvailability: {
Expand Down