Skip to content

Instantly share code, notes, and snippets.

@dnewber
Last active December 24, 2019 17:33
Show Gist options
  • Select an option

  • Save dnewber/bb822fb8b4ff071928f57204dd37dbbf to your computer and use it in GitHub Desktop.

Select an option

Save dnewber/bb822fb8b4ff071928f57204dd37dbbf to your computer and use it in GitHub Desktop.
Middleware Usage Guide

Middleware Usage Guide

User Story 1: As a MapHabit Community Manager, I can link my PCC credentials to my MapHabit account.

To create/update a relationship between the Maphabit user and the PCC user, make the following request:
curl -X PATCH \
  "https://api-staging.middleware.maphabit.com/v1/mh/community/community123/user/123/rel/pccUser" \
  -H 'Content-Type: application/json' \
  -H  "Authorization: Bearer token" \
  -d '{ \
  "data": { \
    "type": "PCCRelationship", \
    "id": "pccOrgUUID.pccUserId" \
  } \
}'
To create/update a relationship between a Maphabit community and a PCC facility, make the following request:
curl -X PATCH \
"https://api-staging.middleware.maphabit.com/v1/mh/community/community123/rel/pccFac" \
-H  "accept: application/json" \
-H  "Authorization: Bearer token" \
-H  "Content-Type: application/json" \
-d '{
  "data":{  \
    "type": "PCCRelationship",  \
    "id": "pccOrgUuid.pccFacId" \
  } \
}''
To view a Maphabit user's PCC relationship:
curl -X GET "https://api-staging.middleware.maphabit.com/v1/mh/community/community123/user/1/rel/pccUser" \
  -H  "accept: application/json" \
  -H  "Authorization: Bearer token"
To view a Maphabit community's PCC relationship:
curl -X GET "https://api-staging.middleware.maphabit.com/v1/mh/community/community123/rel/pccFac" \
  -H  "accept: application/json" \
  -H  "Authorization: Bearer token"

User Story 3: As an anonymous visitor, I can use my PCC credentials to login to MapHabit.

To get a list of all the Maphabit users that are linked to the provided PCC user credentials, make the following request:
curl -X GET \
    "https://api-staging.middleware.maphabit.com/v1/pcc/org/<orgUuid>/user/<pccUserId>/rel/mhUser" \
        -H  "accept: application/json" \
        -H  "Authorization: Bearer token"

User Story 4: As a MapHabit community manager, I can remove previously established link to a PCC user.

To delete a relationship between a PCC User and a Maphabit User, make the following request:
    curl -X PATCH \
      https://api-staging.middleware.maphabit.com/v1/mh/community/community123/user/123/rel/pccUser \
      -H 'Content-Type: application/json' \
      -H  "Authorization: Bearer token" \
      -d '{"data": null}'
To delete a relationship between a PCC Facility and a Maphabit Community, make the following request:
    curl -X PATCH \
      "https://api-staging.middleware.maphabit.com/v1/mh/community/community123/rel/pccFac" \
      -H 'Content-Type: application/json' \
      -H  "Authorization: Bearer token" \
      -d '{"data": null}'

User Story 5: As MH community manager with linked PCC account, I can view the list of PCC patients in the PCC facility to which I have access.

Get a list of PCC patients in a facility with the following request:
curl -G \
"http://127.0.0.1:5000/v1/pcc/org/1D56E037-24C5-409F-A414-C9718B519300/patient" \
-d filter['facId']=12 \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer token"
Pagination is possible by supplying the "page" parameter with values for "number" and "size":
curl -G \
"http://127.0.0.1:5000/v1/pcc/org/1D56E037-24C5-409F-A414-C9718B519300/patient" \
-d filter['facId']=12 \
-d page['number']=2 \
-d page['size']=200 \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer token"

Note: PCC does not provide the total number of records available. While paging, the last page of records will have no "next" link.


User Story 6: As MH community manager with linked PCC account, I can create a MapHabit Resident from a PCC patient.

After the user chooses a PCC patient, get the PCC patient data to create a resident from (user should provide additional data attributes):
curl -X GET \
    "https://api-staging.middleware.maphabit.com/v1/pcc/org/pccOrgUUID/patient/patientID" \
        -H  "accept: application/json" \
        -H  "Authorization: Bearer token"
Then, create a MH resident from the PCC patient data + user provided data with the following request:
curl -X POST \
    "https://api-staging.middleware.maphabit.com/v1/mh/community/community123/user" \
        -H  "accept: application/json" \
        -H  "Authorization: Bearer token" \
        -H  "Content-Type: application/json" \
        -d '{ \
	"data": { \
		"id": "1D56E037-24C5-409F-A414-C9718B519300.6209", \
		"type": "PCCPatient", \
		"attributes": { \
			"birthDate": "1953-11-25", \
			"facId": 12, \
			"firstName": "Shari", \
			"gender": "FEMALE", \
			"lastName": "Abreu", \
			"orgUuid": "1D56E037-24C5-409F-A414-C9718B519300", \
			"roomId": 1158, \
			...
		}, \
	    } \
	}'

User Story 7: As a MH community manager with a linked PCC account, I can link an existing MapHabit Resident to a PCC Patient.

Create a relationship between a resident and a patient with the following request:
curl -X PATCH \
    "https://api-staging.middleware.maphabit.com/v1/mh/community/communty123/user/1/rel/pccPatient" \
        -H  "accept: application/json"
        -H  "Authorization: Bearer token"
        -H  "Content-Type: application/json"
        -d '{ \
            "data": { \
                "type": "PCCRelationship", \
                "id": "pccOrgUuid.pccUserId" \
                } \
            }'
To view a Maphabit resident's PCC relationship:
curl -X GET "https://api-staging.middleware.maphabit.com/v1/mh/community/community123/user/1/rel/pccPatient" \
  -H  "accept: application/json" \
  -H  "Authorization: Bearer token"

User Story 8: As a MH community manager with linked a PCC account, I can unlink an existing MapHabit Resident from a PCC Patient.

To delete a relationship between a PCC Patient and a Maphabit Resident, make the following request:
    curl -X PATCH \
      https://api-staging.middleware.maphabit.com/v1/mh/community/community123/user/1/rel/pccPatient \
      -H 'Content-Type: application/json' \
      -H  "Authorization: Bearer token" \
      -d '{"data": null}'

User Story 9 & 10: As a MH community manager with a linked PCC account, I can synchronize all of the patients at a PCC facility to my community.

Enable/Disable autosync for a linked Maphabit community with the following request:
curl -X PATCH  \
  "https://api-staging.middleware.maphabit.com/v1/mh/community/community123"  \
    -H  "accept: application/json"  \
    -H  "Authorization: Bearer token"  \
    -H  "Content-Type: application/json"  \
    -d '{ \
        "data": { \
          "type": "MHCommunity", \
          "id": "communityId", \
          "attributes": { \
            "autosync": boolean \
          } \
        } \
      }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment